Skip to content

CMP-4655: Add oc compliance fetch-stig-results subcommand - #1378

Open
yuumasato wants to merge 17 commits into
ComplianceAsCode:masterfrom
yuumasato:oc-compliance-fetch-stig-results
Open

CMP-4655: Add oc compliance fetch-stig-results subcommand#1378
yuumasato wants to merge 17 commits into
ComplianceAsCode:masterfrom
yuumasato:oc-compliance-fetch-stig-results

Conversation

@yuumasato

Copy link
Copy Markdown
Member

Note

This PR builds on top of #1329 (the oc-compliance port). Because it is
stacked, the diff currently includes the port commits, so it should be
reviewed/merged after #1329. Once #1329 merges, this branch will be
rebased onto master and the diff will reduce to just the commits below.
CI failures originating in already-ported files (e.g. gofmt/go vet in
fetchraw/fetchfixes/controls/viewresult) belong to #1329, not to this
change.

What

Adds a new oc compliance fetch-stig-results subcommand that converts the
ComplianceCheckResults produced by a STIG ScanSettingBinding into XCCDF
results files importable by DISA STIG Viewer, rewriting each rule id to its
DISA SV-*_rule reference.

Why

Users running the DISA STIG profiles (ocp4-stig, rhcos4-stig) review and
attest results in DISA STIG Viewer. Until now there was no way to produce a file
STIG Viewer can ingest with the DISA rule ids — this bridges Compliance Operator
results into that workflow.

How

  • Reads the control.compliance.openshift.io/STIG-RULE annotation the operator
    sets on each result (the SV-*_rule id; ;-separated when a check maps to
    several).
  • Emits a standalone XCCDF <TestResult> matching oscap --stig-viewer output,
    which STIG Viewer imports natively.
  • Output modes: default = one combined file (named after the binding;
    importable against either the platform or node STIG since SV ids are globally
    unique); --per-scan = one file per scan; --scan <name> = a single scan.
  • Overlapping results collapse worst-status-wins
    (FAIL > ERROR > INCONSISTENT > MANUAL > INFO > no-result > PASS > NOT-APPLICABLE).
  • Read-only against the cluster: only Get (ScanSettingBinding) and List
    (ComplianceCheckResults); all writes are to the local output directory.

Testing

  • Unit tests for status aggregation and XCCDF rendering; e2e spec covering all
    three output modes.
  • Verified live against a cluster with a completed STIG scan; the generated file
    imports cleanly into DISA STIG Viewer.

Docs

  • cmd/oc-compliance/README.md (plugin overview) and
    doc/stig-viewer-results.md (workflow, aggregation precedence table, import
    steps, and the benign rule-revision mismatch note).

Image build

Also includes a plugin image build (images/oc-compliance/Dockerfile + Makefile
targets) so the plugin can be built and pushed to any registry:

make oc-compliance-push IMAGE_REPO=quay.io/<namespace> TAG=<tag>

@openshift-ci-robot

Copy link
Copy Markdown
Collaborator

@yuumasato: This pull request references CMP-4647 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the epic to target the "5.1.0" version, but no target version was set.

Details

In response to this:

[!NOTE]
This PR builds on top of #1329 (the oc-compliance port). Because it is
stacked, the diff currently includes the port commits, so it should be
reviewed/merged after #1329. Once #1329 merges, this branch will be
rebased onto master and the diff will reduce to just the commits below.
CI failures originating in already-ported files (e.g. gofmt/go vet in
fetchraw/fetchfixes/controls/viewresult) belong to #1329, not to this
change.

What

Adds a new oc compliance fetch-stig-results subcommand that converts the
ComplianceCheckResults produced by a STIG ScanSettingBinding into XCCDF
results files importable by DISA STIG Viewer, rewriting each rule id to its
DISA SV-*_rule reference.

Why

Users running the DISA STIG profiles (ocp4-stig, rhcos4-stig) review and
attest results in DISA STIG Viewer. Until now there was no way to produce a file
STIG Viewer can ingest with the DISA rule ids — this bridges Compliance Operator
results into that workflow.

How

  • Reads the control.compliance.openshift.io/STIG-RULE annotation the operator
    sets on each result (the SV-*_rule id; ;-separated when a check maps to
    several).
  • Emits a standalone XCCDF <TestResult> matching oscap --stig-viewer output,
    which STIG Viewer imports natively.
  • Output modes: default = one combined file (named after the binding;
    importable against either the platform or node STIG since SV ids are globally
    unique); --per-scan = one file per scan; --scan <name> = a single scan.
  • Overlapping results collapse worst-status-wins
    (FAIL > ERROR > INCONSISTENT > MANUAL > INFO > no-result > PASS > NOT-APPLICABLE).
  • Read-only against the cluster: only Get (ScanSettingBinding) and List
    (ComplianceCheckResults); all writes are to the local output directory.

Testing

  • Unit tests for status aggregation and XCCDF rendering; e2e spec covering all
    three output modes.
  • Verified live against a cluster with a completed STIG scan; the generated file
    imports cleanly into DISA STIG Viewer.

Docs

  • cmd/oc-compliance/README.md (plugin overview) and
    doc/stig-viewer-results.md (workflow, aggregation precedence table, import
    steps, and the benign rule-revision mismatch note).

Image build

Also includes a plugin image build (images/oc-compliance/Dockerfile + Makefile
targets) so the plugin can be built and pushed to any registry:

make oc-compliance-push IMAGE_REPO=quay.io/<namespace> TAG=<tag>

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
openshift-ci Bot requested review from jhrozek and rhmdnd September 1, 2026 12:45
@openshift-ci

openshift-ci Bot commented Sep 1, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: yuumasato

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved label Sep 1, 2026
rhmdnd and others added 13 commits September 1, 2026 15:02
Add k8s.io/cli-runtime, k8s.io/kubectl/pkg/cmd/cp,
and github.com/pkg/browser to support the oc-compliance
CLI tool being ported into this repository.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Port the shared utilities from oc-compliance into this
repository. This includes constants, Kubernetes client
abstractions, input validation, YAML serialization, and
profile/suite helpers that all subcommands depend on.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Port the main CLI entry point and the bind subcommand
from oc-compliance. The bind command creates
ScanSettingBinding objects for given Profiles or
TailoredProfiles, with optional dry-run output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Port the controls subcommand from oc-compliance. This
command reports which compliance controls a profile
fulfills by inspecting rule annotations, with output
rendered as a merged table grouped by benchmark.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Port the rerun-now subcommand from oc-compliance. This
command forces ComplianceScans to re-trigger by setting
the rescan annotation, supporting ComplianceScan,
ComplianceSuite, and ScanSettingBinding targets.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Port the fetch-fixes subcommand entry point, the shared
FixPersister, and the ExtraManifestBuilder framework
(default and ArgoCD) from oc-compliance. The object type
helpers follow in the next commit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Port the Rule, Profile, and ComplianceRemediation helpers
for the fetch-fixes subcommand. These handle fetching
available fixes from each object type and persisting
them as YAML files.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Port the fetch-raw subcommand entry point and the
ComplianceSuite and ScanSettingBinding helpers from
oc-compliance. The ComplianceScan helper that handles
PVC extraction follows in the next commit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Port the ComplianceScan helper that extracts raw ARF
results from PVCs by creating an extractor pod, using
kubectl cp to copy results, and optionally generating
HTML reports via oscap.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Port the view-result subcommand from oc-compliance. This
command displays detailed information about a
ComplianceCheckResult by traversing the owner chain to
find the relevant rule, profile, and remediation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Port the end-to-end tests from oc-compliance. These tests
cover all subcommands: bind, controls, fetch-fixes,
fetch-raw, rerun-now, and view-result. Updated deprecated
ioutil calls to use os package equivalents.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add Makefile targets for building, installing, and
running e2e tests for oc-compliance. The e2e target
builds the binary, installs it as an oc plugin, then
runs the tests — matching the original oc-compliance
repository's workflow.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
After rebasing the port onto master, re-pin go.mod to master's dependency
versions (k8s.io/* v0.35.7, cel-go v0.30.0, golang.org/x/crypto v0.54.0,
compliance-sdk v0.1.1, go 1.25.11) and re-run go mod tidy + go mod vendor so
the oc-compliance additions (k8s.io/cli-runtime, k8s.io/kubectl,
github.com/pkg/browser, tablewriter) resolve consistently at v0.35.7 instead
of the stale v0.35.5 the branch was originally cut against.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yuumasato
yuumasato force-pushed the oc-compliance-fetch-stig-results branch 2 times, most recently from d5ea92c to 6251904 Compare September 1, 2026 13:33
@yuumasato yuumasato added this to the 1.11.0 milestone Sep 1, 2026
yuumasato and others added 4 commits September 1, 2026 16:01
Generate DISA STIG Viewer XCCDF result files from the
ComplianceCheckResults produced by a ScanSettingBinding. Each rule id is
rewritten to its STIG reference (SV-*_rule) from the
control.compliance.openshift.io/STIG-RULE annotation. Where a single STIG
rule is covered by more than one check, the worst status wins.

The output matches the standalone <TestResult> format that OpenSCAP
writes with --stig-viewer, which DISA STIG Viewer imports natively.

By default every scan is collapsed into a single combined file (named
after the binding); because STIG rule ids are globally unique, that file
can be imported against either the platform or node STIG. --per-scan
emits one file per scan instead, and --scan restricts output to a single
named scan.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add a README for the oc-compliance plugin listing its subcommands, and a
topic doc walking through the fetch-stig-results workflow: generating
XCCDF results (combined, per-scan, single-scan), how overlapping results
are collapsed worst-status-wins, importing into DISA STIG Viewer, and the
benign rule-revision mismatch warning.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add a Dockerfile and Makefile targets to build a throwaway oc-compliance
plugin image from public bases, for testing the plugin.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
go vet rejects the non-constant format string in generateHTMLReports
(oscap output was passed as the format argument); use "%s". Also apply
the gofmt struct-field alignment corrected by `make update-coverage-line`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yuumasato
yuumasato force-pushed the oc-compliance-fetch-stig-results branch from 6251904 to 880b8e1 Compare September 1, 2026 14:06
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:1378-880b8e108dfdd20c7e92b3657858a64af8eec576

@yuumasato yuumasato changed the title CMP-4647: Add oc compliance fetch-stig-results subcommand CMP-4655: Add oc compliance fetch-stig-results subcommand Sep 1, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Collaborator

@yuumasato: This pull request references CMP-4655 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.1.0" version, but no target version was set.

Details

In response to this:

[!NOTE]
This PR builds on top of #1329 (the oc-compliance port). Because it is
stacked, the diff currently includes the port commits, so it should be
reviewed/merged after #1329. Once #1329 merges, this branch will be
rebased onto master and the diff will reduce to just the commits below.
CI failures originating in already-ported files (e.g. gofmt/go vet in
fetchraw/fetchfixes/controls/viewresult) belong to #1329, not to this
change.

What

Adds a new oc compliance fetch-stig-results subcommand that converts the
ComplianceCheckResults produced by a STIG ScanSettingBinding into XCCDF
results files importable by DISA STIG Viewer, rewriting each rule id to its
DISA SV-*_rule reference.

Why

Users running the DISA STIG profiles (ocp4-stig, rhcos4-stig) review and
attest results in DISA STIG Viewer. Until now there was no way to produce a file
STIG Viewer can ingest with the DISA rule ids — this bridges Compliance Operator
results into that workflow.

How

  • Reads the control.compliance.openshift.io/STIG-RULE annotation the operator
    sets on each result (the SV-*_rule id; ;-separated when a check maps to
    several).
  • Emits a standalone XCCDF <TestResult> matching oscap --stig-viewer output,
    which STIG Viewer imports natively.
  • Output modes: default = one combined file (named after the binding;
    importable against either the platform or node STIG since SV ids are globally
    unique); --per-scan = one file per scan; --scan <name> = a single scan.
  • Overlapping results collapse worst-status-wins
    (FAIL > ERROR > INCONSISTENT > MANUAL > INFO > no-result > PASS > NOT-APPLICABLE).
  • Read-only against the cluster: only Get (ScanSettingBinding) and List
    (ComplianceCheckResults); all writes are to the local output directory.

Testing

  • Unit tests for status aggregation and XCCDF rendering; e2e spec covering all
    three output modes.
  • Verified live against a cluster with a completed STIG scan; the generated file
    imports cleanly into DISA STIG Viewer.

Docs

  • cmd/oc-compliance/README.md (plugin overview) and
    doc/stig-viewer-results.md (workflow, aggregation precedence table, import
    steps, and the benign rule-revision mismatch note).

Image build

Also includes a plugin image build (images/oc-compliance/Dockerfile + Makefile
targets) so the plugin can be built and pushed to any registry:

make oc-compliance-push IMAGE_REPO=quay.io/<namespace> TAG=<tag>

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 openshift-eng/jira-lifecycle-plugin repository.

@yuumasato

Copy link
Copy Markdown
Member Author

/retest

@openshift-ci

openshift-ci Bot commented Sep 2, 2026

Copy link
Copy Markdown

PR needs rebase.

Details

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-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants