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

Multiple issues with CIS 4.3.x sudo #118

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions tasks/section_4/cis_4.3.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
- name: "4.3.2 | PATCH | Ensure sudo commands use pty"
ansible.builtin.lineinfile:
path: /etc/sudoers
regexp: '^Defaults use_'
line: 'Defaults use_pty'
insertafter: '^Defaults'
regexp: '^\s*Defaults\s+use_pty\s*$'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Look for a wider range of compatible regexps...in particular, I had a file that mirrored the format of the lines in the distribution file and used a tab to separate. Instead of calling it correct or replacing the line, it added a new line.

line: 'Defaults use_pty'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this is spaced to look like the defaults in the distributed sudoers file, it should use a tab like those entries instead of using 8 spaces. For simplicity, since it is not unlikely contributors' editors will replace tabs with spaces, just use a single space.

insertafter: 'EOF'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should insert at end of file, in particular the inserted directive should take precedence over "Defaults !use_pty" if that appears in an included file or in #includedir.

when:
- ubtu20cis_rule_4_3_2
tags:
Expand All @@ -33,9 +33,9 @@
- name: "4.3.3 | PATCH | Ensure sudo log file exists"
ansible.builtin.lineinfile:
path: /etc/sudoers
regexp: '^Defaults logfile'
line: 'Defaults logfile="{{ ubtu20cis_sudo_logfile }}"'
insertafter: '^Defaults'
regexp: '^\s*Defaults\s+logfile\s*='
line: 'Defaults logfile="{{ ubtu20cis_sudo_logfile }}"'
insertafter: 'EOF'
when:
- ubtu20cis_rule_4_3_3
tags:
Expand Down Expand Up @@ -89,15 +89,15 @@
- name: "4.3.6 | PATCH | Ensure sudo authentication timeout is configured correctly | Set value if no results"
ansible.builtin.lineinfile:
path: /etc/sudoers
regexp: 'Defaults timestamp_timeout='
regexp: '^\s*Defaults\s+timestamp_timeout\s*='
line: "Defaults timestamp_timeout={{ ubtu20cis_sudo_timestamp_timeout }}"
validate: '/usr/sbin/visudo -cf %s'
when: ubtu20cis_4_3_6_timeout_files.stdout | length == 0

- name: "4.3.6 | PATCH | Ensure sudo authentication timeout is configured correctly | Set value if has results"
ansible.builtin.replace:
path: "{{ item }}"
regexp: 'timestamp_timeout=(\d+)'
regexp: 'timestamp_timeout\s*=\s*(\d+)'
replace: "timestamp_timeout={{ ubtu20cis_sudo_timestamp_timeout }}"
validate: '/usr/sbin/visudo -cf %s'
loop: "{{ ubtu20cis_4_3_6_timeout_files.stdout_lines }}"
Expand Down