-
Notifications
You must be signed in to change notification settings - Fork 705
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The rule file_permission_user_init_files now checks only dot files of users with UID greater than or equal 1000. But according to RHEL 9 STIG and CIS benchmarks it should check also the root user's dot files. This commit creates a new rule file_permission_user_init_files_root which is almost the same as file_permission_user_init_files, but the new rule accounts also for the root user and his init files. We also change the OVAL jinja macro. This change will include the root user to the user list only if needed. We will use the root in the rule file_permission_user_init_file. But we will not use the root in accounts_user_interactive_home_directory_defined where we keep the old behavior. The commit also adds a simple test scenario covering this situation. Fixes: #11699
- Loading branch information
Showing
19 changed files
with
269 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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
34 changes: 34 additions & 0 deletions
34
.../system/accounts/accounts-session/file_permission_user_init_files_root/ansible/shared.yml
This file contains 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,34 @@ | ||
# platform = multi_platform_all | ||
# reboot = false | ||
# strategy = restrict | ||
# complexity = low | ||
# disruption = low | ||
|
||
{{{ ansible_instantiate_variables("var_user_initialization_files_regex") }}} | ||
|
||
|
||
- name: '{{{ rule_title }}} - Gather User Info' | ||
ansible.builtin.getent: | ||
database: passwd | ||
|
||
- name: '{{{ rule_title }}} - Find Init Files' | ||
ansible.builtin.find: | ||
paths: "{{ item.value[4] }}" | ||
pattern: "{{ var_user_initialization_files_regex }}" | ||
hidden: true | ||
use_regex: true | ||
with_dict: "{{ ansible_facts.getent_passwd }}" | ||
when: | ||
- item.value[4] != "/sbin/nologin" | ||
- item.key not in ["nobody", "nfsnobody"] | ||
- item.value[1] | int >= {{{ uid_min }}} or item.key == "root" | ||
register: found_init_files | ||
|
||
- name: '{{{ rule_title }}} - Fix Init Files Permissions' | ||
ansible.builtin.file: | ||
path: "{{ item.1.path }}" | ||
mode: u-s,g-wxs,o= | ||
loop: "{{ q('ansible.builtin.subelements', | ||
found_init_files.results, | ||
'files', | ||
{'skip_missing': True}) }}" |
26 changes: 26 additions & 0 deletions
26
...uide/system/accounts/accounts-session/file_permission_user_init_files_root/bash/shared.sh
This file contains 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,26 @@ | ||
# platform = multi_platform_all | ||
# reboot = false | ||
# strategy = restrict | ||
# complexity = low | ||
# disruption = low | ||
|
||
{{{ bash_instantiate_variables("var_user_initialization_files_regex") }}} | ||
|
||
readarray -t interactive_users < <(awk -F: '$3==0 || $3>={{{ uid_min }}} {print $1}' /etc/passwd) | ||
readarray -t interactive_users_home < <(awk -F: '$3==0 || $3>={{{ uid_min }}} {print $6}' /etc/passwd) | ||
readarray -t interactive_users_shell < <(awk -F: '$3==0 || $3>={{{ uid_min }}} {print $7}' /etc/passwd) | ||
|
||
USERS_IGNORED_REGEX='nobody|nfsnobody' | ||
|
||
for (( i=0; i<"${#interactive_users[@]}"; i++ )); do | ||
if ! grep -qP "$USERS_IGNORED_REGEX" <<< "${interactive_users[$i]}" && \ | ||
[ "${interactive_users_shell[$i]}" != "/sbin/nologin" ]; then | ||
|
||
readarray -t init_files < <(find "${interactive_users_home[$i]}" -maxdepth 1 \ | ||
-exec basename {} \; | grep -P "$var_user_initialization_files_regex") | ||
for file in "${init_files[@]}"; do | ||
chmod u-s,g-wxs,o= "${interactive_users_home[$i]}/$file" | ||
done | ||
fi | ||
done | ||
|
46 changes: 46 additions & 0 deletions
46
...ide/system/accounts/accounts-session/file_permission_user_init_files_root/oval/shared.xml
This file contains 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,46 @@ | ||
<def-group> | ||
<definition class="compliance" id="{{{ rule_id }}}" version="1"> | ||
{{{ oval_metadata("User initialization files have mode 0740 or less permissive") }}} | ||
<criteria> | ||
<criterion comment="Initialization files have mode 0740 or less permissive" | ||
test_ref="test_{{{ rule_id }}}" /> | ||
</criteria> | ||
</definition> | ||
|
||
<unix:file_test id="test_{{{ rule_id }}}" check="all" | ||
check_existence="any_exist" version="1" | ||
comment="Init files have mode 0740 or less permissive"> | ||
<unix:object object_ref="object_{{{ rule_id }}}"/> | ||
<unix:state state_ref="state_{{{ rule_id }}}"/> | ||
</unix:file_test> | ||
|
||
<unix:file_object id="object_{{{ rule_id }}}" version="1"> | ||
<unix:path var_ref="var_{{{ rule_id }}}_home_dirs" var_check="at least one"/> | ||
<unix:filename operation="pattern match" var_ref="var_user_initialization_files_regex"/> | ||
</unix:file_object> | ||
|
||
|
||
<unix:file_state id="state_{{{ rule_id }}}" operator="AND" version="1"> | ||
<unix:suid datatype="boolean">false</unix:suid> | ||
<unix:sgid datatype="boolean">false</unix:sgid> | ||
<unix:sticky datatype="boolean">false</unix:sticky> | ||
<unix:gwrite datatype="boolean">false</unix:gwrite> | ||
<unix:gexec datatype="boolean">false</unix:gexec> | ||
<unix:oread datatype="boolean">false</unix:oread> | ||
<unix:owrite datatype="boolean">false</unix:owrite> | ||
<unix:oexec datatype="boolean">false</unix:oexec> | ||
</unix:file_state> | ||
|
||
|
||
{{%- set interactive_users_object = "object_" ~ rule_id ~ "_objects" -%}} | ||
{{{ create_interactive_users_list_object(interactive_users_object, include_root=True) }}} | ||
|
||
<local_variable id="var_{{{ rule_id }}}_home_dirs" datatype="string" version="1" | ||
comment="Variable including all home dirs from interactive users"> | ||
<object_component item_field="home_dir" | ||
object_ref="{{{ interactive_users_object }}}"/> | ||
</local_variable> | ||
|
||
<external_variable comment="init files regex" datatype="int" | ||
id="var_user_initialization_files_regex" version="1" /> | ||
</def-group> |
28 changes: 28 additions & 0 deletions
28
...tem/accounts/accounts-session/file_permission_user_init_files_root/policy/stig/shared.yml
This file contains 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,28 @@ | ||
srg_requirement: |- | ||
All {{{ full_name }}} local initialization files must have mode 0740 or less permissive. | ||
vuldiscussion: |- | ||
Local initialization files are used to configure the user's shell environment upon logon. Malicious modification of these files could compromise accounts upon logon. | ||
checktext: |- | ||
Verify that all local initialization files have a mode of "0740" or less permissive with the following command: | ||
Note: The example will be for the "wadea" user, who has a home directory of "/home/wadea". | ||
$ sudo ls -al /home/wadea/.[^.]* | more | ||
-rwxr-xr-x 1 wadea users 896 Mar 10 2011 .profile | ||
-rwxr-xr-x 1 wadea users 497 Jan 6 2007 .login | ||
-rwxr-xr-x 1 wadea users 886 Jan 6 2007 .something | ||
If any local initialization files have a mode more permissive than "0740", this is a finding. | ||
fixtext: |- | ||
Set the mode of the local initialization files to "0740" with the following command: | ||
Note: The example will be for the wadea user, who has a home directory of "/home/wadea". | ||
$ sudo chmod 0740 /home/wadea/.<INIT_FILE> | ||
vuln_discussion: |- | ||
Local initialization files are used to configure the user's shell environment upon logon. Malicious modification of these files could compromise accounts upon logon. |
42 changes: 42 additions & 0 deletions
42
...x_os/guide/system/accounts/accounts-session/file_permission_user_init_files_root/rule.yml
This file contains 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,42 @@ | ||
documentation_complete: true | ||
|
||
title: 'Ensure All User Initialization Files Have Mode 0740 Or Less Permissive' | ||
|
||
description: |- | ||
Set the mode of the user initialization files, including the <tt>root</tt> user, | ||
to <tt>0740</tt> with the following commands: | ||
<pre> | ||
$ sudo chmod 0740 /root/.<i>INIT_FILE</i> | ||
$ sudo chmod 0740 /home/<i>USER</i>/.<i>INIT_FILE</i> | ||
</pre> | ||
rationale: |- | ||
Local initialization files are used to configure the user's shell environment | ||
upon logon. Malicious modification of these files could compromise accounts upon | ||
logon. | ||
severity: medium | ||
|
||
identifiers: | ||
cce@rhel9: CCE-87087-3 | ||
|
||
references: | ||
disa: CCI-000366 | ||
srg: SRG-OS-000480-GPOS-00227 | ||
|
||
ocil_clause: 'they are not 0740 or more permissive' | ||
|
||
ocil: |- | ||
To verify that all user initialization files have a mode of <tt>0740</tt> or | ||
less permissive, run the following command: | ||
<pre>$ sudo find /home -type f -name '\.*' \( -perm -0002 -o -perm -0020 \)</pre> | ||
There should be no output. | ||
fixtext: |- | ||
Set the mode of the local initialization files to "0740" with the following command: | ||
Note: The example will be for the smithj user, who has a home directory of "/home/smithj". | ||
$ sudo chmod 0740 /home/smithj/. | ||
srg_requirement: 'All {{{ full_name }}} local initialization files must have mode 0740 or less permissive.' |
7 changes: 7 additions & 0 deletions
7
...ounts/accounts-session/file_permission_user_init_files_root/tests/all_permissions.fail.sh
This file contains 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,7 @@ | ||
#!/bin/bash | ||
|
||
# variables = var_user_initialization_files_regex=\.init | ||
|
||
source common.sh | ||
|
||
chmod 7777 /home/dummy/.init |
17 changes: 17 additions & 0 deletions
17
...ide/system/accounts/accounts-session/file_permission_user_init_files_root/tests/common.sh
This file contains 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,17 @@ | ||
#!/bin/bash | ||
|
||
for username in $(awk -F: '($3>={{{ uid_min }}} && $3!=65534) {print $1}' /etc/passwd) | ||
do | ||
userdel -fr $username | ||
done | ||
|
||
touch /root/.init | ||
chmod 0740 /root/.init | ||
|
||
useradd -m dummy | ||
|
||
touch /home/dummy/.init | ||
chmod 0740 /home/dummy/.init | ||
|
||
touch /home/dummy/.ignored_file | ||
chmod 0777 /home/dummy/.ignored_file |
5 changes: 5 additions & 0 deletions
5
...s/accounts-session/file_permission_user_init_files_root/tests/correct_permissions.pass.sh
This file contains 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,5 @@ | ||
#!/bin/bash | ||
|
||
# variables = var_user_initialization_files_regex=\.init | ||
|
||
source common.sh |
10 changes: 10 additions & 0 deletions
10
...ion/file_permission_user_init_files_root/tests/different_home_correct_permissions.pass.sh
This file contains 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,10 @@ | ||
#!/bin/bash | ||
|
||
# variables = var_user_initialization_files_regex=\.init | ||
|
||
source common.sh | ||
|
||
useradd -d /var/dummy2 dummy2 | ||
|
||
touch /var/dummy2/.init | ||
chmod 0740 /var/dummy2/.init |
10 changes: 10 additions & 0 deletions
10
...ssion/file_permission_user_init_files_root/tests/different_home_wrong_permissions.fail.sh
This file contains 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,10 @@ | ||
#!/bin/bash | ||
|
||
# variables = var_user_initialization_files_regex=\.init | ||
|
||
source common.sh | ||
|
||
useradd -d /var/dummy2 dummy2 | ||
|
||
touch /var/dummy2/.init | ||
chmod 0750 /var/dummy2/.init |
7 changes: 7 additions & 0 deletions
7
...s/accounts-session/file_permission_user_init_files_root/tests/lenient_permissions.fail.sh
This file contains 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,7 @@ | ||
#!/bin/bash | ||
|
||
# variables = var_user_initialization_files_regex=\.init | ||
|
||
source common.sh | ||
|
||
chmod 0750 /home/dummy/.init |
8 changes: 8 additions & 0 deletions
8
...ounts-session/file_permission_user_init_files_root/tests/lenient_permissions_root.fail.sh
This file contains 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,8 @@ | ||
#!/bin/bash | ||
|
||
# variables = var_user_initialization_files_regex=\.init | ||
|
||
source common.sh | ||
|
||
touch /root/.init | ||
chmod 0750 /root/.init |
7 changes: 7 additions & 0 deletions
7
.../accounts-session/file_permission_user_init_files_root/tests/stricter_permissions.pass.sh
This file contains 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,7 @@ | ||
#!/bin/bash | ||
|
||
# variables = var_user_initialization_files_regex=\.init | ||
|
||
source common.sh | ||
|
||
chmod 0700 /home/dummy/.init |
This file contains 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 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 |
---|---|---|
|
@@ -479,7 +479,6 @@ CCE-87083-2 | |
CCE-87084-0 | ||
CCE-87085-7 | ||
CCE-87086-5 | ||
CCE-87087-3 | ||
CCE-87091-5 | ||
CCE-87092-3 | ||
CCE-87093-1 | ||
|
This file contains 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 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