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

Ensure that components not in datastream are not mentioned by profiles #11811

Conversation

vojtapolasek
Copy link
Collaborator

Description:

  • see Reduce XCCDF #11800 for context
  • Add function which will ensure that rules / groups which are removed from the datastream are not mentioned in profile definitions

Rationale:

  • the mentioned PR removes unused rules / groups from the datastream, but those rules and groups are still selected (or unselected) by profiles. This breaks the SCAP standard and it produces invalid datastream.

  • Fixes Content is not SCAP valid #11810

Review Hints:

  • run the test according to the linked issue

@vojtapolasek vojtapolasek added bugfix Fixes to reported bugs. Infrastructure Our content build system labels Apr 11, 2024
@vojtapolasek vojtapolasek added this to the 0.1.73 milestone Apr 11, 2024
Copy link

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

Fedora Environment
Open in Gitpod

Oracle Linux 8 Environment
Open in Gitpod

@vojtapolasek vojtapolasek changed the title Fix the build so that the datastream is valid SCAP again Ensure that components not in datastream are not mentioned by profiles Apr 11, 2024
@jan-cerny jan-cerny self-assigned this Apr 11, 2024
Copy link

github-actions bot commented Apr 11, 2024

🤖 A k8s content image for this PR is available at:
ghcr.io/complianceascode/k8scontent:11811
This image was built from commit: f15097e

Click here to see how to deploy it

If you alread have Compliance Operator deployed:
utils/build_ds_container.py -i ghcr.io/complianceascode/k8scontent:11811

Otherwise deploy the content and operator together by checking out ComplianceAsCode/compliance-operator and:
CONTENT_IMAGE=ghcr.io/complianceascode/k8scontent:11811 make deploy-local

def remove_components_not_included(self, components_to_not_include):
rules_to_not_include = components_to_not_include.get("rules", set())
groups_to_not_include = components_to_not_include.get("groups", set())
self.selected = list(set(self.selected) - rules_to_not_include)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a small ask. Before this change the selects in the Profile element in the built XML were sorted nicely. Now they are random, probably due to usage of sets here. I admit we're not testing it and it isn't the case for all elements. But, having the items sorted and ordered deterministically helps us when manual reviewing 2 different data streams. So it would be nice if this is preserved. You can either re-sort it here in this method or you can find a better place, I'm guessing sorting the items in the _add_selects method could also work.

this function takes the data structure containing components which were for some reason excluded from the datastream.
The function ensures that data structures of the Profile class do not include those components (rules, groups).
@vojtapolasek vojtapolasek force-pushed the fix_building_profiles_with_excluded_rules_groups branch from b628302 to f15097e Compare April 12, 2024 06:56
@vojtapolasek
Copy link
Collaborator Author

@jan-cerny good catch, I implemented sorting.

Copy link

codeclimate bot commented Apr 12, 2024

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

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

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

View more on Code Climate.

Copy link
Collaborator

@jan-cerny jan-cerny left a comment

Choose a reason for hiding this comment

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

I have run SCAPVAL on RHEL 8 and RHEL 9 data streams and the validation passed and the issue is fixed. I have also seen thin data streams and they look fine.

@jan-cerny jan-cerny merged commit 093b315 into ComplianceAsCode:master Apr 12, 2024
44 of 45 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. Infrastructure Our content build system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Content is not SCAP valid
2 participants