Skip to content

Conversation

alexhaydock
Copy link
Contributor

Description:

The current CIS profile for RHEL 8 is a monolithic single-profile combining the CIS rules. This does not address the fact that the CIS benchmark is published by CIS as 4 overlapping but separate sub-profiles:

  • Level 1 - Server
  • Level 1 - Workstation
  • Level 2 - Server
  • Level 2 - Workstation

This PR is an attempt to address this (for RHEL 8 initially, but I will expand this to RHEL 7 and 6 later). I intend to also do the same for CentOS and Rocky eventually.

Rationale:

This split uses the current profile format and simply splits it into 4 separate profiles which acknowledge the different rules which are enabled/disabled in each.

More information about this rationale can be found in my discussion thread #6924.

I considered an approach involving the more modular approach that the ANSSI profile is now taking, but since the CIS benchmarks are not cleanly "hierarchical" this doesn't work as cleanly here. At the very least we'd still need separate Server and Workstation profiles.

I know there might still be more work needed before this can be merged, and I'm also aware that there's a number of outstanding controls here which need rules adding. I can see that the upcoming RHEL 8.4 beta has rebased their CAC content to 0.1.54.

My (possibly ambitious) goal here is to land this change (or a similar one), and attempt to clean up any missing CIS rules in time for RHEL 8.5 to include a complete set of CIS profiles when it releases in late 2021/early 2022.

I would especially welcome any comments from @cipherboy or @vojtapolasek on this one, as I know they were involved in some of the discussions I had when planning for this. (No pressure though, I know big monolithic changes like this one can't be fun to review).

Thanks all 😄

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Used by openshift-ci bot. label May 7, 2021
@openscap-ci
Copy link
Collaborator

Can one of the admins verify this patch?

1 similar comment
@openscap-ci
Copy link
Collaborator

Can one of the admins verify this patch?

@openshift-ci-robot openshift-ci-robot added the needs-ok-to-test Used by openshift-ci bot. label May 7, 2021
@openshift-ci-robot
Copy link
Collaborator

Hi @alexhaydock. Thanks for your PR.

I'm waiting for a ComplianceAsCode member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@cipherboy
Copy link
Contributor

/ok-to-test

@openshift-ci-robot openshift-ci-robot added ok-to-test Used by openshift-ci bot. and removed needs-ok-to-test Used by openshift-ci bot. labels May 7, 2021
@openscap-ci
Copy link
Collaborator

openscap-ci commented May 7, 2021

Changes identified:
Profiles:
 cis_level1_server on rhel8
 cis_level1_workstation on rhel8
 cis_level2_workstation on rhel8

Show details

Profile cis_level1_server on rhel8:
 Newly added profile.
Profile cis_level1_workstation on rhel8:
 Newly added profile.
Profile cis_level2_workstation on rhel8:
 Newly added profile.

Recommended tests to execute:
 build_product rhel8
 tests/test_suite.py profile --libvirt qemu:///system test-suite-vm --datastream build/ssg-rhel8-ds.xml cis_level1_server
 tests/test_suite.py profile --libvirt qemu:///system test-suite-vm --datastream build/ssg-rhel8-ds.xml cis_level1_workstation
 tests/test_suite.py profile --libvirt qemu:///system test-suite-vm --datastream build/ssg-rhel8-ds.xml cis_level2_workstation

@alexhaydock
Copy link
Contributor Author

I'm getting some errors in the CI jobs related to this change like:

 The following tests FAILED:
	 69 - missing-references-ssg-rhel8-xccdf.xml (Failed)

and

The following tests FAILED:
	142 - missing-references-ssg-rhel8-xccdf.xml (Failed)

I've pushed a commit which updates the RHEL8 CMakeLists.txt file to hopefully address this but I might be missing some more changes that need making before the new profiles are referenced in all the right places.

@alexhaydock
Copy link
Contributor Author

/retest

@JAORMX
Copy link
Contributor

JAORMX commented May 8, 2021

@openscap-ci test this please

@alexhaydock
Copy link
Contributor Author

Pushed a new commit to fix the build issue the CI job was uncovering. I'd added a new HTML table type for CIS to the RHEL 8 CMakeLists.txt to be consistent with the other benchmarks with "sub-profiles" like ANSSI and NIST, but after looking at how these are defined in SSGCommon.cmake, I'm not sure we need a specific one for CIS, so instead I'm just using the regular ssg_build_html_table_by_ref once for each CIS sub-profile.

@alexhaydock
Copy link
Contributor Author

At this point I'm getting a bit stuck getting this PR in order. I'm not sure my last commit at 24872eb actually fixes things or whether it's a band-aid over the CI failure I was getting before.

I've tried to read the developer docs to get a better understanding of how the HTML tables are generated (which seems to be what's failing currently), but I'm struggling to see the process that's going on.

I also don't want to patch things up by just copying things 4 times for these CIS profiles, when there could be a single unified table schema referred to once.

If anyone's able to help point me in the right direction, that would be much appreciated. 😄

@alexhaydock
Copy link
Contributor Author

Something is going wrong with the table build process with the current commit.

An example is below, that gets built as tables/table-rhel8-cisrefs-level1_server.html

<html xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cdf="http://checklists.nist.gov/xccdf/1.1" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<br><br><div style="text-align: center; font-size: x-large; font-weight:bold"></div>
<br><br><style type="text/css">
		table
		{
			border-collapse:collapse;
		}
		table, th, td
		{
			border: 2px solid #dcdcdc;
			border-left: none;
			border-right: none;
			vertical-align: top;
			padding: 2px;
			font-family: verdana,arial,sans-serif;
			font-size:11px;
		}
		pre { 
			white-space: pre-wrap;
			white-space: -moz-pre-wrap !important;
			word-wrap:break-word; 
		}
		table tr:nth-child(2n+2) { background-color: #f4f4f4; }
		thead
		{
			display: table-header-group;
			font-weight: bold;
			background-color: #dedede;
		}
	</style>
<table><thead>
<td>CCE ID</td>
<td>Rule Title</td>
<td>Description</td>
<td>Rationale</td>
<td>Variable Setting</td>
<td>CIS v1.1.0  Mapping</td>
</thead></table>
</body>
</html>

Clearly something isn't being referenced right here in the table generation process. It's not being populated with the right content and the test is failing as a result.

@vojtapolasek vojtapolasek added this to the 0.1.57 milestone May 11, 2021
@vojtapolasek
Copy link
Collaborator

Hello, could you please look at this discussion?
#6996
I believe it can make our live easier. Especially definition of profiles.
Thank you very much for this contribution, it is great.

@alexhaydock
Copy link
Contributor Author

alexhaydock commented May 11, 2021

Hello, could you please look at this discussion?
#6996
I believe it can make our live easier. Especially definition of profiles.
Thank you very much for this contribution, it is great.

Thanks! 😄

I replied to that other thread. If my goal was to try and land this in RHEL 8.5 (maybe ambitious I know) do you think it would be more sensible to just go ahead and split into the 4 .profile files as I've done here and merge this until we can come to a decision on #6996? That feels like quite a fundamental design change for CaC so it might take a while to reach a conclusion I'm guessing?

Happy to wait if you think it's not going to be feasible either way, but just thought I'd ask.

Edit: I'm not suggesting merging this until the build issues are fixed of course. I know it's still not working perfectly yet due to the HTML table build issues. 😄

@vojtapolasek
Copy link
Collaborator

I suggest to wait for introduction of tags into the policy definition files.

@alexhaydock
Copy link
Contributor Author

I suggest to wait for introduction of tags into the policy definition files.

What would be the next steps to work towards this do you think? I think some of the discussion in #6996 is now focusing on aspects which might be more CIS-specific and might be more relevant upstream (which is great! but might not help us in the shorter-term).

@openshift-ci openshift-ci bot added the needs-rebase Used by openshift-ci bot. label Jun 1, 2021
@vojtapolasek
Copy link
Collaborator

@alexhaydock This PR introduces changes to the way in which policy levels are defined.
#7072
Do you plan to use it while splitting rhel8 profile?
I am going to use it while splitting the rhel7 profile.

@alexhaydock
Copy link
Contributor Author

@alexhaydock This PR introduces changes to the way in which policy levels are defined.
#7072
Do you plan to use it while splitting rhel8 profile?
I am going to use it while splitting the rhel7 profile.

@vojtapolasek That's my plan. I think overall this PR will need a complete rework, but I think we're in a much better situation now that #7072 has been merged. I'll try and put aside some time to work on this soon. In the meantime I've been trying to increase the coverage of some of the CIS rules that are missing.

@alexhaydock
Copy link
Contributor Author

I've brought this branch back in line with master as rebasing didn't really make sense with how different this is going to end up now that #7108 is merged. I'm still planning to fix this one but GitHub has auto-closed the PR for now. Stay tuned.

@alexhaydock alexhaydock reopened this Jun 29, 2021
@alexhaydock
Copy link
Contributor Author

There are legitimate failures in the gating test, but it's just some CCEs and references. @alexhaydock do you think that you could look into it? An automated CCE adder can be extracted from #7249, and adding references will be very easy for you.
Also would it make sense to rebase the PR as #7226 got merged?

Thanks @matejak

I think I've addressed the failures in the build now. I guess we will find out when the next run completes.

I did try the tool in #7249 and even after running source .pyenv.sh to set up the Python environment properly, I found that the script would run but didn't produce any output, and a git diff in the directory suggests it wasn't actually doing anything. I didn't really have time to debug though sadly.

This is what I was trying to run, inside the root dir of 8c8d6c7 and with the latest fix-rules.py from your branch:

~/fixrules/fix-rules.py -p products/rhel8/product.yml add-cce root_path_no_dot file_groupowner_efi_grub2_cfg file_owner_efi_grub2_cfg file_permissions_efi_grub2_cfg


references:
cis@rhel7: "5.7"
cis@rhel8: 5.7
Copy link
Member

Choose a reason for hiding this comment

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

I am sorry, but you have to quote the 5.7 for the time being, because otherwise it is interpreted as a number, which confuses the build system.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@matejak Ah that makes sense! I guess the references with multiple . delimiters are treated as strings automatically?

@matejak
Copy link
Member

matejak commented Aug 17, 2021

Nice! And one more thing - if you rebase against master (i.e. you run git rebase master), those two merge commits should simply fall out. You will then have to push --force-with-lease after the rebase, but it is worth to get rid of those merge commits - we try to keep those out of the history.

@pep8speaks
Copy link

Hello @alexhaydock! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 162:42: E741 ambiguous variable name 'l'
Line 162:100: E501 line too long (115 > 99 characters)
Line 163:21: E741 ambiguous variable name 'l'

@alexhaydock
Copy link
Contributor Author

@matejak ...I don't think those merge commands went quite as expected. Uh oh 😬 (or is that what you were expecting?)

@matejak
Copy link
Member

matejak commented Aug 17, 2021

No, I think that everything went fine. Those failed actions indicate that an OVAL may be broken, but it probably doesn't have anything to do with the rebase - I have checked the branch before and after, and it looks the same.

@alexhaydock
Copy link
Contributor Author

alexhaydock commented Aug 17, 2021

No, I think that everything went fine. Those failed actions indicate that an OVAL may be broken, but it probably doesn't have anything to do with the rebase - I have checked the branch before and after, and it looks the same.

I guess the GitHub UI just presents it in a confusing way then. It went from the "Files Changed" tab showing just my changed files to showing 149 changed files, mostly from commits other than mine. But if that's expected then no problem!

I'll have a look through the build output when they've all finished running and see whether I can track down the broken OVAL.

@cipherboy
Copy link
Contributor

cipherboy commented Aug 17, 2021

@matejak I agree with @alexhaydock, something looks funny here. Did you (Alex) perhaps do the rebase/merge the wrong direction, and pulled stuff from master into this branch, rather than rebasing your branch on top of master? Just a thought.

@matejak
Copy link
Member

matejak commented Aug 17, 2021

Alex probably rebased against an old master. File contents are fine (that's what I meant), but when I have tried to rebase, I got just over 50 commits, so yes, the PR is probably correct, but it is cluttered. So Alex please sync your master with upstream (i.e. this repository - git pull should do the trick, git log will give you a solid indication whether you were really successful with the update), and the rebase again. The number of commits and files changed should drop, and there should be no intervention required.

@alexhaydock
Copy link
Contributor Author

@matejak I agree with @alexhaydock, something looks funny here. Did you (Alex) perhaps do the rebase/merge the wrong direction, and pulled stuff from master into this branch, rather than rebasing your branch on top of master? Just a thought.

@cipherboy

Ah! I think you're absolutely right 🤦 I always manage to mess up merges somehow. Thank goodness for git reflog. I've undone what I did for now and I'll try again later with a proper rebase.

@openshift-ci
Copy link

openshift-ci bot commented Aug 17, 2021

@alexhaydock: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Rerun command
ci/prow/e2e-aws-ocp4-cis-node 9dae4cb link /test e2e-aws-ocp4-cis-node
ci/prow/e2e-aws-ocp4-moderate 9dae4cb link /test e2e-aws-ocp4-moderate
ci/prow/e2e-aws-ocp4-moderate-node 9dae4cb link /test e2e-aws-ocp4-moderate-node
ci/prow/e2e-aws-rhcos4-e8 379910b link /test e2e-aws-rhcos4-e8

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@matejak
Copy link
Member

matejak commented Aug 18, 2021

That's it, thank you very much for the effort!

Copy link
Member

@matejak matejak left a comment

Choose a reason for hiding this comment

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

The issue in the control file that Vojta discovered before has been fixed, and the PR has been cleanly rebased, so there is nothing else that stops it from merging.

@matejak
Copy link
Member

matejak commented Aug 18, 2021

/retest

@matejak matejak dismissed vojtapolasek’s stale review August 18, 2021 09:20

The outstanding item has been fixed, and Vojta is on PTO, unable to acknowledge that.

@matejak matejak merged commit f343e98 into ComplianceAsCode:master Aug 18, 2021
@alexhaydock
Copy link
Contributor Author

Thanks for the help and feedback everyone! Glad to finally get this one done and merged. 😄

@alexhaydock
Copy link
Contributor Author

Out of interest @matejak (completely understand if you can't say) but do you know whether it's likely that CAC 0.1.58 will make it into RHEL 8.5, or is it more likely to be the 0.1.57 release that's already out?

@matejak
Copy link
Member

matejak commented Aug 18, 2021

Out of interest @matejak (completely understand if you can't say) but do you know whether it's likely that CAC 0.1.58 will make it into RHEL 8.5, or is it more likely to be the 0.1.57 release that's already out?

Unfortunately we can't comment on our plans, but you can try to read between the lines, and see how it went when 8.5 is out :-)

@yuumasato yuumasato added the Highlight This PR/Issue should make it to the featured changelog. label Aug 23, 2021
@marcusburghardt marcusburghardt added RHEL8 Red Hat Enterprise Linux 8 product related. CIS CIS Benchmark related. labels Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CIS CIS Benchmark related. Highlight This PR/Issue should make it to the featured changelog. ok-to-test Used by openshift-ci bot. RHEL8 Red Hat Enterprise Linux 8 product related.
Projects
None yet
Development

Successfully merging this pull request may close these issues.