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

Adds utilities for OSCAL Component Definitions from policies #11292

Merged
merged 16 commits into from
Jan 15, 2024

Conversation

jpower432
Copy link
Contributor

@jpower432 jpower432 commented Nov 20, 2023

Description:

This PR adds utilities under the utils directory to create OSCAL component definitions using the files under the controls directory to populate the implemented requirements and mapping to the rules.

What was added?
  • Core logic under utils/oscal
  • Unit tests under test/unit/utils/oscal
  • Documentation for the utilities

Rationale:

The policy was used to initially fill in the control responses because it contains all the required information for a component definition (status, description, rule mapping). However, the class ComponentDefinitionGenerator takes a ControlSelector class in order to allow how control response information is selected and constructed separate from the generation logic.

I tried to follow the guidance of one-step one commit to keep the options open for breaking this down into smaller PRs. However, all the changes would be needed to get an OSCAL component definition that would be compatible with compliance-trestle.

Review Hints:

This is PR is part two to #11286 so please see that PR to review the first two commits. Merged

Important Notes
  • To support installing compliance-trestle during CI job execution for testing, changes were made to the workflow files in the following commits:
    9fea72d
    5fa74a9

  • It performs a mapping from SSG status to OSCAL implementation status in the OscalStatus class

  • The script uses the "Section letter:" convention in the control notes to create statements under the implemented requirements.

  • The script maps parameter to rules uses the xccdf_variable field under template.vars

  • To determine what responses will mapped to the controls in the OSCAL profile the control id and label property from the resolved catalog is searched.

How to test

An example of how to execute the script:

$ ./build_product ocp4
$ ./utils/rule_dir_json.py
$ ./utils/oscal/build_cd_from_policy.py -o build/ocp4.json -p fedramp_rev4_high -pr ocp4 -c nist_ocp4:high

Example of how to verify compatibility with compliance-trestle

$ mkdir tmp-trestle-dir
$ cd tmp-trestle-dir && trestle init
$ trestle import -f https://raw.githubusercontent.com/GSA/fedramp-automation/master/dist/content/rev4/baselines/json/FedRAMP_rev4_HIGH-baseline_profile.json -o fedramp_rev4_high
$ trestle import -f ../content/build/ocp4.json -o ocp4
$ trestle author component-generate --name ocp4 -o markdown/components/ocp4
# Here you will notice that the implementation and rules are populated in the Markdown
$ cat markdown/components/ocp4/ocp4/fedramp_rev4_high/cm/cm-6.1.md

@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Used by openshift-ci bot. needs-ok-to-test Used by openshift-ci bot. labels Nov 20, 2023
Copy link

openshift-ci bot commented Nov 20, 2023

Hi @jpower432. 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.

Copy link

github-actions bot commented Nov 20, 2023

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

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

Fedora Testing Environment
Open in Gitpod

Oracle Linux 8 Environment
Open in Gitpod

@jpower432 jpower432 changed the title Add utilities for OSCAL Component Definitions from policies Adds utilities for OSCAL Component Definitions from policies Nov 20, 2023
@jpower432 jpower432 force-pushed the add_oscal_cd_generation branch 3 times, most recently from 5ebf9f7 to 9edbd80 Compare November 22, 2023 00:05
@vojtapolasek vojtapolasek added this to the 0.1.72 milestone Nov 29, 2023
@openshift-merge-robot openshift-merge-robot added the needs-rebase Used by openshift-ci bot. label Dec 8, 2023
@jpower432 jpower432 force-pushed the add_oscal_cd_generation branch from 9edbd80 to 4f1ba16 Compare December 11, 2023 14:25
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Used by openshift-ci bot. label Dec 11, 2023
This creates a single component definition and component for a product
and fills control responses based on the input policy.

Signed-off-by: Jennifer Power <[email protected]>
…figuration

Updates to gate.yml were made to support installing compliance-trestle and
CMakeLists.txt was updated to keep the oscal utilties unit tests from running
when the python version is lower than 3.8 and the required modules are not
installed.

Signed-off-by: Jennifer Power <[email protected]>
Based on status, the control notes are moved to remarks for status
justification.

Signed-off-by: Jennifer Power <[email protected]>
Some imports do not comply with mypy requirements.
This adds "skip" to follow-imports for utils/oscal to localize the testing to just
those scripts.

Signed-off-by: Jennifer Power <[email protected]>
The ControlSelector abstract class would allow the ComponentDefinitionGenerator
to be reused with various methods of deriving control response information.

Signed-off-by: Jennifer Power <[email protected]>
…ented requirement

The status is declared in the control policy at the control level, so updating
`handle_response` to always add the implementation status to the implemented requirement.

Signed-off-by: Jennifer Power <[email protected]>
@jpower432 jpower432 force-pushed the add_oscal_cd_generation branch from 4f1ba16 to 2e538d7 Compare December 11, 2023 20:21
@jpower432 jpower432 marked this pull request as ready for review December 11, 2023 21:44
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Used by openshift-ci bot. label Dec 11, 2023
@Mab879
Copy link
Member

Mab879 commented Dec 11, 2023

/packit build

@Mab879
Copy link
Member

Mab879 commented Dec 12, 2023

/packit build

@Mab879 Mab879 self-assigned this Jan 4, 2024
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 do have a few comments.

docs/manual/developer/05_tools_and_utilities.md Outdated Show resolved Hide resolved
docs/manual/developer/05_tools_and_utilities.md Outdated Show resolved Hide resolved
@jpower432 jpower432 requested a review from Mab879 January 9, 2024 20:06
utils/oscal/__init__.py Outdated Show resolved Hide resolved
utils/oscal/control_selector.py Outdated Show resolved Hide resolved
utils/oscal/params_extractor.py Outdated Show resolved Hide resolved
utils/oscal/rules_transformer.py Outdated Show resolved Hide resolved
utils/oscal/cd_generator.py Outdated Show resolved Hide resolved
@jpower432 jpower432 force-pushed the add_oscal_cd_generation branch from 2cb66ac to 4c8fa7d Compare January 10, 2024 17:06
Copy link

codeclimate bot commented Jan 10, 2024

Code Climate has analyzed commit 4c8fa7d and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 2

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 58.5% (0.0% change).

View more on Code Climate.

@jpower432 jpower432 requested a review from Mab879 January 15, 2024 15:30
@Mab879
Copy link
Member

Mab879 commented Jan 15, 2024

/packit rebuild-failed

@Mab879
Copy link
Member

Mab879 commented Jan 15, 2024

Waving Automatus tests as the test rules don't need tests.

@Mab879
Copy link
Member

Mab879 commented Jan 15, 2024

/packit retest-failed

@Mab879
Copy link
Member

Mab879 commented Jan 15, 2024

Thanks for your hard work on this PR!

@Mab879 Mab879 merged commit 30cb942 into ComplianceAsCode:master Jan 15, 2024
33 of 37 checks passed
@vojtapolasek vojtapolasek added the Highlight This PR/Issue should make it to the featured changelog. label Feb 9, 2024
@marcusburghardt marcusburghardt added the OSCAL PRs and Issues releated to OSCAL label Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Highlight This PR/Issue should make it to the featured changelog. needs-ok-to-test Used by openshift-ci bot. OSCAL PRs and Issues releated to OSCAL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Publish CaC content as an OSCAL Component Definition for NIST 800-53
5 participants