ansible-lockdown / RHEL9-CIS

Ansible role for Red Hat 9 CIS Baseline
https://ansible-lockdown.readthedocs.io
MIT License
109 stars 86 forks source link

4.2.3 | PATCH | Ensure permissions on all logfiles are configured - Not idempotent with Molecule #173

Closed rjacobs1990 closed 6 months ago

rjacobs1990 commented 6 months ago

Describe the Issue 4.2.3 | PATCH | Ensure permissions on all logfiles are configured. Unfortunately this step is not idempotent. When running a cis-wrapper role which is calling this role i noticed that the audit.log kept changing during the molecule idempotency run on aws/azure alma or rhel machines. changed: [almalinux-9-x86_64] => (item=/var/log/audit/audit.log)

Expected Behavior I would like to see no changes in file permissions during the second run.

Actual Behavior The second run is changing the following files: changed: [almalinux-9-x86_64] => (item=/var/log/audit/audit.log)

Control(s) Affected What controls are being affected by the issue 4.2.3 | PATCH | Ensure permissions on all logfiles are configured.

Environment (please complete the following information):

Additional Notes N/A

Possible Solution Below code could be a potential fix for the issue:

        - name: "4.2.3 | PATCH | Ensure permissions on all logfiles are configured | change permissions"
          ansible.builtin.file:
            path: "{{ item.path }}"
            mode: "{% if item.mode != '0600' %}0640{% endif %}"
          loop: "{{ logfiles.files }}"
          loop_control:
            label: "{{ item.path }}"
          when:
            - item.path != "/var/log/btmp"
            - item.path != "/var/log/utmp"
            - item.path != "/var/log/wtmp"
rjacobs1990 commented 6 months ago

updated the mode setting to: "{{ '0600' if item.mode == '0600' else '0640' }}" this prevents skips on the 0600.

uk-bolly commented 6 months ago

hi @rjacobs1990

Great work on the issue and PR i have feedback on the PR.

Many thanks again

uk-bolly