5.4. Compliance Operator 검사

Compliance Operator를 사용하여 규정 준수 검사를 실행하도록 ScanSettingScanSettingBinding API를 사용하는 것이 좋습니다. 이러한 API 오브젝트에 대한 자세한 내용을 보려면 다음을 실행합니다.

$ oc explain scansettings

또는

$ oc explain scansettingbindings

5.4.1. 규정 준수 검사 실행

CIS(Center for Internet Security) 프로필을 사용하여 검사를 실행할 수 있습니다. 편의를 위해 Compliance Operator는 시작 시 적절한 기본값을 사용하여 ScanSetting 오브젝트를 생성합니다. 이 ScanSetting 오브젝트의 이름은 default 입니다.

참고

올인원 컨트롤 플레인 및 작업자 노드의 경우 규정 준수 스캔은 작업자 및 컨트롤 플레인 노드에서 두 번 실행됩니다. 규정 준수 검사에서 일관되지 않은 검사 결과를 생성할 수 있습니다. ScanSetting 오브젝트에서 단일 역할만 정의하여 일관성 없는 결과를 방지할 수 있습니다.

절차

  1. 다음을 실행하여 ScanSetting 오브젝트를 검사합니다.

    $ oc describe scansettings default -n openshift-compliance

    출력 예

    apiVersion: compliance.openshift.io/v1alpha1
    kind: ScanSetting
    metadata:
      name: default
      namespace: openshift-compliance
    rawResultStorage:
      pvAccessModes:
      - ReadWriteOnce 1
      rotation: 3 2
      size: 1Gi 3
    roles:
    - worker 4
    - master 5
    scanTolerations: 6
      default:
      - operator: Exists
      schedule: 0 1 * * * 7

    1
    Compliance Operator는 검사 결과가 포함된 PV(영구 볼륨)를 생성합니다. 기본적으로 PV는 Compliance Operator에서 클러스터에 구성된 스토리지 클래스에 대한 가정을 할 수 없기 때문에 액세스 모드 ReadWriteOnce를 사용합니다. 대부분의 클러스터에서 ReadWriteOnce 액세스 모드를 사용할 수 있습니다. 검사 결과를 가져오려면 볼륨을 바인딩하는 도우미 Pod를 사용하여 이를 수행할 수 있습니다. ReadWriteOnce 액세스 모드를 사용하는 볼륨은 한 번에 하나의 Pod에서만 마운트할 수 있으므로 도우미 Pod를 삭제해야 합니다. 그러지 않으면 Compliance Operator가 후속 검사에 볼륨을 재사용할 수 없습니다.
    2
    Compliance Operator는 세 번의 후속 검사 결과를 볼륨에 보관합니다. 이전 검사는 순환됩니다.
    3
    Compliance Operator는 검사 결과에 대해 1GB의 스토리지를 할당합니다.
    4 5
    검사 설정에서 클러스터 노드를 검사하는 프로필을 사용하는 경우 이러한 노드 역할을 검사합니다.
    6
    기본 검사 설정 오브젝트도 모든 노드를 검사합니다.
    7
    기본 검사 설정 오브젝트는 매일 01:00에 검사를 실행합니다.

    기본 검사 설정 대신 다음과 같은 설정이 있는 default-auto-apply를 사용할 수 있습니다.

    apiVersion: compliance.openshift.io/v1alpha1
    kind: ScanSetting
    metadata:
      name: default-auto-apply
      namespace: openshift-compliance
    autoUpdateRemediations: true 1
    autoApplyRemediations: true 2
    rawResultStorage:
      pvAccessModes:
        - ReadWriteOnce
      rotation: 3
      size: 1Gi
    schedule: 0 1 * * *
    roles:
      - worker
      - master
    scanTolerations:
      default:
      - operator: Exists
    1 2
    autoUpdateRemediationsautoApplyRemediations 플래그를 true로 설정하면 추가 단계 없이 자동으로 조정되는 ScanSetting 오브젝트를 쉽게 생성할 수 있습니다.
  2. 기본 ScanSetting 오브젝트에 바인딩하는 ScanSettingBinding 오브젝트를 생성하고 ciscis-node 프로파일을 사용하여 클러스터를 검사합니다. 예를 들면 다음과 같습니다.

    apiVersion: compliance.openshift.io/v1alpha1
    kind: ScanSettingBinding
    metadata:
      name: cis-compliance
      namespace: openshift-compliance
    profiles:
      - name: ocp4-cis-node
        kind: Profile
        apiGroup: compliance.openshift.io/v1alpha1
      - name: ocp4-cis
        kind: Profile
        apiGroup: compliance.openshift.io/v1alpha1
    settingsRef:
      name: default
      kind: ScanSetting
      apiGroup: compliance.openshift.io/v1alpha1
  3. 다음을 실행하여 ScanSettingBinding 오브젝트를 생성합니다.

    $ oc create -f <file-name>.yaml -n openshift-compliance

    프로세스의 이 시점에서 ScanSettingBinding 오브젝트는 BindingBound 설정을 기반으로 조정됩니다. Compliance Operator는 ComplianceSuite 오브젝트 및 관련 ComplianceScan 오브젝트를 생성합니다.

  4. 다음을 실행하여 컴플라이언스 검사 진행 상황을 따르십시오.

    $ oc get compliancescan -w -n openshift-compliance

    검사는 스캔 단계를 통해 진행되며 완료되면 DONE 단계에 도달합니다. 대부분의 경우 검사 결과는 NON-COMPLIANT입니다. 검사 결과를 검토하고 업데이트 적용 작업을 시작하여 클러스터를 준수하도록 할 수 있습니다. 자세한 내용은 Compliance Operator 업데이트 적용 관리를 참조하십시오.

5.4.2. 작업자 노드에 결과 서버 Pod 예약

결과 서버 포드는 원시 자산 보고 형식(ARF)을 저장하는 PV(영구 볼륨)를 마운트합니다. nodeSelectortolerations 특성을 사용하면 결과 서버 포드의 위치를 구성할 수 있습니다.

이는 컨트롤 플레인 노드가 영구 볼륨을 마운트할 수 없는 환경에 유용합니다.

프로세스

  • Compliance Operator의 ScanSetting CR(사용자 정의 리소스)을 생성합니다.

    1. ScanSetting CR을 정의하고 YAML 파일을 저장합니다(예: rs-workers.yaml ):

      apiVersion: compliance.openshift.io/v1alpha1
      kind: ScanSetting
      metadata:
        name: rs-on-workers
        namespace: openshift-compliance
      rawResultStorage:
        nodeSelector:
          node-role.kubernetes.io/worker: "" 1
        pvAccessModes:
        - ReadWriteOnce
        rotation: 3
        size: 1Gi
        tolerations:
        - operator: Exists 2
      roles:
      - worker
      - master
      scanTolerations:
        - operator: Exists
      schedule: 0 1 * * *
      1
      Compliance Operator는 이 노드를 사용하여 검사 결과를 ARF 형식으로 저장합니다.
      2
      결과 서버 Pod는 모든 테인트를 허용합니다.
    2. ScanSetting CR을 생성하려면 다음 명령을 실행합니다.

      $ oc create -f rs-workers.yaml

검증

  • ScanSetting 오브젝트가 생성되었는지 확인하려면 다음 명령을 실행합니다.

    $ oc get scansettings rs-on-workers -n openshift-compliance -o yaml

    출력 예

    apiVersion: compliance.openshift.io/v1alpha1
    kind: ScanSetting
    metadata:
      creationTimestamp: "2021-11-19T19:36:36Z"
      generation: 1
      name: rs-on-workers
      namespace: openshift-compliance
      resourceVersion: "48305"
      uid: 43fdfc5f-15a7-445a-8bbc-0e4a160cd46e
    rawResultStorage:
      nodeSelector:
        node-role.kubernetes.io/worker: ""
      pvAccessModes:
      - ReadWriteOnce
      rotation: 3
      size: 1Gi
      tolerations:
      - operator: Exists
    roles:
    - worker
    - master
    scanTolerations:
    - operator: Exists
    schedule: 0 1 * * *
    strictNodeScan: true