|
|
ff1465 |
From 5ec53805a4aaf04752400eef826ff49222c0a3ba Mon Sep 17 00:00:00 2001
|
|
|
ff1465 |
From: Marcus Burghardt <maburgha@redhat.com>
|
|
|
ff1465 |
Date: Wed, 20 Oct 2021 16:17:01 +0200
|
|
|
ff1465 |
Subject: [PATCH 1/3] OVAL, tests and remediation for the rule:
|
|
|
ff1465 |
|
|
|
ff1465 |
accounts_user_interactive_home_directory_defined
|
|
|
ff1465 |
---
|
|
|
ff1465 |
.../ansible/shared.yml | 24 +++++++++++++
|
|
|
ff1465 |
.../bash/shared.sh | 9 +++++
|
|
|
ff1465 |
.../oval/shared.xml | 36 +++++++++++++++++++
|
|
|
ff1465 |
.../tests/home_dir_all_empty.fail.sh | 6 ++++
|
|
|
ff1465 |
.../tests/home_dir_not_exclusive.fail.sh | 6 ++++
|
|
|
ff1465 |
.../tests/home_dir_one_empty.fail.sh | 8 +++++
|
|
|
ff1465 |
.../tests/home_dir_properly_defined.pass.sh | 4 +++
|
|
|
ff1465 |
.../tests/home_dir_root.fail.sh | 6 ++++
|
|
|
ff1465 |
.../tests/interactive_users_absent.pass.sh | 4 +++
|
|
|
ff1465 |
9 files changed, 103 insertions(+)
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/ansible/shared.yml
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/bash/shared.sh
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/oval/shared.xml
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_all_empty.fail.sh
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_not_exclusive.fail.sh
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_one_empty.fail.sh
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_properly_defined.pass.sh
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_root.fail.sh
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/interactive_users_absent.pass.sh
|
|
|
ff1465 |
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/ansible/shared.yml b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/ansible/shared.yml
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..fc9b780daa8
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/ansible/shared.yml
|
|
|
ff1465 |
@@ -0,0 +1,24 @@
|
|
|
ff1465 |
+# platform = multi_platform_all
|
|
|
ff1465 |
+# reboot = false
|
|
|
ff1465 |
+# strategy = restrict
|
|
|
ff1465 |
+# complexity = low
|
|
|
ff1465 |
+# disruption = low
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+- name: Get all local users from /etc/passwd
|
|
|
ff1465 |
+ ansible.builtin.getent:
|
|
|
ff1465 |
+ database: passwd
|
|
|
ff1465 |
+ split: ':'
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+- name: Create local_users variable from the getent output
|
|
|
ff1465 |
+ ansible.builtin.set_fact:
|
|
|
ff1465 |
+ local_users: '{{ ansible_facts.getent_passwd|dict2items }}'
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+- name: Ensure interactive users have a home directory defined
|
|
|
ff1465 |
+ ansible.builtin.user:
|
|
|
ff1465 |
+ name: '{{ item.key }}'
|
|
|
ff1465 |
+ home: '/home/{{ item.key }}'
|
|
|
ff1465 |
+ create_home: no
|
|
|
ff1465 |
+ loop: '{{ local_users }}'
|
|
|
ff1465 |
+ when:
|
|
|
ff1465 |
+ - item.value[2]|int >= {{{ uid_min }}}
|
|
|
ff1465 |
+ - item.value[2]|int != 65534
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/bash/shared.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/bash/shared.sh
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..23b0a85aa6a
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/bash/shared.sh
|
|
|
ff1465 |
@@ -0,0 +1,9 @@
|
|
|
ff1465 |
+# platform = multi_platform_all
|
|
|
ff1465 |
+# reboot = false
|
|
|
ff1465 |
+# strategy = restrict
|
|
|
ff1465 |
+# complexity = low
|
|
|
ff1465 |
+# disruption = low
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+for user in `awk -F':' '{ if ($4 >= {{{ uid_min }}} && $4 != 65534) print $1 }' /etc/passwd`; do
|
|
|
ff1465 |
+ sed -i "s/\($user:x:[0-9]*:[0-9]*:.*:\).*\(:.*\)$/\1\/home\/$user\2/g" /etc/passwd;
|
|
|
ff1465 |
+done
|
|
|
ff1465 |
\ No newline at end of file
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/oval/shared.xml b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/oval/shared.xml
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..5efb84ab2cf
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/oval/shared.xml
|
|
|
ff1465 |
@@ -0,0 +1,36 @@
|
|
|
ff1465 |
+<def-group>
|
|
|
ff1465 |
+ <definition class="compliance" id="{{{ rule_id }}}" version="1">
|
|
|
ff1465 |
+ {{{ oval_metadata("All Interactive Users Must Have A Home Directory Defined") }}}
|
|
|
ff1465 |
+ <criteria>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ comment="All Interactive Users Must Have A Home Directory Defined"/>
|
|
|
ff1465 |
+ </criteria>
|
|
|
ff1465 |
+ </definition>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ "file_ownership_home_directories" rule.
|
|
|
ff1465 |
+ #### creation of object #### -->
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ version="1">
|
|
|
ff1465 |
+ <unix:username datatype="string" operation="not equal">nobody</unix:username>
|
|
|
ff1465 |
+ <filter action="include">state_accounts_user_interactive_home_directory_defined_uids</filter>
|
|
|
ff1465 |
+ </unix:password_object>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ version="1">
|
|
|
ff1465 |
+ <unix:user_id datatype="int" operation="greater than or equal">{{{ uid_min }}}</unix:user_id>
|
|
|
ff1465 |
+ </unix:password_state>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ <unix:password_state id="state_accounts_user_interactive_home_directory_defined" version="1">
|
|
|
ff1465 |
+ <unix:home_dir operation="pattern match">^\/\w*\/\w{1,}[\/\w]*$</unix:home_dir>
|
|
|
ff1465 |
+ </unix:password_state>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ check_existence="any_exist" version="1"
|
|
|
ff1465 |
+ comment="All Interactive Users Have A Home Directory Defined">
|
|
|
ff1465 |
+ <unix:object object_ref="object_accounts_user_interactive_home_directory_defined_objects"/>
|
|
|
ff1465 |
+ <unix:state state_ref="state_accounts_user_interactive_home_directory_defined"/>
|
|
|
ff1465 |
+ </unix:password_test>
|
|
|
ff1465 |
+</def-group>
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_all_empty.fail.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_all_empty.fail.sh
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..4bc9e10a21c
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_all_empty.fail.sh
|
|
|
ff1465 |
@@ -0,0 +1,6 @@
|
|
|
ff1465 |
+#!/bin/bash
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+USER="cac_user"
|
|
|
ff1465 |
+useradd -M $USER
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+sed -i "s/\(.*:x:[0-9]\{4,\}:[0-9]*:.*:\).*\(:.*\)$/\1\2/g" /etc/passwd
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_not_exclusive.fail.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_not_exclusive.fail.sh
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..5c905e03791
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_not_exclusive.fail.sh
|
|
|
ff1465 |
@@ -0,0 +1,6 @@
|
|
|
ff1465 |
+#!/bin/bash
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+USER="cac_user"
|
|
|
ff1465 |
+useradd -M $USER
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+sed -i 's/\(.*:x:[0-9]\{4,\}:[0-9]*:.*:\).*\(:.*\)$/\1\/tmp\2/g' /etc/passwd
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_one_empty.fail.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_one_empty.fail.sh
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..00d37799c77
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_one_empty.fail.sh
|
|
|
ff1465 |
@@ -0,0 +1,8 @@
|
|
|
ff1465 |
+#!/bin/bash
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+USER1="cac_user1"
|
|
|
ff1465 |
+USER2="cac_user2"
|
|
|
ff1465 |
+useradd -M $USER1
|
|
|
ff1465 |
+useradd -M $USER2
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+sed -i "s/\($USER1:x:[0-9]*:[0-9]*:.*:\).*\(:.*\)$/\1\2/g" /etc/passwd
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_properly_defined.pass.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_properly_defined.pass.sh
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..7c181afdd4b
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_properly_defined.pass.sh
|
|
|
ff1465 |
@@ -0,0 +1,4 @@
|
|
|
ff1465 |
+#!/bin/bash
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+USER="cac_user"
|
|
|
ff1465 |
+useradd -M $USER
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_root.fail.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_root.fail.sh
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..16bb94477bc
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_root.fail.sh
|
|
|
ff1465 |
@@ -0,0 +1,6 @@
|
|
|
ff1465 |
+#!/bin/bash
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+USER="cac_user"
|
|
|
ff1465 |
+useradd -M $USER
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+sed -i "s/\($USER:x:[0-9]*:[0-9]*:.*:\).*\(:.*\)$/\1\/\2/g" /etc/passwd
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/interactive_users_absent.pass.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/interactive_users_absent.pass.sh
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..ed34f0940a7
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/interactive_users_absent.pass.sh
|
|
|
ff1465 |
@@ -0,0 +1,4 @@
|
|
|
ff1465 |
+#!/bin/bash
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+# remove all interactive users (ID >= 1000) from /etc/passwd
|
|
|
ff1465 |
+sed -i '/.*:[0-9]\{4,\}:/d' /etc/passwd
|
|
|
ff1465 |
|
|
|
ff1465 |
From 47cf69c176ce8e7ec1922bf8cdcd1d35b02552c9 Mon Sep 17 00:00:00 2001
|
|
|
ff1465 |
From: Marcus Burghardt <maburgha@redhat.com>
|
|
|
ff1465 |
Date: Tue, 26 Oct 2021 14:39:11 +0200
|
|
|
ff1465 |
Subject: [PATCH 2/3] OVAL, tests and remediation for the rule:
|
|
|
ff1465 |
|
|
|
ff1465 |
accounts_user_interactive_home_directory_exists
|
|
|
ff1465 |
---
|
|
|
ff1465 |
.../bash/shared.sh | 2 +-
|
|
|
ff1465 |
.../ansible/shared.yml | 24 +++++
|
|
|
ff1465 |
.../bash/shared.sh | 9 ++
|
|
|
ff1465 |
.../oval/shared.xml | 91 +++++++++++++++++++
|
|
|
ff1465 |
.../tests/home_dir_present.pass.sh | 10 ++
|
|
|
ff1465 |
.../tests/home_dirs_all_absent.fail.sh | 6 ++
|
|
|
ff1465 |
.../tests/home_dirs_one_absent.fail.sh | 7 ++
|
|
|
ff1465 |
.../tests/interactive_users_absent.pass.sh | 4 +
|
|
|
ff1465 |
8 files changed, 152 insertions(+), 1 deletion(-)
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/ansible/shared.yml
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/bash/shared.sh
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/oval/shared.xml
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/home_dir_present.pass.sh
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/home_dirs_all_absent.fail.sh
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/home_dirs_one_absent.fail.sh
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/interactive_users_absent.pass.sh
|
|
|
ff1465 |
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/bash/shared.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/bash/shared.sh
|
|
|
ff1465 |
index 23b0a85aa6a..94f8a579f1f 100644
|
|
|
ff1465 |
--- a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/bash/shared.sh
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/bash/shared.sh
|
|
|
ff1465 |
@@ -6,4 +6,4 @@
|
|
|
ff1465 |
|
|
|
ff1465 |
for user in `awk -F':' '{ if ($4 >= {{{ uid_min }}} && $4 != 65534) print $1 }' /etc/passwd`; do
|
|
|
ff1465 |
sed -i "s/\($user:x:[0-9]*:[0-9]*:.*:\).*\(:.*\)$/\1\/home\/$user\2/g" /etc/passwd;
|
|
|
ff1465 |
-done
|
|
|
ff1465 |
\ No newline at end of file
|
|
|
ff1465 |
+done
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/ansible/shared.yml b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/ansible/shared.yml
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..e7acc477d25
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/ansible/shared.yml
|
|
|
ff1465 |
@@ -0,0 +1,24 @@
|
|
|
ff1465 |
+# platform = multi_platform_all
|
|
|
ff1465 |
+# reboot = false
|
|
|
ff1465 |
+# strategy = restrict
|
|
|
ff1465 |
+# complexity = low
|
|
|
ff1465 |
+# disruption = low
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+- name: Get all local users from /etc/passwd
|
|
|
ff1465 |
+ ansible.builtin.getent:
|
|
|
ff1465 |
+ database: passwd
|
|
|
ff1465 |
+ split: ':'
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+- name: Create local_users variable from the getent output
|
|
|
ff1465 |
+ ansible.builtin.set_fact:
|
|
|
ff1465 |
+ local_users: '{{ ansible_facts.getent_passwd|dict2items }}'
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+- name: Ensure interactive users have a home directory defined
|
|
|
ff1465 |
+ ansible.builtin.user:
|
|
|
ff1465 |
+ name: '{{ item.key }}'
|
|
|
ff1465 |
+ home: '/home/{{ item.key }}'
|
|
|
ff1465 |
+ create_home: yes
|
|
|
ff1465 |
+ loop: '{{ local_users }}'
|
|
|
ff1465 |
+ when:
|
|
|
ff1465 |
+ - item.value[2]|int >= {{{ uid_min }}}
|
|
|
ff1465 |
+ - item.value[2]|int != 65534
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/bash/shared.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/bash/shared.sh
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..044b650f103
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/bash/shared.sh
|
|
|
ff1465 |
@@ -0,0 +1,9 @@
|
|
|
ff1465 |
+# platform = multi_platform_all
|
|
|
ff1465 |
+# reboot = false
|
|
|
ff1465 |
+# strategy = restrict
|
|
|
ff1465 |
+# complexity = low
|
|
|
ff1465 |
+# disruption = low
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+for user in $(awk -F':' '{ if ($4 >= {{{ uid_min }}} && $4 != 65534) print $1}' /etc/passwd); do
|
|
|
ff1465 |
+ mkhomedir_helper $user 0077;
|
|
|
ff1465 |
+done
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/oval/shared.xml b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/oval/shared.xml
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..0a5b313f5b4
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/oval/shared.xml
|
|
|
ff1465 |
@@ -0,0 +1,91 @@
|
|
|
ff1465 |
+<def-group>
|
|
|
ff1465 |
+ <definition class="compliance" id="{{{ rule_id }}}" version="1">
|
|
|
ff1465 |
+ {{{ oval_metadata("All Interactive Users Home Directories Must Exist") }}}
|
|
|
ff1465 |
+ <criteria operator="OR">
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ comment="All Interactive Users Home Directories Must Exist"/>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ comment="Interactive users don't exist on the system"/>
|
|
|
ff1465 |
+ </criteria>
|
|
|
ff1465 |
+ </definition>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ version="1">
|
|
|
ff1465 |
+ <unix:username datatype="string" operation="not equal">nobody</unix:username>
|
|
|
ff1465 |
+ <filter action="include">state_accounts_user_interactive_home_directory_exists_uids</filter>
|
|
|
ff1465 |
+ </unix:password_object>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ <unix:password_state id="state_accounts_user_interactive_home_directory_exists_uids" version="1">
|
|
|
ff1465 |
+ <unix:user_id datatype="int" operation="greater than or equal">{{{ uid_min }}}</unix:user_id>
|
|
|
ff1465 |
+ </unix:password_state>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ datatype="string" version="1"
|
|
|
ff1465 |
+ comment="Variable including all home dirs from interactive users">
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ object_ref="object_accounts_user_interactive_home_directory_exists_objects"/>
|
|
|
ff1465 |
+ </local_variable>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ datatype="int" version="1"
|
|
|
ff1465 |
+ comment="Variable including expected count of home dirs present on the system">
|
|
|
ff1465 |
+ <count>
|
|
|
ff1465 |
+ <variable_component var_ref="var_accounts_user_interactive_home_directory_exists_dirs_list"/>
|
|
|
ff1465 |
+ </count>
|
|
|
ff1465 |
+ </local_variable>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ version="1">
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ var_check="at least one"/>
|
|
|
ff1465 |
+ <unix:filename xsi:nil="true"/>
|
|
|
ff1465 |
+ </unix:file_object>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ datatype="int" version="1"
|
|
|
ff1465 |
+ comment="Variable including number of home dirs present on file system">
|
|
|
ff1465 |
+ <count>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ object_ref="object_accounts_user_interactive_home_directory_exists_dirs_fs"/>
|
|
|
ff1465 |
+ </count>
|
|
|
ff1465 |
+ </local_variable>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ version="1">
|
|
|
ff1465 |
+ <ind:var_ref>var_accounts_user_interactive_home_directory_exists_dirs_count_fs</ind:var_ref>
|
|
|
ff1465 |
+ </ind:variable_object>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ version="1">
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ var_ref="var_accounts_user_interactive_home_directory_exists_dirs_count"/>
|
|
|
ff1465 |
+ </ind:variable_state>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ check_existence="at_least_one_exists" version="1"
|
|
|
ff1465 |
+ comment="Check the existence of interactive users.">
|
|
|
ff1465 |
+ <ind:object object_ref="object_accounts_user_interactive_home_directory_exists_dirs_count_fs"/>
|
|
|
ff1465 |
+ <ind:state state_ref="state_accounts_user_interactive_home_directory_exists_dirs_count_pw"/>
|
|
|
ff1465 |
+ </ind:variable_test>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ version="1">
|
|
|
ff1465 |
+ <ind:var_ref>var_accounts_user_interactive_home_directory_exists_dirs_count</ind:var_ref>
|
|
|
ff1465 |
+ </ind:variable_object>
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+ check_existence="none_exist" version="1"
|
|
|
ff1465 |
+ comment="Check the existence of interactive users.">
|
|
|
ff1465 |
+ <ind:object object_ref="object_accounts_user_interactive_home_directory_exists_dirs_count_pw"/>
|
|
|
ff1465 |
+ </ind:variable_test>
|
|
|
ff1465 |
+</def-group>
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/home_dir_present.pass.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/home_dir_present.pass.sh
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..d5434cbe4f5
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/home_dir_present.pass.sh
|
|
|
ff1465 |
@@ -0,0 +1,10 @@
|
|
|
ff1465 |
+#!/bin/bash
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+USER="cac_user"
|
|
|
ff1465 |
+useradd -m $USER
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+# This is to make sure that any possible user create in the test environment has also
|
|
|
ff1465 |
+# a home dir created on the system.
|
|
|
ff1465 |
+for user in $(awk -F':' '{ if ($4 >= {{{ uid_min }}} && $4 != 65534) print $1}' /etc/passwd); do
|
|
|
ff1465 |
+ mkhomedir_helper $user 0077;
|
|
|
ff1465 |
+done
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/home_dirs_all_absent.fail.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/home_dirs_all_absent.fail.sh
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..af240252de3
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/home_dirs_all_absent.fail.sh
|
|
|
ff1465 |
@@ -0,0 +1,6 @@
|
|
|
ff1465 |
+#!/bin/bash
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+USER="cac_user"
|
|
|
ff1465 |
+useradd -M $USER
|
|
|
ff1465 |
+# This make sure home dirs related to test environment users are also removed.
|
|
|
ff1465 |
+rm -Rf /home/*
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/home_dirs_one_absent.fail.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/home_dirs_one_absent.fail.sh
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..5bce517215c
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/home_dirs_one_absent.fail.sh
|
|
|
ff1465 |
@@ -0,0 +1,7 @@
|
|
|
ff1465 |
+#!/bin/bash
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+USER1="cac_user1"
|
|
|
ff1465 |
+USER2="cac_user2"
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+useradd -m $USER1
|
|
|
ff1465 |
+useradd -M $USER2
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/interactive_users_absent.pass.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/interactive_users_absent.pass.sh
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..ed34f0940a7
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/interactive_users_absent.pass.sh
|
|
|
ff1465 |
@@ -0,0 +1,4 @@
|
|
|
ff1465 |
+#!/bin/bash
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+# remove all interactive users (ID >= 1000) from /etc/passwd
|
|
|
ff1465 |
+sed -i '/.*:[0-9]\{4,\}:/d' /etc/passwd
|
|
|
ff1465 |
|
|
|
ff1465 |
From 0d6a5e588d71e927291641cbf2a23259995f0b2d Mon Sep 17 00:00:00 2001
|
|
|
ff1465 |
From: Marcus Burghardt <maburgha@redhat.com>
|
|
|
ff1465 |
Date: Mon, 8 Nov 2021 15:09:12 +0100
|
|
|
ff1465 |
Subject: [PATCH 3/3] Improved the remediation and rule description
|
|
|
ff1465 |
|
|
|
ff1465 |
Included conditional on remediation to make sure that
|
|
|
ff1465 |
already compliant home directories are skipped.
|
|
|
ff1465 |
---
|
|
|
ff1465 |
.../ansible/shared.yml | 3 ++-
|
|
|
ff1465 |
.../bash/shared.sh | 7 +++++--
|
|
|
ff1465 |
.../rule.yml | 5 +++++
|
|
|
ff1465 |
.../tests/home_dir_defined_out_home.pass.sh | 4 ++++
|
|
|
ff1465 |
.../ansible/shared.yml | 3 +--
|
|
|
ff1465 |
5 files changed, 17 insertions(+), 5 deletions(-)
|
|
|
ff1465 |
create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_defined_out_home.pass.sh
|
|
|
ff1465 |
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/ansible/shared.yml b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/ansible/shared.yml
|
|
|
ff1465 |
index fc9b780daa8..13fbdd1ca44 100644
|
|
|
ff1465 |
--- a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/ansible/shared.yml
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/ansible/shared.yml
|
|
|
ff1465 |
@@ -13,7 +13,7 @@
|
|
|
ff1465 |
ansible.builtin.set_fact:
|
|
|
ff1465 |
local_users: '{{ ansible_facts.getent_passwd|dict2items }}'
|
|
|
ff1465 |
|
|
|
ff1465 |
-- name: Ensure interactive users have a home directory defined
|
|
|
ff1465 |
+- name: Ensure interactive users have an exclusive home directory defined
|
|
|
ff1465 |
ansible.builtin.user:
|
|
|
ff1465 |
name: '{{ item.key }}'
|
|
|
ff1465 |
home: '/home/{{ item.key }}'
|
|
|
ff1465 |
@@ -22,3 +22,4 @@
|
|
|
ff1465 |
when:
|
|
|
ff1465 |
- item.value[2]|int >= {{{ uid_min }}}
|
|
|
ff1465 |
- item.value[2]|int != 65534
|
|
|
ff1465 |
+ - not item.value[4] | regex_search('^\/\w*\/\w{1,}')
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/bash/shared.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/bash/shared.sh
|
|
|
ff1465 |
index 94f8a579f1f..7fac61d4892 100644
|
|
|
ff1465 |
--- a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/bash/shared.sh
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/bash/shared.sh
|
|
|
ff1465 |
@@ -4,6 +4,9 @@
|
|
|
ff1465 |
# complexity = low
|
|
|
ff1465 |
# disruption = low
|
|
|
ff1465 |
|
|
|
ff1465 |
-for user in `awk -F':' '{ if ($4 >= {{{ uid_min }}} && $4 != 65534) print $1 }' /etc/passwd`; do
|
|
|
ff1465 |
- sed -i "s/\($user:x:[0-9]*:[0-9]*:.*:\).*\(:.*\)$/\1\/home\/$user\2/g" /etc/passwd;
|
|
|
ff1465 |
+for user in $(awk -F':' '{ if ($4 >= {{{ uid_min }}} && $4 != 65534) print $1 }' /etc/passwd); do
|
|
|
ff1465 |
+ # This follows the same logic of evaluation of home directories as used in OVAL.
|
|
|
ff1465 |
+ if ! grep -q $user /etc/passwd | cut -d: -f6 | grep '^\/\w*\/\w\{1,\}'; then
|
|
|
ff1465 |
+ sed -i "s/\($user:x:[0-9]*:[0-9]*:.*:\).*\(:.*\)$/\1\/home\/$user\2/g" /etc/passwd;
|
|
|
ff1465 |
+ fi
|
|
|
ff1465 |
done
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/rule.yml b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/rule.yml
|
|
|
ff1465 |
index 20d26032338..b58164c5403 100644
|
|
|
ff1465 |
--- a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/rule.yml
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/rule.yml
|
|
|
ff1465 |
@@ -8,6 +8,11 @@ description: |-
|
|
|
ff1465 |
Assign home directories to all interactive users that currently do not
|
|
|
ff1465 |
have a home directory assigned.
|
|
|
ff1465 |
|
|
|
ff1465 |
+ This rule checks if the home directory is properly defined in a folder which has
|
|
|
ff1465 |
+ at least one parent folder, like "user" in "/home/user" or "/remote/users/user".
|
|
|
ff1465 |
+ Therefore, this rule will report a finding for home directories like <tt>/users</tt>,
|
|
|
ff1465 |
+ <tt>/tmp</tt> or <tt>/</tt>.
|
|
|
ff1465 |
+
|
|
|
ff1465 |
rationale: |-
|
|
|
ff1465 |
If local interactive users are not assigned a valid home directory, there is no
|
|
|
ff1465 |
place for the storage and control of files they should own.
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_defined_out_home.pass.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_defined_out_home.pass.sh
|
|
|
ff1465 |
new file mode 100644
|
|
|
ff1465 |
index 00000000000..c7100f304ca
|
|
|
ff1465 |
--- /dev/null
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_defined/tests/home_dir_defined_out_home.pass.sh
|
|
|
ff1465 |
@@ -0,0 +1,4 @@
|
|
|
ff1465 |
+#!/bin/bash
|
|
|
ff1465 |
+
|
|
|
ff1465 |
+USER="cac_user"
|
|
|
ff1465 |
+useradd -M -d /data/$USER $USER
|
|
|
ff1465 |
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/ansible/shared.yml b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/ansible/shared.yml
|
|
|
ff1465 |
index e7acc477d25..84382a7f488 100644
|
|
|
ff1465 |
--- a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/ansible/shared.yml
|
|
|
ff1465 |
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/ansible/shared.yml
|
|
|
ff1465 |
@@ -13,10 +13,9 @@
|
|
|
ff1465 |
ansible.builtin.set_fact:
|
|
|
ff1465 |
local_users: '{{ ansible_facts.getent_passwd|dict2items }}'
|
|
|
ff1465 |
|
|
|
ff1465 |
-- name: Ensure interactive users have a home directory defined
|
|
|
ff1465 |
+- name: Ensure interactive users have a home directory exists
|
|
|
ff1465 |
ansible.builtin.user:
|
|
|
ff1465 |
name: '{{ item.key }}'
|
|
|
ff1465 |
- home: '/home/{{ item.key }}'
|
|
|
ff1465 |
create_home: yes
|
|
|
ff1465 |
loop: '{{ local_users }}'
|
|
|
ff1465 |
when:
|