apiVersion: compliance.openshift.io/v1alpha1
kind: ProfileBundle
name: <profile bundle name>
namespace: openshift-compliance
status:
dataStreamStatus: VALID (1)
OpenShift Container Platform 中的合规性操作符为您提供了多个自定义资源定义 (CRD) 来完成合规性扫描。为了运行合规性扫描,它利用预定义的安全策略,这些策略源自 ComplianceAsCode 社区项目。合规性操作符将这些安全策略转换为 CRD,您可以使用这些 CRD 来运行合规性扫描并获取对发现问题的补救措施。
默认情况下,合规性操作符 CRD 包括 `ProfileBundle` 和 `Profile` 对象,您可以在其中定义和设置合规性扫描要求的规则。您还可以使用 `TailoredProfile` 对象自定义默认配置文件。
安装合规性运算符时,它包含可立即运行的ProfileBundle
对象。合规性运算符会解析ProfileBundle
对象,并为捆绑包中的每个配置文件创建一个Profile
对象。它还会解析Rule
和Variable
对象,这些对象由Profile
对象使用。
ProfileBundle
对象示例apiVersion: compliance.openshift.io/v1alpha1
kind: ProfileBundle
name: <profile bundle name>
namespace: openshift-compliance
status:
dataStreamStatus: VALID (1)
1 | 指示合规性运算符是否能够解析内容文件。 |
当 |
当您从无效镜像回滚到已知的镜像时,ProfileBundle
对象将停止响应并显示PENDING
状态。作为解决方法,您可以切换到与之前的镜像不同的镜像。或者,您可以删除并重新创建ProfileBundle
对象以恢复工作状态。
Profile
对象定义了可以针对特定合规性标准评估的规则和变量。它包含有关 OpenSCAP 配置文件的解析详细信息,例如其 XCCDF 标识符和针对Node
或Platform
类型的配置文件检查。您可以直接使用Profile
对象,也可以使用TailorProfile
对象进一步自定义它。
您不能手动创建或修改 |
Profile
对象示例apiVersion: compliance.openshift.io/v1alpha1
description: <description of the profile>
id: xccdf_org.ssgproject.content_profile_moderate (1)
kind: Profile
metadata:
annotations:
compliance.openshift.io/product: <product name>
compliance.openshift.io/product-type: Node (2)
creationTimestamp: "YYYY-MM-DDTMM:HH:SSZ"
generation: 1
labels:
compliance.openshift.io/profile-bundle: <profile bundle name>
name: rhcos4-moderate
namespace: openshift-compliance
ownerReferences:
- apiVersion: compliance.openshift.io/v1alpha1
blockOwnerDeletion: true
controller: true
kind: ProfileBundle
name: <profile bundle name>
uid: <uid string>
resourceVersion: "<version number>"
selfLink: /apis/compliance.openshift.io/v1alpha1/namespaces/openshift-compliance/profiles/rhcos4-moderate
uid: <uid string>
rules: (3)
- rhcos4-account-disable-post-pw-expiration
- rhcos4-accounts-no-uid-except-zero
- rhcos4-audit-rules-dac-modification-chmod
- rhcos4-audit-rules-dac-modification-chown
title: <title of the profile>
1 | 指定配置文件的 XCCDF 名称。在将ComplianceScan 对象定义为扫描的 profile 属性的值时,使用此标识符。 |
2 | 指定Node 或Platform 。节点配置文件扫描集群节点,平台配置文件扫描 Kubernetes 平台。 |
3 | 指定配置文件的规则列表。每个规则对应于单个检查。 |
构成配置文件的Rule
对象也作为对象公开。使用Rule
对象定义您的合规性检查要求并指定如何修复它。
Rule
对象示例 apiVersion: compliance.openshift.io/v1alpha1
checkType: Platform (1)
description: <description of the rule>
id: xccdf_org.ssgproject.content_rule_configure_network_policies_namespaces (2)
instructions: <manual instructions for the scan>
kind: Rule
metadata:
annotations:
compliance.openshift.io/rule: configure-network-policies-namespaces
control.compliance.openshift.io/CIS-OCP: 5.3.2
control.compliance.openshift.io/NERC-CIP: CIP-003-3 R4;CIP-003-3 R4.2;CIP-003-3
R5;CIP-003-3 R6;CIP-004-3 R2.2.4;CIP-004-3 R3;CIP-007-3 R2;CIP-007-3 R2.1;CIP-007-3
R2.2;CIP-007-3 R2.3;CIP-007-3 R5.1;CIP-007-3 R6.1
control.compliance.openshift.io/NIST-800-53: AC-4;AC-4(21);CA-3(5);CM-6;CM-6(1);CM-7;CM-7(1);SC-7;SC-7(3);SC-7(5);SC-7(8);SC-7(12);SC-7(13);SC-7(18)
labels:
compliance.openshift.io/profile-bundle: ocp4
name: ocp4-configure-network-policies-namespaces
namespace: openshift-compliance
rationale: <description of why this rule is checked>
severity: high (3)
title: <summary of the rule>
1 | 指定此规则执行的检查类型。Node 配置文件扫描集群节点,Platform 配置文件扫描 Kubernetes 平台。空值表示没有自动检查。 |
2 | 指定规则的 XCCDF 名称,该名称直接从数据流中解析。 |
3 | 指定规则失败时的严重性。 |
|
使用TailoredProfile
对象根据您的组织要求修改默认Profile
对象。您可以启用或禁用规则,设置变量值,并为自定义提供理由。验证后,TailoredProfile
对象将创建一个ConfigMap
,ComplianceScan
对象可以引用该ConfigMap
。
您可以通过在 |
TailoredProfile
对象示例apiVersion: compliance.openshift.io/v1alpha1
kind: TailoredProfile
metadata:
name: rhcos4-with-usb
spec:
extends: rhcos4-moderate (1)
title: <title of the tailored profile>
disableRules:
- name: <name of a rule object to be disabled>
rationale: <description of why this rule is checked>
status:
id: xccdf_compliance.openshift.io_profile_rhcos4-with-usb (2)
outputRef:
name: rhcos4-with-usb-tp (3)
namespace: openshift-compliance
state: READY (4)
1 | 这是可选的。构建TailoredProfile 的Profile 对象的名称。如果未设置值,则将根据enableRules 列表创建一个新的配置文件。 |
2 | 指定定制配置文件的 XCCDF 名称。 |
3 | 指定ConfigMap 名称,该名称可用作ComplianceScan 的tailoringConfigMap.name 属性的值。 |
4 | 显示对象的狀態,例如READY 、PENDING 和FAILURE 。如果对象的狀態为ERROR ,则属性status.errorMessage 将提供失败的原因。 |
使用TailoredProfile
对象,可以使用TailoredProfile
结构创建一个新的Profile
对象。要创建新的Profile
,请设置以下配置参数
合适的标题
extends
值必须为空
TailoredProfile
对象上的扫描类型注释
compliance.openshift.io/product-type: Platform/Node
如果您未设置 |
定义合规性扫描的要求后,您可以通过指定扫描的类型、扫描的发生时间和扫描的位置来配置它。为此,合规性运算符为您提供了ScanSetting
对象。
使用ScanSetting
对象定义和重用运行扫描的操作策略。默认情况下,合规性运算符会创建以下ScanSetting
对象
default - 它每天凌晨 1 点在主节点和工作节点上运行扫描,使用 1Gi 持久卷 (PV) 并保留最后三个结果。补救措施既不自动应用也不自动更新。
default-auto-apply - 它每天凌晨 1 点在控制平面节点和工作节点上运行扫描,使用 1Gi 持久卷 (PV) 并保留最后三个结果。autoApplyRemediations
和autoUpdateRemediations
都设置为 true。
ScanSetting
对象示例apiVersion: compliance.openshift.io/v1alpha1
autoApplyRemediations: true (1)
autoUpdateRemediations: true (2)
kind: ScanSetting
maxRetryOnTimeout: 3
metadata:
creationTimestamp: "2022-10-18T20:21:00Z"
generation: 1
name: default-auto-apply
namespace: openshift-compliance
resourceVersion: "38840"
uid: 8cb0967d-05e0-4d7a-ac1c-08a7f7e89e84
rawResultStorage:
nodeSelector:
node-role.kubernetes.io/master: ""
pvAccessModes:
- ReadWriteOnce
rotation: 3 (3)
size: 1Gi (4)
tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/master
operator: Exists
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 300
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 300
- effect: NoSchedule
key: node.kubernetes.io/memory-pressure
operator: Exists
roles: (6)
- master
- worker
scanTolerations:
- operator: Exists
schedule: 0 1 * * * (5)
showNotApplicable: false
strictNodeScan: true
timeout: 30m
1 | 设置为true 以启用自动补救。设置为false 以禁用自动补救。 |
||
2 | 设置为true 以启用内容更新的自动补救。设置为false 以禁用内容更新的自动补救。 |
||
3 | 指定以原始结果格式存储的扫描数量。默认值为3 。随着较旧的结果被轮换,管理员必须在轮换发生之前将结果存储在其他地方。 |
||
4 | 指定应为扫描创建的存储大小,以存储原始结果。默认值为1Gi |
||
5 | 以 cron 格式指定应运行扫描的频率。
|
||
6 | 指定node-role.kubernetes.io 标签值以安排Node 类型的扫描。此值必须与MachineConfigPool 的名称匹配。 |
定义合规性扫描要求并配置运行扫描的设置后,合规性运算符将使用ScanSettingBinding
对象处理它。
使用ScanSettingBinding
对象指定您的合规性要求,并参考Profile
或TailoredProfile
对象。然后将其链接到ScanSetting
对象,该对象提供扫描的操作约束。然后,合规性运算符将根据ScanSetting
和ScanSettingBinding
对象生成ComplianceSuite
对象。
ScanSettingBinding
对象示例apiVersion: compliance.openshift.io/v1alpha1
kind: ScanSettingBinding
metadata:
name: <name of the scan>
profiles: (1)
# Node checks
- name: rhcos4-with-usb
kind: TailoredProfile
apiGroup: compliance.openshift.io/v1alpha1
# Cluster checks
- name: ocp4-moderate
kind: Profile
apiGroup: compliance.openshift.io/v1alpha1
settingsRef: (2)
name: my-companys-constraints
kind: ScanSetting
apiGroup: compliance.openshift.io/v1alpha1
1 | 指定要扫描环境的Profile 或TailoredProfile 对象的详细信息。 |
2 | 指定操作约束,例如计划和存储大小。 |
创建ScanSetting
和ScanSettingBinding
对象将生成合规性套件。要获取合规性套件列表,请运行以下命令
$ oc get compliancesuites
如果您删除 |
创建合规性套件后,您可以使用ComplianceSuite
对象监控已部署扫描的状态。
ComplianceSuite
对象可帮助您跟踪扫描的状态。它包含创建扫描的原始设置和整体结果。
对于Node
类型的扫描,您应该将其映射到MachineConfigPool
,因为它包含任何问题的修复方案。如果您指定标签,请确保它直接应用于池。
ComplianceSuite
对象示例apiVersion: compliance.openshift.io/v1alpha1
kind: ComplianceSuite
metadata:
name: <name of the scan>
spec:
autoApplyRemediations: false (1)
schedule: "0 1 * * *" (2)
scans: (3)
- name: workers-scan
scanType: Node
profile: xccdf_org.ssgproject.content_profile_moderate
content: ssg-rhcos4-ds.xml
contentImage: registry.redhat.io/compliance/openshift-compliance-content-rhel8@sha256:45dc...
rule: "xccdf_org.ssgproject.content_rule_no_netrc_files"
nodeSelector:
node-role.kubernetes.io/worker: ""
status:
Phase: DONE (4)
Result: NON-COMPLIANT (5)
scanStatuses:
- name: workers-scan
phase: DONE
result: NON-COMPLIANT
1 | 设置为true 以启用自动补救。设置为false 以禁用自动补救。 |
2 | 以 cron 格式指定应运行扫描的频率。 |
3 | 指定要在集群中运行的扫描规范列表。 |
4 | 指示扫描的进度。 |
5 | 指示套件的总体结果。 |
套件在后台根据scans
参数创建ComplianceScan
对象。您可以通过编程方式获取ComplianceSuites
事件。要获取套件的事件,请运行以下命令
$ oc get events --field-selector involvedObject.kind=ComplianceSuite,involvedObject.name=<name of the suite>
手动定义 |
Compliance Operator 包含供高级用户进行调试或与现有工具集成的选项。虽然建议您不要直接创建ComplianceScan
对象,但您可以使用ComplianceSuite
对象来管理它。
ComplianceScan
对象示例apiVersion: compliance.openshift.io/v1alpha1
kind: ComplianceScan
metadata:
name: <name of the scan>
spec:
scanType: Node (1)
profile: xccdf_org.ssgproject.content_profile_moderate (2)
content: ssg-ocp4-ds.xml
contentImage: registry.redhat.io/compliance/openshift-compliance-content-rhel8@sha256:45dc... (3)
rule: "xccdf_org.ssgproject.content_rule_no_netrc_files" (4)
nodeSelector: (5)
node-role.kubernetes.io/worker: ""
status:
phase: DONE (6)
result: NON-COMPLIANT (7)
1 | 指定Node 或Platform 。节点配置文件扫描集群节点,平台配置文件扫描Kubernetes平台。 |
||
2 | 指定要运行的配置文件的XCCDF标识符。 | ||
3 | 指定封装配置文件的容器镜像。 | ||
4 | 这是可选的。指定扫描以运行单个规则。此规则必须使用XCCDF ID标识,并且必须属于指定的配置文件。
|
||
5 | 如果您在OpenShift Container Platform上并希望生成修复方案,则nodeSelector标签必须与MachineConfigPool 标签匹配。
|
||
6 | 指示扫描的当前阶段。 | ||
7 | 指示扫描的结果。 |
如果您删除 |
扫描完成后,它会将结果生成ComplianceCheckResult
对象的自定义资源。但是,原始结果以ARF格式提供。这些结果存储在持久卷 (PV) 中,该卷具有与扫描名称关联的持久卷声明 (PVC)。您可以通过编程方式获取ComplianceScans
事件。要为套件生成事件,请运行以下命令
oc get events --field-selector involvedObject.kind=ComplianceScan,involvedObject.name=<name of the suite>
当合规性套件达到DONE
阶段时,您可以查看扫描结果和可能的修复方案。
当您使用特定配置文件运行扫描时,将验证配置文件中的多个规则。对于每个规则,都会创建一个ComplianceCheckResult
对象,该对象提供集群针对特定规则的状态。
ComplianceCheckResult
对象示例apiVersion: compliance.openshift.io/v1alpha1
kind: ComplianceCheckResult
metadata:
labels:
compliance.openshift.io/check-severity: medium
compliance.openshift.io/check-status: FAIL
compliance.openshift.io/suite: example-compliancesuite
compliance.openshift.io/scan-name: workers-scan
name: workers-scan-no-direct-root-logins
namespace: openshift-compliance
ownerReferences:
- apiVersion: compliance.openshift.io/v1alpha1
blockOwnerDeletion: true
controller: true
kind: ComplianceScan
name: workers-scan
description: <description of scan check>
instructions: <manual instructions for the scan>
id: xccdf_org.ssgproject.content_rule_no_direct_root_logins
severity: medium (1)
status: FAIL (2)
1 | 描述扫描检查的严重性。 |
2 | 描述检查的结果。可能的值为:
|
要获取套件中的所有检查结果,请运行以下命令
oc get compliancecheckresults \
-l compliance.openshift.io/suite=workers-compliancesuite
对于特定检查,您可以指定数据流修复。但是,如果存在Kubernetes修复,则Compliance Operator会创建一个ComplianceRemediation
对象。
ComplianceRemediation
对象示例apiVersion: compliance.openshift.io/v1alpha1
kind: ComplianceRemediation
metadata:
labels:
compliance.openshift.io/suite: example-compliancesuite
compliance.openshift.io/scan-name: workers-scan
machineconfiguration.openshift.io/role: worker
name: workers-scan-disable-users-coredumps
namespace: openshift-compliance
ownerReferences:
- apiVersion: compliance.openshift.io/v1alpha1
blockOwnerDeletion: true
controller: true
kind: ComplianceCheckResult
name: workers-scan-disable-users-coredumps
uid: <UID>
spec:
apply: false (1)
object:
current: (2)
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
spec:
config:
ignition:
version: 2.2.0
storage:
files:
- contents:
source: data:,%2A%20%20%20%20%20hard%20%20%20core%20%20%20%200
filesystem: root
mode: 420
path: /etc/security/limits.d/75-disable_users_coredumps.conf
outdated: {} (3)
1 | true 表示已应用修复方案。false 表示未应用修复方案。 |
2 | 包含修复方案的定义。 |
3 | 指示先前从早期版本的内容中解析的修复方案。Compliance Operator仍然保留过时的对象,以便管理员有机会在应用新修复方案之前对其进行审查。 |
要获取套件中的所有修复方案,请运行以下命令
oc get complianceremediations \
-l compliance.openshift.io/suite=workers-compliancesuite
要列出所有可以自动修复的失败检查,请运行以下命令
oc get compliancecheckresults \
-l 'compliance.openshift.io/check-status in (FAIL),compliance.openshift.io/automated-remediation'
要列出所有可以手动修复的失败检查,请运行以下命令
oc get compliancecheckresults \
-l 'compliance.openshift.io/check-status in (FAIL),!compliance.openshift.io/automated-remediation'