-
Notifications
You must be signed in to change notification settings - Fork 698
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
Refactor Ansible remediations that search local file systems #10912
Changes from all commits
8b1dc5b
f940433
17a8926
9997776
c0de3ee
5eafed2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,28 +4,16 @@ | |
# complexity = low | ||
# disruption = low | ||
|
||
- name: Ensure SHA_CRYPT_MIN_ROUNDS has minimum value of 5000 | ||
replace: | ||
- name: "{{{ rule_title }}} - Ensure SHA_CRYPT_MIN_ROUNDS has Minimum Value of 5000" | ||
ansible.builtin.replace: | ||
path: /etc/login.defs | ||
regexp: '(^\s*SHA_CRYPT_MIN_ROUNDS\s+)(?!(?:[5-9]\d{3,}|\d{5,}))\S*(\s*$)' | ||
replace: '\g<1>5000\g<2>' | ||
backup: no | ||
|
||
- name: Check to see if SHA_CRYPT_MIN_ROUNDS is explicitly configured | ||
shell: | | ||
set -o pipefail | ||
grep -e '^\s*SHA_CRYPT_MIN_ROUNDS\s\+' /etc/login.defs || true | ||
register: check_sha_crypt_min_rounds_result | ||
|
||
# NOTE(gyee): there's a possibility that the value of SHA_CRYPT_MIN_ROUNDS is | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was the comment useful? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
# greater than the value of SHA_CRYPT_MAX_ROUNDS. But as far as we're, | ||
# concerned, this is not a problem as per login.defs, | ||
# if SHA_CRYPT_MIN_ROUNDS > SHA_CRYPT_MAX_ROUNDS, the highest value will be | ||
# used. In that case, we don't need to touch SHA_CRYPT_MAX_ROUNDS. | ||
- name: Ensure SHA_CRYPT_MAX_ROUNDS has minimum value of 5000 | ||
replace: | ||
- name: "{{{ rule_title }}} - Ensure SHA_CRYPT_MAX_ROUNDS has Minimum Value of 5000" | ||
ansible.builtin.replace: | ||
path: /etc/login.defs | ||
regexp: '(^\s*SHA_CRYPT_MAX_ROUNDS\s+)(?!(?:[5-9]\d{3,}|\d{5,}))\S*(\s*$)' | ||
replace: '\g<1>5000\g<2>' | ||
backup: no | ||
when: '"SHA_CRYPT_MIN_ROUNDS" not in check_sha_crypt_min_rounds_result.stdout' |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/bin/bash | ||
|
||
source common.sh | ||
|
||
echo "SHA_CRYPT_MIN_ROUNDS 5000" > "/etc/login.defs" | ||
echo "SHA_CRYPT_MAX_ROUNDS 5000" >> "/etc/login.defs" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
# Default values are 5000 if the parameters are not defined. | ||
echo "SHA_CRYPT_MIN_ROUNDS 5000" > "/etc/login.defs" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
# Default values are 5000 if the parameters are not defined. | ||
echo "SHA_CRYPT_MAX_ROUNDS 5000" > "/etc/login.defs" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
# Default values are 5000 if the parameters are not defined. | ||
truncate -s 0 "/etc/login.defs" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
echo "SHA_CRYPT_MIN_ROUNDS 5000" > "/etc/login.defs" | ||
echo "SHA_CRYPT_MAX_ROUNDS 4999" >> "/etc/login.defs" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/bin/bash | ||
|
||
source common.sh | ||
|
||
echo "SHA_CRYPT_MIN_ROUNDS 4999" > "/etc/login.defs" | ||
echo "SHA_CRYPT_MAX_ROUNDS 5000" >> "/etc/login.defs" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
echo "SHA_CRYPT_MIN_ROUNDS 4999" > "/etc/login.defs" | ||
echo "SHA_CRYPT_MAX_ROUNDS 4999" >> "/etc/login.defs" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,64 +4,11 @@ | |
# complexity = low | ||
# disruption = medium | ||
|
||
- name: "{{{ rule_title }}} - Define Excluded (Non-Local) File Systems and Paths" | ||
ansible.builtin.set_fact: | ||
excluded_fstypes: | ||
- afs | ||
- ceph | ||
- cifs | ||
- smb3 | ||
- smbfs | ||
- sshfs | ||
- ncpfs | ||
- ncp | ||
- nfs | ||
- nfs4 | ||
- gfs | ||
- gfs2 | ||
- glusterfs | ||
- gpfs | ||
- pvfs2 | ||
- ocfs2 | ||
- lustre | ||
- davfs | ||
- fuse.sshfs | ||
excluded_paths: | ||
- dev | ||
- proc | ||
- run | ||
- sys | ||
search_paths: [] | ||
world_writable_dirs: [] | ||
|
||
- name: "{{{ rule_title }}} - Find Relevant Root Directories Ignoring Pre-Defined Excluded Paths" | ||
ansible.builtin.find: | ||
paths: / | ||
file_type: directory | ||
excludes: "{{ excluded_paths }}" | ||
hidden: true | ||
recurse: false | ||
register: result_relevant_root_dirs | ||
|
||
- name: "{{{ rule_title }}} - Include Relevant Root Directories in a List of Paths to be Searched" | ||
ansible.builtin.set_fact: | ||
search_paths: "{{ search_paths | union([item.path]) }}" | ||
loop: "{{ result_relevant_root_dirs.files }}" | ||
|
||
- name: "{{{ rule_title }}} - Increment Search Paths List with Local Partitions Mount Points" | ||
ansible.builtin.set_fact: | ||
search_paths: "{{ search_paths | union([item.mount]) }}" | ||
loop: '{{ ansible_mounts }}' | ||
when: | ||
- item.fstype not in excluded_fstypes | ||
- item.mount != '/' | ||
{{{ ansible_create_list_of_local_paths(list_name="search_paths") }}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the fail of the test scenario
When executed local with a virtual machine back end the test is passing.
I think the problem isn't related to the contents of this PR. |
||
|
||
- name: "{{{ rule_title }}} - Increment Search Paths List with Local NFS File System Targets" | ||
- name: "{{{ rule_title }}} - Define Rule Specific Facts" | ||
ansible.builtin.set_fact: | ||
search_paths: "{{ search_paths | union([item.device.split(':')[1]]) }}" | ||
loop: '{{ ansible_mounts }}' | ||
when: | ||
- item.device is search("localhost:") | ||
world_writable_dirs: [] | ||
|
||
- name: "{{{ rule_title }}} - Find All Uncompliant Directories in Local File Systems" | ||
ansible.builtin.command: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this be reported as not permitted shell command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. It is using the
cmd
module and the test only cares aboutshell
module, so it won't be reported as an issue.