Skip to content
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

Fix Lexicological ordering of immutable.rules #12763

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

bordenit
Copy link

Description:

The filename for the auditd immutable rules is 90-immutable.rules in some areas, but not in others. This fixes it.

Rationale:

With lexicological ordering naming the file immutable.rules will not let it load last. The DISA STIG, and common practice is to put the immutable rule at the last entry in the audit.rules file. Also, the DISA STIG checks for the last line in the audit.rules file for this check. Instead of loading the -e option into audit.rules in a random fashion, the system should be rebooted, then it will pick up the -e from the 90-immutable.rules and put it at the end.

@openshift-ci openshift-ci bot added the needs-ok-to-test Used by openshift-ci bot. label Dec 21, 2024
Copy link

openshift-ci bot commented Dec 21, 2024

Hi @bordenit. Thanks for your PR.

I'm waiting for a ComplianceAsCode member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link

Start a new ephemeral environment with changes proposed in this pull request:

rhel8 (from CTF) Environment (using Fedora as testing environment)
Open in Gitpod

Fedora Testing Environment
Open in Gitpod

Oracle Linux 8 Environment
Open in Gitpod

Copy link

This datastream diff is auto generated by the check Compare DS/Generate Diff

Click here to see the full diff
bash remediation for rule 'xccdf_org.ssgproject.content_rule_audit_rules_immutable' differs.
--- xccdf_org.ssgproject.content_rule_audit_rules_immutable
+++ xccdf_org.ssgproject.content_rule_audit_rules_immutable
@@ -15,7 +15,7 @@
 # * /etc/audit/audit.rules file 		(for auditctl case)
 # * /etc/audit/rules.d/immutable.rules		(for augenrules case)
 
-for AUDIT_FILE in "/etc/audit/audit.rules" "/etc/audit/rules.d/immutable.rules"
+for AUDIT_FILE in "/etc/audit/audit.rules" "/etc/audit/rules.d/90-immutable.rules"
 do
 	echo '' >> $AUDIT_FILE
 	echo '# Set the audit.rules configuration immutable per security requirements' >> $AUDIT_FILE

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_audit_rules_immutable' differs.
--- xccdf_org.ssgproject.content_rule_audit_rules_immutable
+++ xccdf_org.ssgproject.content_rule_audit_rules_immutable
@@ -73,15 +73,14 @@
   - reboot_required
   - restrict_strategy
 
-- name: Add Audit -e option into /etc/audit/rules.d/immutable.rules and /etc/audit/audit.rules
+- name: Add Audit -e option into /etc/audit/rules.d/90-immutable.rules
   lineinfile:
     path: '{{ item }}'
     create: true
     line: -e 2
     mode: g-rwx,o-rwx
   loop:
-  - /etc/audit/audit.rules
-  - /etc/audit/rules.d/immutable.rules
+  - /etc/audit/rules.d/90-immutable.rules
   when:
   - '"audit" in ansible_facts.packages'
   - '"kernel" in ansible_facts.packages'

@bordenit
Copy link
Author

bordenit commented Dec 21, 2024

Well, doesn't seem to matter much, the -e is still always loaded last based on my testing when you reload the rules in entirety, but placing the immutable rules in 90- follows the RHEL guidance as well......
https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/security_hardening/auditing-the-system_security-hardening#using-augenrules-to-define-persistent-rules_auditing-the-system

Also, the audit system should be trusted to load the rules in order, depending on how you run the playbook, which order, tags, etc... it could update /etc/audit/audit.rules in a different order with the lineinfile commands. If you want consistency, rename the /etc/audit/rules.d .rules files with something like 30-stig.rules and 90-immutable.rules, and trust the audit system to load /etc/audit/audit.rules in the same order every time. Using the playbook is very inconsistent with iteration for the rules being manually placed in /etc/audit/audit.rules.

@Mab879 Mab879 self-assigned this Jan 9, 2025
@Mab879 Mab879 added this to the 0.1.76 milestone Jan 9, 2025
Copy link

codeclimate bot commented Jan 10, 2025

Code Climate has analyzed commit 6ab29c5 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 61.6% (0.0% change).

View more on Code Climate.

Copy link
Member

@Mab879 Mab879 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR pull request.

I have let one comment to ensure the files used in both remediation types are the same.

Secondly, I'm not sure 90-immutable.rules will work fully with this project. We have many unnumbered files such as modules.rules and based on my quick research it seems 90-immutable.rules, might get loaded first.

lineinfile:
path: "{{ item }}"
create: True
line: "-e 2"
mode: g-rwx,o-rwx
loop:
- "/etc/audit/audit.rules"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep this file to match the bash remediation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ok-to-test Used by openshift-ci bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants