-
Notifications
You must be signed in to change notification settings - Fork 827
Fix remediations for file_permissions_audit_configuration_stig #15019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Mab879
merged 4 commits into
ComplianceAsCode:master
from
macko1:fix_file_permissions_audit_configuration_stig
Aug 25, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fb68d7c
fix file_permissions_audit_configuration_stig
macko1 c171187
Prefix ansible task names with rule title, restart auditd only when n…
ggbecker ad220a8
Fix remediations to use 'service' not 'systemctl'
macko1 c719f9a
Use ansible.builtin.command instead of shell
macko1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
...iting/auditd_configure_rules/file_permissions_audit_configuration_stig/ansible/shared.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # platform = multi_platform_rhel | ||
| # reboot = false | ||
| # strategy = configure | ||
| # complexity = low | ||
| # disruption = low | ||
|
|
||
| # Copied and modified from `file_permissions/ansible.yml` template | ||
| # | ||
| # Sets mode 0600 and ownership root:root on all audit config files. | ||
| # Installs an auditd.service dropin to restore 0600 on audit.rules after augenrules | ||
| # rewrites it to 0640 when /etc/audit/rules.d/ content changes (RHEL 8/9 only, not containers). | ||
|
|
||
| - name: "{{{ rule_title }}} - Set /etc/audit/audit.rules and /etc/audit/auditd.conf to 0600, owned by root" | ||
| ansible.builtin.file: | ||
| path: "{{ item }}" | ||
| mode: '0600' | ||
| owner: root | ||
| group: root | ||
| state: file | ||
| loop: | ||
| - /etc/audit/audit.rules | ||
| - /etc/audit/auditd.conf | ||
| failed_when: false | ||
| register: audit_config_perms | ||
|
|
||
| - name: "{{{ rule_title }}} - Find /etc/audit/rules.d/*.rules files" | ||
| ansible.builtin.find: | ||
| paths: /etc/audit/rules.d/ | ||
| depth: 1 | ||
| file_type: file | ||
| patterns: '*.rules' | ||
| register: rules_files | ||
|
|
||
| - name: "{{{ rule_title }}} - Set /etc/audit/rules.d/*.rules files to 0600, owned by root" | ||
| ansible.builtin.file: | ||
| path: "{{ item.path }}" | ||
| mode: '0600' | ||
| owner: root | ||
| group: root | ||
| state: file | ||
| loop: "{{ rules_files.files }}" | ||
| register: rules_dir_perms | ||
|
|
||
| - name: "{{{ rule_title }}} - Install ExecStartPost dropin on auditd.service" | ||
| block: | ||
| - name: "{{{ rule_title }}} - Create dropin directory /etc/systemd/system/auditd.service.d" | ||
| ansible.builtin.file: | ||
| path: /etc/systemd/system/auditd.service.d | ||
| state: directory | ||
| mode: '0755' | ||
|
|
||
| - name: "{{{ rule_title }}} - Install /etc/systemd/system/auditd.service.d/permissions.conf" | ||
| ansible.builtin.copy: | ||
|
macko1 marked this conversation as resolved.
|
||
| dest: /etc/systemd/system/auditd.service.d/permissions.conf | ||
| content: | | ||
| [Service] | ||
| ExecStartPost=/usr/bin/chmod 0600 /etc/audit/audit.rules | ||
| mode: '0644' | ||
|
|
||
| - name: "{{{ rule_title }}} - Restore SELinux context on /etc/systemd/system/auditd.service.d/permissions.conf" | ||
| ansible.builtin.command: restorecon /etc/systemd/system/auditd.service.d/permissions.conf | ||
| changed_when: false | ||
|
|
||
| - name: "{{{ rule_title }}} - Reload systemd daemon to pick up permissions.conf" | ||
| ansible.builtin.systemd: | ||
| daemon_reload: true | ||
|
|
||
| # IMPORTANT: this is necessary to ensure the dropin is loaded and the permissions for /etc/audit/ and /etc/audit/rules.d/ files are set correctly. | ||
| - name: "{{{ rule_title }}} - Restart auditd.service" | ||
| ansible.builtin.command: service auditd restart | ||
| when: | ||
| - audit_config_perms.changed or rules_dir_perms.changed | ||
|
|
||
| when: | ||
|
ggbecker marked this conversation as resolved.
|
||
| - '"audit" in ansible_facts.packages' | ||
| - '"kernel-core" in ansible_facts.packages' | ||
40 changes: 40 additions & 0 deletions
40
.../auditing/auditd_configure_rules/file_permissions_audit_configuration_stig/bash/shared.sh
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # platform = multi_platform_rhel | ||
| # reboot = false | ||
| # strategy = configure | ||
| # complexity = low | ||
| # disruption = low | ||
|
|
||
| # Copied and modified from `file_permissions/bash.template` template | ||
| # | ||
| # Sets mode 0600 and ownership root:root on all audit config files. | ||
| # Installs an auditd.service dropin to restore 0600 on audit.rules after augenrules | ||
| # rewrites it to 0640 when /etc/audit/rules.d/ content changes (RHEL 8/9 only, not containers). | ||
|
|
||
| find /etc/audit/ -maxdepth 1 -type f \ | ||
| -regextype posix-extended -regex '^.*audit(\.rules|d\.conf)$' \ | ||
| -exec chmod 0600 {} \; \ | ||
| -exec chown root:root {} \; | ||
|
|
||
| find /etc/audit/rules.d/ -maxdepth 1 -type f -name '*.rules' \ | ||
| -exec chmod 0600 {} \; \ | ||
| -exec chown root:root {} \; | ||
|
|
||
| if rpm --quiet -q audit && rpm --quiet -q kernel-core; then | ||
|
|
||
| # Generate the dropin file content to restore 0600 on audit.rules after augenrules rewrites it to 0640 when /etc/audit/rules.d/ content changes (RHEL 8/9 only, not containers). | ||
|
|
||
| mkdir -p /etc/systemd/system/auditd.service.d | ||
| chmod 0755 /etc/systemd/system/auditd.service.d | ||
|
|
||
| cat > /etc/systemd/system/auditd.service.d/permissions.conf << 'EOF' | ||
| [Service] | ||
| ExecStartPost=/usr/bin/chmod 0600 /etc/audit/audit.rules | ||
| EOF | ||
| chmod 0644 /etc/systemd/system/auditd.service.d/permissions.conf | ||
|
macko1 marked this conversation as resolved.
|
||
| restorecon /etc/systemd/system/auditd.service.d/permissions.conf | ||
|
|
||
| systemctl daemon-reload | ||
| # IMPORTANT: this is necessary to ensure the dropin is loaded and the permissions for /etc/audit/ and /etc/audit/rules.d/ files are set correctly. | ||
| service auditd restart | ||
|
|
||
| fi | ||
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.