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

Change rules related to /etc/shadow to check only local user configuration #10838

Merged
merged 11 commits into from
Jul 18, 2023

Conversation

jan-cerny
Copy link
Collaborator

Description:

This PR changes OVAL checks in rules that are related to /etc/shadow configuration in a way that the OVAL check will use OVAL textfilecontent54_test to parse data directly from /etc/shadow instead of using the OVAL shadow_test.

This PR changes the following rules:

  • accounts_password_set_max_life_existing
  • accounts_password_set_min_life_existing
  • accounts_password_set_warn_age_existing
  • accounts_set_post_pw_existing

Moreover, some OVAL code was refactored to Jinja macros in order to share code and prevent code duplication.

Rationale:

Using OVAL shadow_test means that the checks also consider remote (LDAP) users, because the implementation of the shadow probe in OpenSCAP uses the getpwent() function which read all users from NSS maps, including non-local users. That isn't desired. The rules should check local configuration. The remediation can't fix remote users, only local ones.
I think it is reasonable to change scope of those rules so that remediation and check are aligned.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2213958

Review Hints:

python3 tests/automatus.py rule --dontclean --libvirt qemu:///system ssgts_rhel9 accounts_password_set_max_life_existing accounts_password_set_min_life_existing accounts_password_set_warn_age_existing accounts_set_post_pw_existing

@jan-cerny jan-cerny added bugfix Fixes to reported bugs. OVAL OVAL update. Related to the systems assessments. Update Rule Issues or pull requests related to Rules updates. labels Jul 13, 2023
@jan-cerny jan-cerny added this to the 0.1.69 milestone Jul 13, 2023
@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
OVAL for rule 'xccdf_org.ssgproject.content_rule_accounts_password_set_max_life_existing' differs.
--- oval:ssg-accounts_password_set_max_life_existing:def:1
+++ oval:ssg-accounts_password_set_max_life_existing:def:1
@@ -1,3 +1,4 @@
 criteria AND
-criterion oval:ssg-test_password_max_life_existing:tst:1
-criterion oval:ssg-test_password_max_life_existing_minimum:tst:1
+criterion oval:ssg-test_accounts_password_set_max_life_existing_password_max_life_existing:tst:1
+criterion oval:ssg-test_accounts_password_set_max_life_existing_password_max_life_existing_minimum:tst:1
+criterion oval:ssg-test_accounts_password_set_max_life_existing_password_max_life_not_empty:tst:1

OVAL for rule 'xccdf_org.ssgproject.content_rule_accounts_password_set_min_life_existing' differs.
--- oval:ssg-accounts_password_set_min_life_existing:def:1
+++ oval:ssg-accounts_password_set_min_life_existing:def:1
@@ -1,3 +1,4 @@
 criteria AND
-criterion oval:ssg-test_password_min_life_existing:tst:1
-criterion oval:ssg-test_password_min_life_existing_maximum:tst:1
+criterion oval:ssg-test_accounts_password_set_min_life_existing_password_max_life_existing:tst:1
+criterion oval:ssg-test_accounts_password_set_min_life_existing_password_max_life_existing_minimum:tst:1
+criterion oval:ssg-test_accounts_password_set_min_life_existing_password_max_life_not_empty:tst:1

@jan-cerny
Copy link
Collaborator Author

I have removed a parameter that has a low meaning.

Change OVAL in rule `accounts_password_set_max_life_existing` so that
it doesn't use the OVAL "unix:shadow_object" element which
checks also remote users via NSS. Instead, it will parse `/etc/shadow`
using the "ind:textfilecontent54_object" which will include only
local users.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2213958
Moving the OVAL code to a new jinja macro `etc_shadow_test` will
allow us to reduce the code in other similar rules.
Change OVAL in rule `accounts_password_set_min_life_existing` so that
it doesn't use the OVAL "unix:shadow_object" element which
checks also remote users via NSS. Instead, it will parse `/etc/shadow`
using the "ind:textfilecontent54_object" which will include only
local users.

This change is similar to the recent change that has been done in
`accounts_password_set_max_life_existing` and leverages the OVAL
macro.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2213958
Change OVAL in rule `accounts_password_set_warn_age_existing` so that
it doesn't use the OVAL "unix:shadow_object" element which
checks also remote users via NSS. Instead, it will parse `/etc/shadow`
using the "ind:textfilecontent54_object" which will include only
local users.

This change is similar to the recent change that has been done in
`accounts_password_set_max_life_existing` and
`accounts_password_set_min_life_existing`.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2213958
Extracts some OVAL code to a new macro textfilecontent54_test_etc_shadow
which can be reused later.
In rule accounts_password_set_warn_age_existing we will
replace an OVAL test with a macro textfilecontent54_test_etc_shadow
to reduce code duplication.
Change OVAL in rule `accounts_set_post_pw_existing` so that
it doesn't use the OVAL "unix:shadow_object" element which
checks also remote users via NSS. Instead, it will parse `/etc/shadow`
using the "ind:textfilecontent54_object" which will include only
local users.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2213958
Unify the OVAL code used in rules accounts_password_set_warn_age_existing
and accounts_set_post_pw_existing. The code is very similar so it
can be easily replaced by a Jinja macro. That prevents a code
duplication.
We will remove the `field` parameter of the macro `etc_shadow_test`
because this parameter is only substituted into an XML comment in
OVAL and doesn't impact the actual behavior, so its added value
is low I think.
@jan-cerny
Copy link
Collaborator Author

I have rebased this PR on the top of the latest upstream master branch.

@vojtapolasek vojtapolasek self-assigned this Jul 17, 2023

<ind:textfilecontent54_object id="object_{{{ test_id }}}" version="1">
<ind:filepath>/etc/shadow</ind:filepath>
<!-- filters away accounts with no passwords and locked passwords (passwords are located in the 2nd field)-->
Copy link
Collaborator

Choose a reason for hiding this comment

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

@jan-cerny I don't understand this comment. Can you explain please? It confuses me because the next regexp is supplied in form of macro argument.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right that it's confusing. It's left there from the previous version where this wasn't a macro. Although in the current state it generates a correct statement in the generated OVAL, it doesn't make sense to have it here. It would be better to remove it and instead add a similar comment to the place where this is called.

@jan-cerny
Copy link
Collaborator Author

@vojtapolasek I have resolved the confusing comment by removing the comment from the macro code and instead adding comments to places where the regular expressions are defined.

@codeclimate
Copy link

codeclimate bot commented Jul 17, 2023

Code Climate has analyzed commit e7424a0 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 53.4% (0.0% change).

View more on Code Climate.

Copy link
Collaborator

@vojtapolasek vojtapolasek left a comment

Choose a reason for hiding this comment

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

Thank you for the fix, LGTM.

@vojtapolasek vojtapolasek merged commit 7cab0f8 into ComplianceAsCode:master Jul 18, 2023
29 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixes to reported bugs. OVAL OVAL update. Related to the systems assessments. Update Rule Issues or pull requests related to Rules updates.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants