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

Complete CIS requirement for system accounts #10627

Merged
merged 12 commits into from
May 24, 2023

Conversation

marcusburghardt
Copy link
Member

Description:

This PR updates the following rules:

  • no_password_auth_for_systemaccounts
    • Rule description updated
    • Included OVAL check
    • Included Bash and Ansible remediation
    • Included test scenarios
  • no_shelllogin_for_systemaccounts
    • Rule description updated
    • Included Bash and Ansible remediation
    • Updated test scenarios

Rationale:

Review Hints:

Automatus should be enough for tests
The commits are organized chronologically, to make it easier to review how the PR evolved.

@marcusburghardt marcusburghardt added RHEL9 Red Hat Enterprise Linux 9 product related. Update Rule Issues or pull requests related to Rules updates. RHEL8 Red Hat Enterprise Linux 8 product related. CIS CIS Benchmark related. labels May 23, 2023
@marcusburghardt marcusburghardt added this to the 0.1.68 milestone May 23, 2023
@marcusburghardt marcusburghardt requested a review from a team as a code owner May 23, 2023 21:29
@github-actions
Copy link

Start a new ephemeral environment with changes proposed in this pull request:

rhel8 (from CTF) Environment (using Fedora as testing environment)
Open in Gitpod

Fedora Testing Environment
Open in Gitpod

Oracle Linux 8 Environment
Open in Gitpod

@github-actions
Copy link

This datastream diff is auto generated by the check Compare DS/Generate Diff

Click here to see the full diff
New content has different text for rule 'xccdf_org.ssgproject.content_rule_no_password_auth_for_systemaccounts'.%0A--- xccdf_org.ssgproject.content_rule_no_password_auth_for_systemaccounts%0A+++ xccdf_org.ssgproject.content_rule_no_password_auth_for_systemaccounts%0A@@ -3,17 +3,13 @@%0A Ensure that System Accounts Are Locked%0A %0A [description]:%0A-Some accounts are not associated with a human user of the system, and exist to%0A-perform some administrative function. An attacker should not be able to log into%0A-these accounts.%0A+Some accounts are not associated with a human user of the system, and exist to perform some%0A+administrative functions. An attacker should not be able to log into these accounts.%0A %0A-System accounts are those user accounts with a user ID%0A-less than UID_MIN, where value of the UID_MIN directive is set in%0A-/etc/login.defs configuration file. In the default configuration UID_MIN is set%0A-to 500, thus system accounts are those user accounts with a user ID less than%0A-500. If any system account SYSACCT (other than root) has an unlocked password,%0A-disable it with the command:%0A-$ sudo passwd -l SYSACCT%0A+System accounts are those user accounts with a user ID less than 1000.%0A+If any system account other than root, halt, sync, shutdown%0A+and nfsnobody has an unlocked password, disable it with the command:%0A+$ sudo usermod -L account%0A %0A [reference]:%0A CIP-003-8 R5.1.1%0A@@ -48,6 +44,12 @@%0A [reference]:%0A CM-6(a)%0A %0A+[reference]:%0A+5.6.2%0A+%0A [rationale]:%0A-Disabling authentication for default system accounts makes it more difficult%0A-for attackers to make use of them to compromise a system.false%0A+Disabling authentication for default system accounts makes it more difficult for attackers%0A+to make use of them to compromise a system.%0A+%0A+[ident]:%0A+CCE-86112-0%0A%0ANew datastream adds OVAL for rule 'xccdf_org.ssgproject.content_rule_no_password_auth_for_systemaccounts'.%0AOCIL for rule 'xccdf_org.ssgproject.content_rule_no_password_auth_for_systemaccounts' differs.%0A--- ocil:ssg-no_password_auth_for_systemaccounts_ocil:questionnaire:1%0A+++ ocil:ssg-no_password_auth_for_systemaccounts_ocil:questionnaire:1%0A@@ -1,9 +1,5 @@%0A-To obtain a listing of all users and the contents of their shadow password%0A-field, run the command:%0A-$ sudo awk -F: '$1 !~ /^root$/ && $2 !~ /^[!*]/ {print $1 ":" $2}' /etc/shadow%0A-Identify the system accounts from this listing. These will primarily be the accounts%0A-with UID numbers less than UID_MIN, other than root. Value of the UID_MIN%0A-directive is set in /etc/login.defs configuration file. In the default%0A-configuration, UID_MIN is set to 500.%0A-      Is it the case that it is not?%0A+To obtain a list of all users and the content of their shadow password field, run the command:%0A+$ sudo readarray -t systemaccounts %0A+Verify if all accounts are locked.%0A+      Is it the case that system accounts are not locked?%0A       %0ANew datastream adds bash remediation for rule 'xccdf_org.ssgproject.content_rule_no_password_auth_for_systemaccounts'.%0ANew datastream adds ansible remediation for rule 'xccdf_org.ssgproject.content_rule_no_password_auth_for_systemaccounts'.%0ANew content has different text for rule 'xccdf_org.ssgproject.content_rule_no_shelllogin_for_systemaccounts'.%0A--- xccdf_org.ssgproject.content_rule_no_shelllogin_for_systemaccounts%0A+++ xccdf_org.ssgproject.content_rule_no_shelllogin_for_systemaccounts%0A@@ -3,22 +3,19 @@%0A Ensure that System Accounts Do Not Run a Shell Upon Login%0A %0A [description]:%0A-Some accounts are not associated with a human user of the system, and exist to%0A-perform some administrative function. Should an attacker be able to log into%0A-these accounts, they should not be granted access to a shell.%0A-%0A-The login shell for each local account is stored in the last field of each line%0A-in /etc/passwd. System accounts are those user accounts with a user ID%0A-less than UID_MIN, where value of UID_MIN directive is set in%0A-/etc/login.defs configuration file. In the default configuration UID_MIN is set%0A-to 1000, thus system accounts are those user accounts with a user ID less than%0A+Some accounts are not associated with a human user of the system, and exist to perform some%0A+administrative functions. Should an attacker be able to log into these accounts, they should%0A+not be granted access to a shell.%0A+%0A+The login shell for each local account is stored in the last field of each line in%0A+/etc/passwd. System accounts are those user accounts with a user ID less than%0A 1000. The user ID is stored in the third field. If any system account%0A-SYSACCT (other than root) has a login shell, disable it with the%0A-command: $ sudo usermod -s /sbin/nologin SYSACCT%0A+other than root has a login shell, disable it with the command:%0A+$ sudo usermod -s /sbin/nologin account%0A %0A [warning]:%0A-Do not perform the steps in this section on the root account. Doing so might%0A-cause the system to become inaccessible.%0A+Do not perform the steps in this section on the root account. Doing so might cause the%0A+system to become inaccessible.%0A %0A [reference]:%0A 1%0A@@ -210,8 +207,8 @@%0A 5.6.2%0A %0A [rationale]:%0A-Ensuring shells are not given to system accounts upon login makes it more%0A-difficult for attackers to make use of system accounts.%0A+Ensuring shells are not given to system accounts upon login makes it more difficult for%0A+attackers to make use of system accounts.%0A %0A [ident]:%0A CCE-80843-6%0A%0AOCIL for rule 'xccdf_org.ssgproject.content_rule_no_shelllogin_for_systemaccounts' differs.%0A--- ocil:ssg-no_shelllogin_for_systemaccounts_ocil:questionnaire:1%0A+++ ocil:ssg-no_shelllogin_for_systemaccounts_ocil:questionnaire:1%0A@@ -1,8 +1,6 @@%0A-To obtain a listing of all users, their UIDs, and their shells, run the%0A-command: $ awk -F: '{print $1 ":" $3 ":" $7}' /etc/passwd Identify%0A-the system accounts from this listing. These will primarily be the accounts%0A-with UID numbers less than UID_MIN, other than root. Value of the UID_MIN%0A-directive is set in /etc/login.defs configuration file. In the default%0A-configuration UID_MIN is set to 1000.%0A-      Is it the case that any system account (other than root) has a login shell?%0A+To obtain a listing of all users, their UIDs, and their shells, run the command:%0A+$ awk -F: '{print $1 ":" $3 ":" $7}' /etc/passwd%0A+Identify the system accounts from this listing. These will primarily be the accounts with UID%0A+numbers less than 1000, other than root.%0A+      Is it the case that any system account other than root has a login shell?%0A       %0ANew datastream adds bash remediation for rule 'xccdf_org.ssgproject.content_rule_no_shelllogin_for_systemaccounts'.%0ANew datastream adds ansible remediation for rule 'xccdf_org.ssgproject.content_rule_no_shelllogin_for_systemaccounts'.

@Mab879 Mab879 self-assigned this May 23, 2023
Copy link
Member

@Mab879 Mab879 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I just have couple of minor changes.

Mab879
Mab879 previously approved these changes May 24, 2023
@Mab879
Copy link
Member

Mab879 commented May 24, 2023

/packit build

@Mab879 Mab879 dismissed their stale review May 24, 2023 13:02

Needs a rebase for testing farm.

@Mab879
Copy link
Member

Mab879 commented May 24, 2023

Once #10628 lands in master, can you rebase this PR?

@Mab879
Copy link
Member

Mab879 commented May 24, 2023

#10628 has been merged to master.

Using a similar logic from the create_interactive_users_list_object
macro but focused in system accounts only.
The no_password_auth_for_systemaccounts was missing OVAL.
It is not capable to check if systems have system accounts with a
password defined.
Aligned to the Project Style Guide. Also updated description,
references, indentifiers, ocil and ocil_clause.
The no_password_auth_for_systemaccounts rule was moved from
related_rules to rules in CIS control file for RHEL8 and RHEL9.
Aligned to the Project Style Guide. Also updated description,
ocil, ocil_clause and fixtext.
The CIS 5.6.2 requirement for RHEL8 and RHEL9 is now automated.
Relevant rules include OVAL checking plus Bash and Ansible
remediation.
@marcusburghardt
Copy link
Member Author

Once #10628 lands in master, can you rebase this PR?

Rebased

@codeclimate
Copy link

codeclimate bot commented May 24, 2023

Code Climate has analyzed commit fb89db4 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 52.5% (0.0% change).

View more on Code Climate.

@Mab879
Copy link
Member

Mab879 commented May 24, 2023

I'm waving the Automatus failures as the tests pass locally.

@Mab879 Mab879 merged commit 7971805 into ComplianceAsCode:master May 24, 2023
@marcusburghardt marcusburghardt deleted the cis_system_accounts branch May 24, 2023 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CIS CIS Benchmark related. RHEL8 Red Hat Enterprise Linux 8 product related. RHEL9 Red Hat Enterprise Linux 9 product related. Update Rule Issues or pull requests related to Rules updates.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RHEL 8 CIS 5.4.2 Ensure system accounts are secured (Automated)
2 participants