Using the oc-compliance plugin¶
Although the Compliance Operator automates many of the checks and remediations for the cluster, an administrator can use the oc-compliance plugin to perform the full process of bringing a cluster into compliance by interacting with the Compliance Operator API and other components.
Install the oc-compliance plugin¶
You can install the oc-compliance plugin to simplify compliance operations from the command line.
Procedure
-
Extract the
oc-complianceimage to get theoc-compliancebinary:$ podman run --rm -v ~/.local/bin:/mnt/out:Z registry.redhat.io/compliance/oc-compliance-rhel8:stable /bin/cp /usr/bin/oc-compliance /mnt/out/Example outputW0611 20:35:46.486903 11354 manifest.go:440] Chose linux/amd64 manifest from the manifest list.You can now run
oc-compliance.
Fetch raw results¶
An administrator or auditor can review the complete detailed results of a scan as created by the OpenSCAP tool. These results contain more details than what is contained in the ComplianceCheckResult custom resource (CR).
When a compliance scan finishes, the results of the individual checks are listed in the resulting ComplianceCheckResult custom resource (CR). However, an administrator or auditor might require the complete details of the scan. The OpenSCAP tool creates an Advanced Recording Format (ARF) formatted file with the detailed results. This ARF file is too large to store in a config map or other standard Kubernetes resource, so a persistent volume (PV) is created to contain it.
Procedure
-
Fetch the results from the PV by running the following command:
where:
-
<object-type>can be eitherscansettingbinding,compliancescanorcompliancesuite, depending on which of these objects the scans were launched with. -
<object-name>is the name of the binding, suite, or scan object to gather the ARF file for, and<output-path>is the local directory to place the results.For example:
Example outputFetching results for my-binding scans: ocp4-cis, ocp4-cis-node-worker, ocp4-cis-node-master Fetching raw compliance results for scan 'ocp4-cis'....... The raw compliance results are available in the following directory: /tmp/ocp4-cis Fetching raw compliance results for scan 'ocp4-cis-node-worker'........... The raw compliance results are available in the following directory: /tmp/ocp4-cis-node-worker Fetching raw compliance results for scan 'ocp4-cis-node-master'...... The raw compliance results are available in the following directory: /tmp/ocp4-cis-node-master
-
-
View the list of files in the directory:
-
Extract the results:
-
View the extracted results:
Re-running scans¶
Although it is possible to run scans as scheduled jobs, you must often re-run a scan on demand, particularly after remediations are applied or when other changes to the cluster are made.
Rerunning a scan with the Compliance Operator requires the use of an annotation on the scan object. However, with the oc-compliance plugin you can rerun a scan with a single command.
Procedure
-
Rerun the scans for the
ScanSettingBindingobject namedmy-bindingby running the following command:
Use ScanSettingBinding custom resources¶
When using the ScanSetting and ScanSettingBinding custom resources (CRs) that the Compliance Operator provides, it is possible to run scans for multiple profiles while using a common set of scan options, such as schedule, machine roles, tolerations, and so on.
Although that is easier than working with multiple ComplianceSuite or ComplianceScan objects, it can confuse new users.
The oc compliance bind subcommand helps you create a ScanSettingBinding CR.
Procedure
-
Run:
$ oc compliance bind [--dry-run] -N <binding name> [-S <scansetting name>] <objtype/objname> [..<objtype/objname>]-
If you omit the
-Sflag, thedefaultscan setting provided by the Compliance Operator is used. -
The object type is the Kubernetes object type, which can be
profileortailoredprofile. More than one object can be provided. -
The object name is the name of the Kubernetes resource, such as
.metadata.name. -
Add the
--dry-runoption to display the YAML file of the objects that are created.For example, given the following profiles and scan settings:
Example outputNAME AGE VERSION ocp4-cis 3h49m 1.9.0 ocp4-cis-1-9 3h49m 1.9.0 ocp4-cis-node 3h49m 1.9.0 ocp4-cis-node-1-9 3h49m 1.9.0 ocp4-e8 3h49m ocp4-high 3h49m Revision 4 ocp4-high-node 3h49m Revision 4 ocp4-high-node-rev-4 3h49m Revision 4 ocp4-high-rev-4 3h49m Revision 4 ocp4-moderate 3h49m Revision 4 ocp4-moderate-node 3h49m Revision 4 ocp4-moderate-node-rev-4 3h49m Revision 4 ocp4-moderate-rev-4 3h49m Revision 4 ocp4-nerc-cip 3h49m ocp4-nerc-cip-node 3h49m ocp4-pci-dss 3h49m 4.0.0 ocp4-pci-dss-3-2 3h49m 3.2.1 ocp4-pci-dss-4-0 3h49m 4.0.0 ocp4-pci-dss-node 3h49m 4.0.0 ocp4-pci-dss-node-3-2 3h49m 3.2.1 ocp4-pci-dss-node-4-0 3h49m 4.0.0 ocp4-stig 3h49m V2R3 ocp4-stig-node 3h49m V2R3 ocp4-stig-node-v2r3 3h49m V2R3 ocp4-stig-v2r3 3h49m V2R3 rhcos4-e8 3h49m rhcos4-high 3h49m Revision 4 rhcos4-high-rev-4 3h49m Revision 4 rhcos4-moderate 3h49m Revision 4 rhcos4-moderate-rev-4 3h49m Revision 4 rhcos4-nerc-cip 3h49m rhcos4-stig 3h49m V2R3 rhcos4-stig-v2r3 3h49m V2R3
-
-
To apply the
defaultsettings to theocp4-cisandocp4-cis-nodeprofiles, run:After the
ScanSettingBindingCR is created, the bound profile begins scanning for both profiles with the related settings. Overall, this is the fastest way to begin scanning with the Compliance Operator.
Print controls¶
You can view a report of the compliance standards and controls that a given profile satisfies.
Compliance standards are generally organized into a the following hierarchy:
- A benchmark is the top-level definition of a set of controls for a particular standard. For example, FedRAMP Moderate or Center for Internet Security (CIS) v.1.6.0.
- A control describes a family of requirements that must be met to be in compliance with the benchmark. For example, FedRAMP AC-01 (access control policy and procedures).
- A rule is a single check that is specific for the system being brought into compliance, and one or more of these rules map to a control.
- The Compliance Operator handles the grouping of rules into a profile for a single benchmark. It can be difficult to determine which controls that the set of rules in a profile satisfy.
Procedure
-
The
oc compliancecontrolssubcommand provides a report of the standards and controls that a given profile satisfies:
Fetch compliance remediation details¶
The Compliance Operator provides remediation objects that are used to automate the changes required to make the cluster compliant. You can use the fetch-fixes subcommand to help you understand exactly which configuration remediations are used.
The fetch-fixes extracts the remediation objects from a profile, rule, or ComplianceRemediation object into a directory for you to inspect.
Warning
Use caution before applying remediations directly. Some remediations might not be applicable in bulk, such as the usbguard rules in the moderate profile. In these cases, allow the Compliance Operator to apply the rules because it addresses the dependencies and ensures that the cluster remains in a good state.
Procedure
-
View the remediations for a profile:
Example outputNo fixes to persist for rule 'ocp4-api-server-api-priority-flowschema-catch-all' No fixes to persist for rule 'ocp4-api-server-api-priority-gate-enabled' No fixes to persist for rule 'ocp4-api-server-audit-log-maxbackup' Persisted rule fix to /tmp/ocp4-api-server-audit-log-maxsize.yaml No fixes to persist for rule 'ocp4-api-server-audit-log-path' No fixes to persist for rule 'ocp4-api-server-auth-mode-no-aa' No fixes to persist for rule 'ocp4-api-server-auth-mode-node' No fixes to persist for rule 'ocp4-api-server-auth-mode-rbac' No fixes to persist for rule 'ocp4-api-server-basic-auth' No fixes to persist for rule 'ocp4-api-server-bind-address' No fixes to persist for rule 'ocp4-api-server-client-ca' Persisted rule fix to /tmp/ocp4-api-server-encryption-provider-cipher.yaml Persisted rule fix to /tmp/ocp4-api-server-encryption-provider-config.yamlNote
The
No fixes to persistwarning is expected whenever there are rules in a profile that do not have a corresponding remediation, because either the rule cannot be remediated automatically or a remediation was not provided. -
You can view a sample of the YAML file. The
headcommand will show you the first 10 lines: -
View the remediation from a
ComplianceRemediationobject created after a scan:Example outputNAME STATE ocp4-cis-api-server-encryption-provider-cipher NotApplied ocp4-cis-api-server-encryption-provider-config NotApplied -
You can view a sample of the YAML file. The
headcommand will show you the first 10 lines:
View ComplianceCheckResult object details¶
When scans are finished running, ComplianceCheckResult objects are created for the individual scan rules. You can use the view-result subcommand to provide a human-readable output of the ComplianceCheckResult object details.
Procedure
-
Run:
Additional resources