rootfiles_configured: populate /usr/share/rootfiles/ in remediation#14710
Draft
ggbecker wants to merge 1 commit into
Draft
rootfiles_configured: populate /usr/share/rootfiles/ in remediation#14710ggbecker wants to merge 1 commit into
ggbecker wants to merge 1 commit into
Conversation
On RHEL 9.0/9.1 the rootfiles package installs dotfiles directly into /root/ and does not create /usr/share/rootfiles/. The remediation was writing a tmpfiles.d conf with C copy entries sourcing from that directory. When the destination files were absent at boot, systemd-tmpfiles failed with "No such file or directory" because the source path did not exist. Fix the Bash and Ansible remediations to create /usr/share/rootfiles/ and copy each dotfile from /root/ to that directory if not already present, so the tmpfiles.d source is always valid. On RHEL 9.2+ where rootfiles already provides /usr/share/rootfiles/, these steps are no-ops. Fixes ComplianceAsCode#14582
|
Skipping CI for Draft Pull Request. |
|
This datastream diff is auto generated by the check Click here to see the full diffbash remediation for rule 'xccdf_org.ssgproject.content_rule_rootfiles_configured' differs.
--- xccdf_org.ssgproject.content_rule_rootfiles_configured
+++ xccdf_org.ssgproject.content_rule_rootfiles_configured
@@ -1,7 +1,13 @@
# Remediation is applicable only in certain platforms
if rpm --quiet -q rootfiles; then
-find "/etc/tmpfiles.d/" -name "*.conf" -print0 | xargs -0 sed -i "/C[[:space:]]*\/root\/.bash_logout/d"
+mkdir -p /usr/share/rootfiles
+ [ -f "/root/.bash_logout" ] && [ ! -f "/usr/share/rootfiles/.bash_logout" ] && cp "/root/.bash_logout" "/usr/share/rootfiles/.bash_logout"
+ [ -f "/root/.bash_profile" ] && [ ! -f "/usr/share/rootfiles/.bash_profile" ] && cp "/root/.bash_profile" "/usr/share/rootfiles/.bash_profile"
+ [ -f "/root/.bashrc" ] && [ ! -f "/usr/share/rootfiles/.bashrc" ] && cp "/root/.bashrc" "/usr/share/rootfiles/.bashrc"
+ [ -f "/root/.cshrc" ] && [ ! -f "/usr/share/rootfiles/.cshrc" ] && cp "/root/.cshrc" "/usr/share/rootfiles/.cshrc"
+ [ -f "/root/.tcshrc" ] && [ ! -f "/usr/share/rootfiles/.tcshrc" ] && cp "/root/.tcshrc" "/usr/share/rootfiles/.tcshrc"
+ find "/etc/tmpfiles.d/" -name "*.conf" -print0 | xargs -0 sed -i "/C[[:space:]]*\/root\/.bash_logout/d"
find "/etc/tmpfiles.d/" -name "*.conf" -print0 | xargs -0 sed -i "/C[[:space:]]*\/root\/.bash_profile/d"
find "/etc/tmpfiles.d/" -name "*.conf" -print0 | xargs -0 sed -i "/C[[:space:]]*\/root\/.bashrc/d"
find "/etc/tmpfiles.d/" -name "*.conf" -print0 | xargs -0 sed -i "/C[[:space:]]*\/root\/.cshrc/d"
ansible remediation for rule 'xccdf_org.ssgproject.content_rule_rootfiles_configured' differs.
--- xccdf_org.ssgproject.content_rule_rootfiles_configured
+++ xccdf_org.ssgproject.content_rule_rootfiles_configured
@@ -1,6 +1,54 @@
- name: Gather the package facts
package_facts:
manager: auto
+ tags:
+ - configure_strategy
+ - low_complexity
+ - low_disruption
+ - medium_severity
+ - no_reboot_needed
+ - rootfiles_configured
+
+- name: Ensure rootfiles tmpfile.d is Configured Correctly - Ensure source directory
+ exists
+ ansible.builtin.file:
+ path: /usr/share/rootfiles
+ state: directory
+ mode: '0755'
+ owner: root
+ group: root
+ when: '"rootfiles" in ansible_facts.packages'
+ tags:
+ - configure_strategy
+ - low_complexity
+ - low_disruption
+ - medium_severity
+ - no_reboot_needed
+ - rootfiles_configured
+
+- name: Ensure rootfiles tmpfile.d is Configured Correctly - Stat /root/.bash_logout
+ ansible.builtin.stat:
+ path: /root/.bash_logout
+ register: rootfiles_configured_bash_logout_root_stat
+ when: '"rootfiles" in ansible_facts.packages'
+ tags:
+ - configure_strategy
+ - low_complexity
+ - low_disruption
+ - medium_severity
+ - no_reboot_needed
+ - rootfiles_configured
+
+- name: Ensure rootfiles tmpfile.d is Configured Correctly - Copy /root/.bash_logout
+ to /usr/share/rootfiles/.bash_logout if missing
+ ansible.builtin.copy:
+ src: /root/.bash_logout
+ dest: /usr/share/rootfiles/.bash_logout
+ remote_src: true
+ force: false
+ when:
+ - '"rootfiles" in ansible_facts.packages'
+ - rootfiles_configured_bash_logout_root_stat.stat.exists
tags:
- configure_strategy
- low_complexity
@@ -55,6 +103,37 @@
- no_reboot_needed
- rootfiles_configured
+- name: Ensure rootfiles tmpfile.d is Configured Correctly - Stat /root/.bash_profile
+ ansible.builtin.stat:
+ path: /root/.bash_profile
+ register: rootfiles_configured_bash_profile_root_stat
+ when: '"rootfiles" in ansible_facts.packages'
+ tags:
+ - configure_strategy
+ - low_complexity
+ - low_disruption
+ - medium_severity
+ - no_reboot_needed
+ - rootfiles_configured
+
+- name: Ensure rootfiles tmpfile.d is Configured Correctly - Copy /root/.bash_profile
+ to /usr/share/rootfiles/.bash_profile if missing
+ ansible.builtin.copy:
+ src: /root/.bash_profile
+ dest: /usr/share/rootfiles/.bash_profile
+ remote_src: true
+ force: false
+ when:
+ - '"rootfiles" in ansible_facts.packages'
+ - rootfiles_configured_bash_profile_root_stat.stat.exists
+ tags:
+ - configure_strategy
+ - low_complexity
+ - low_disruption
+ - medium_severity
+ - no_reboot_needed
+ - rootfiles_configured
+
- name: Ensure rootfiles tmpfile.d is Configured Correctly - Find configuration files
ansible.builtin.find:
paths: /etc/tmpfiles.d/
@@ -101,6 +180,37 @@
- no_reboot_needed
- rootfiles_configured
+- name: Ensure rootfiles tmpfile.d is Configured Correctly - Stat /root/.bashrc
+ ansible.builtin.stat:
+ path: /root/.bashrc
+ register: rootfiles_configured_bashrc_root_stat
+ when: '"rootfiles" in ansible_facts.packages'
+ tags:
+ - configure_strategy
+ - low_complexity
+ - low_disruption
+ - medium_severity
+ - no_reboot_needed
+ - rootfiles_configured
+
+- name: Ensure rootfiles tmpfile.d is Configured Correctly - Copy /root/.bashrc to
+ /usr/share/rootfiles/.bashrc if missing
+ ansible.builtin.copy:
+ src: /root/.bashrc
+ dest: /usr/share/rootfiles/.bashrc
+ remote_src: true
+ force: false
+ when:
+ - '"rootfiles" in ansible_facts.packages'
+ - rootfiles_configured_bashrc_root_stat.stat.exists
+ tags:
+ - configure_strategy
+ - low_complexity
+ - low_disruption
+ - medium_severity
+ - no_reboot_needed
+ - rootfiles_configured
+
- name: Ensure rootfiles tmpfile.d is Configured Correctly - Find configuration files
ansible.builtin.find:
paths: /etc/tmpfiles.d/
@@ -147,6 +257,37 @@
- no_reboot_needed
- rootfiles_configured
+- name: Ensure rootfiles tmpfile.d is Configured Correctly - Stat /root/.cshrc
+ ansible.builtin.stat:
+ path: /root/.cshrc
+ register: rootfiles_configured_cshrc_root_stat
+ when: '"rootfiles" in ansible_facts.packages'
+ tags:
+ - configure_strategy
+ - low_complexity
+ - low_disruption
+ - medium_severity
+ - no_reboot_needed
+ - rootfiles_configured
+
+- name: Ensure rootfiles tmpfile.d is Configured Correctly - Copy /root/.cshrc to
+ /usr/share/rootfiles/.cshrc if missing
+ ansible.builtin.copy:
+ src: /root/.cshrc
+ dest: /usr/share/rootfiles/.cshrc
+ remote_src: true
+ force: false
+ when:
+ - '"rootfiles" in ansible_facts.packages'
+ - rootfiles_configured_cshrc_root_stat.stat.exists
+ tags:
+ - configure_strategy
+ - low_complexity
+ - low_disruption
+ - medium_severity
+ - no_reboot_needed
+ - rootfiles_configured
+
- name: Ensure rootfiles tmpfile.d is Configured Correctly - Find configuration files
ansible.builtin.find:
paths: /etc/tmpfiles.d/
@@ -193,6 +334,37 @@
- no_reboot_needed
- rootfiles_configured
+- name: Ensure rootfiles tmpfile.d is Configured Correctly - Stat /root/.tcshrc
+ ansible.builtin.stat:
+ path: /root/.tcshrc
+ register: rootfiles_configured_tcshrc_root_stat
+ when: '"rootfiles" in ansible_facts.packages'
+ tags:
+ - configure_strategy
+ - low_complexity
+ - low_disruption
+ - medium_severity
+ - no_reboot_needed
+ - rootfiles_configured
+
+- name: Ensure rootfiles tmpfile.d is Configured Correctly - Copy /root/.tcshrc to
+ /usr/share/rootfiles/.tcshrc if missing
+ ansible.builtin.copy:
+ src: /root/.tcshrc
+ dest: /usr/share/rootfiles/.tcshrc
+ remote_src: true
+ force: false
+ when:
+ - '"rootfiles" in ansible_facts.packages'
+ - rootfiles_configured_tcshrc_root_stat.stat.exists
+ tags:
+ - configure_strategy
+ - low_complexity
+ - low_disruption
+ - medium_severity
+ - no_reboot_needed
+ - rootfiles_configured
+
- name: Ensure rootfiles tmpfile.d is Configured Correctly - Find configuration files
ansible.builtin.find:
paths: /etc/tmpfiles.d/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
On RHEL 9.0/9.1 the rootfiles package installs dotfiles directly into /root/ and does not create /usr/share/rootfiles/. The remediation was writing a tmpfiles.d conf with C copy entries sourcing from that directory. When the destination files were absent at boot, systemd-tmpfiles failed with "No such file or directory" because the source path did not exist.
Fix the Bash and Ansible remediations to create /usr/share/rootfiles/ and copy each dotfile from /root/ to that directory if not already present, so the tmpfiles.d source is always valid. On RHEL 9.2+ where rootfiles already provides /usr/share/rootfiles/, these steps are no-ops.
Rationale:
Fixes Systemd-tmpfiles errors on RHEL 9 boot #14582
This is a Claude suggestion to fix the issue, let's run the tests and see if the error is fixed.