7.7. 고급 보안 프로필 Operator 작업

고급 작업을 사용하여 지표를 활성화하거나, Webhook를 구성하거나, syscall을 제한합니다.

7.7.1. seccomp 프로필에서 허용되는 syscalls 제한

Security Profiles Operator는 기본적으로 seccomp 프로필 의 syscall 을 제한하지 않습니다. spod 구성에서 허용되는 syscall 목록을 정의할 수 있습니다.

프로세스

  • allowedSyscalls 목록을 정의하려면 다음 명령을 실행하여 spec 매개변수를 조정합니다.

    $ oc -n openshift-security-profiles patch spod spod --type merge \
        -p '{"spec":{"allowedSyscalls": ["exit", "exit_group", "futex", "nanosleep"]}}'
중요

Operator는 allowed 목록에 정의된 syscall의 하위 집합이 있는 seccomp 프로필만 설치합니다. 이 규칙을 따르지 않는 모든 프로필은 거부됩니다.

spod 구성에서 허용된 syscall 목록이 수정되면 Operator는 비준수인 이미 설치된 프로필을 식별하고 이를 자동으로 제거합니다.

7.7.2. 컨테이너 런타임의 기본 syscall

baseProfileName 특성을 사용하여 지정된 런타임에서 컨테이너를 시작하는 데 필요한 최소 syscall 을 설정할 수 있습니다.

프로세스

  • SeccompProfile kind 오브젝트를 편집하고 spec 필드에 baseProfileName: runc-v1.0.0 을 추가합니다.

    apiVersion: security-profiles-operator.x-k8s.io/v1beta1
    kind: SeccompProfile
    metadata:
      namespace: my-namespace
      name: example-name
    spec:
      defaultAction: SCMP_ACT_ERRNO
      baseProfileName: runc-v1.0.0
      syscalls:
        - action: SCMP_ACT_ALLOW
          names:
            - exit_group

7.7.3. spod 데몬에서 메모리 최적화 활성화

spod 데몬 프로세스 내에서 실행되는 컨트롤러는 프로필 레코딩이 활성화된 경우 클러스터에서 사용 가능한 모든 Pod를 감시합니다. 이로 인해 대규모 클러스터에서 메모리 사용량이 매우 높아지므로 spod 데몬이 메모리 부족 또는 충돌로 이어질 수 있습니다.

충돌이 발생하지 않도록 spod 데몬은 프로필 레코딩용으로 지정된 Pod만 캐시 메모리에 로드하도록 구성할 수 있습니다.

+

참고

SPO 메모리 최적화는 기본적으로 활성화되어 있지 않습니다.

프로세스

  1. 다음 명령을 실행하여 메모리 최적화를 활성화합니다.

    $ oc -n openshift-security-profiles patch spod spod --type=merge -p '{"spec":{"enableMemoryOptimization":true}}'
  2. Pod의 보안 프로필을 기록하려면 Pod에 spo.x-k8s.io/enable-recording: "true" 로 레이블이 지정되어야 합니다.

    apiVersion: v1
    kind: Pod
    metadata:
      name: my-recording-pod
      labels:
        spo.x-k8s.io/enable-recording: "true"

7.7.4. 데몬 리소스 요구 사항 사용자 정의

데몬 컨테이너의 기본 리소스 요구 사항은 spod 구성의 daemonResourceRequirements 필드를 사용하여 조정할 수 있습니다.

프로세스

  • 데몬 컨테이너의 메모리 및 cpu 요청 및 제한을 지정하려면 다음 명령을 실행합니다.

    $ oc -n openshift-security-profiles patch spod spod --type merge -p \
        '{"spec":{"daemonResourceRequirements": { \
        "requests": {"memory": "256Mi", "cpu": "250m"}, \
        "limits": {"memory": "512Mi", "cpu": "500m"}}}}'

7.7.5. spod 데몬 Pod의 사용자 정의 우선순위 클래스 이름 설정

spod 데몬 Pod의 기본 우선순위 클래스 이름은 system-node-critical 로 설정됩니다. priorityClassName 필드에서 값을 설정하여 spod 구성에서 사용자 정의 우선순위 클래스 이름을 구성할 수 있습니다.

프로세스

  • 다음 명령을 실행하여 우선순위 클래스 이름을 구성합니다.

    $ oc -n openshift-security-profiles patch spod spod --type=merge -p '{"spec":{"priorityClassName":"my-priority-class"}}'

    출력 예

    securityprofilesoperatordaemon.openshift-security-profiles.x-k8s.io/spod patched

7.7.6. 메트릭 사용

openshift-security-profiles 네임스페이스는 kube-rbac-proxy 컨테이너에서 보호하는 메트릭 끝점을 제공합니다. 모든 메트릭은 openshift-security-profiles 네임스페이스 내의 메트릭 서비스에 의해 노출됩니다.

Security Profiles Operator에는 클러스터 역할과 해당 바인딩 spo-metrics-client 가 포함되어 있어 클러스터 내에서 메트릭을 검색할 수 있습니다. 사용 가능한 메트릭 경로는 다음 두 가지입니다.

  • metrics.openshift-security-profiles/metrics: 컨트롤러 런타임 메트릭의 경우
  • metrics.openshift-security-profiles/metrics-spod: Operator 데몬 지표의 경우

프로세스

  1. 지표 서비스의 상태를 보려면 다음 명령을 실행합니다.

    $ oc get svc/metrics -n openshift-security-profiles

    출력 예

    NAME      TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
    metrics   ClusterIP   10.0.0.228   <none>        443/TCP   43s

  2. 메트릭을 검색하려면 다음 명령을 실행하여 openshift-security-profiles 네임스페이스에서 기본 ServiceAccount 토큰을 사용하여 서비스 끝점을 쿼리합니다.

    $ oc run --rm -i --restart=Never --image=registry.fedoraproject.org/fedora-minimal:latest \
        -n openshift-security-profiles metrics-test -- bash -c \
        'curl -ks -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" https://metrics.openshift-security-profiles/metrics-spod'

    출력 예

    # HELP security_profiles_operator_seccomp_profile_total Counter about seccomp profile operations.
    # TYPE security_profiles_operator_seccomp_profile_total counter
    security_profiles_operator_seccomp_profile_total{operation="delete"} 1
    security_profiles_operator_seccomp_profile_total{operation="update"} 2

  3. 다른 네임스페이스에서 메트릭을 검색하려면 다음 명령을 실행하여 ServiceAccountspo-metrics-client ClusterRoleBinding 에 연결합니다.

    $ oc get clusterrolebinding spo-metrics-client -o wide

    출력 예

    NAME                 ROLE                             AGE   USERS   GROUPS   SERVICEACCOUNTS
    spo-metrics-client   ClusterRole/spo-metrics-client   35m                    openshift-security-profiles/default

7.7.6.1. controller-runtime 메트릭

controller-runtime 지표 및 DaemonSet 끝점 metrics-spod 는 기본 메트릭 세트를 제공합니다. 데몬에서 추가 메트릭을 제공합니다. 이 메트릭은 항상 security_profiles_operator_ 접두사가 붙습니다.

표 7.1. 사용 가능한 controller-runtime 메트릭

메트릭 키가능한 라벨유형목적

seccomp_profile_total

operation={delete,update}

카운터

seccomp 프로필 작업의 양입니다.

seccomp_profile_audit_total

노드,namespace,pod,container,executable,syscall

카운터

seccomp 프로필 감사 작업의 양입니다. 로그를 보강해야 합니다.

seccomp_profile_bpf_total

노드,mount_namespace,profile

카운터

seccomp 프로필 bpf 작업 수입니다. bpf recorder를 활성화해야 합니다.

seccomp_profile_error_total

reason={
SeccompNotSupportedOnNode,
InvalidSeccompProfile,
CannotSaveSeccompProfile,
CannotRemoveSeccompProfile,
CannotUpdateSeccompProfile,
CannotUpdateNodeStatusECDHE}

카운터

seccomp 프로필 오류의 수입니다.

selinux_profile_total

operation={delete,update}

카운터

SELinux 프로파일 작업의 양입니다.

selinux_profile_audit_total

노드,네임 스페이스,Pod,컨테이너,실행 가능한,scontext,tcontext

카운터

SELinux 프로파일 감사 작업의 양입니다. 로그를 보강해야 합니다.

selinux_profile_error_total

reason={
CannotSaveSelinuxPolicy,
CannotUpdatePolicyStatus,
CannotRemoveSelinuxPolicy,
CannotContactSelinuxd,
CannotWritePolicyFile,
CannotGetPolicyStatusECDHE}

카운터

SELinux 프로필 오류의 양입니다.

7.7.7. 로그 강화기 사용

Security Profiles Operator에는 로그 강화 기능이 포함되어 있으며 기본적으로 비활성화되어 있습니다. 로그 보강 컨테이너는 로컬 노드에서 감사 로그를 읽을 수 있는 권한 있는 권한으로 실행됩니다. 로그 강화기는 호스트 PID 네임스페이스 hostPID 내에서 실행됩니다.

중요

로그 보강기에는 호스트 프로세스를 읽을 수 있는 권한이 있어야 합니다.

프로세스

  1. 다음 명령을 실행하여 spod 구성을 패치하여 로그 보강기를 활성화합니다.

    $ oc -n openshift-security-profiles patch spod spod \
        --type=merge -p '{"spec":{"enableLogEnricher":true}}'

    출력 예

    securityprofilesoperatordaemon.security-profiles-operator.x-k8s.io/spod patched

    참고

    Security Profiles Operator는 spod 데몬 세트를 자동으로 다시 배포합니다.

  2. 다음 명령을 실행하여 감사 로그를 확인합니다.

    $ oc -n openshift-security-profiles logs -f ds/spod log-enricher

    출력 예

    I0623 12:51:04.257814 1854764 deleg.go:130] setup "msg"="starting component: log-enricher"  "buildDate"="1980-01-01T00:00:00Z" "compiler"="gc" "gitCommit"="unknown" "gitTreeState"="clean" "goVersion"="go1.16.2" "platform"="linux/amd64" "version"="0.4.0-dev"
    I0623 12:51:04.257890 1854764 enricher.go:44] log-enricher "msg"="Starting log-enricher on node: 127.0.0.1"
    I0623 12:51:04.257898 1854764 enricher.go:46] log-enricher "msg"="Connecting to local GRPC server"
    I0623 12:51:04.258061 1854764 enricher.go:69] log-enricher "msg"="Reading from file /var/log/audit/audit.log"
    2021/06/23 12:51:04 Seeked /var/log/audit/audit.log - &{Offset:0 Whence:2}

7.7.7.1. 로그 보강기를 사용하여 애플리케이션 추적

Security Profiles Operator 로그 강화기를 사용하여 애플리케이션을 추적할 수 있습니다.

프로세스

  1. 애플리케이션을 추적하려면 SeccompProfile 로깅 프로필을 생성합니다.

    apiVersion: security-profiles-operator.x-k8s.io/v1beta1
    kind: SeccompProfile
    metadata:
      name: log
      namespace: default
    spec:
      defaultAction: SCMP_ACT_LOG
  2. 프로필을 사용할 Pod 오브젝트를 생성합니다.

    apiVersion: v1
    kind: Pod
    metadata:
      name: log-pod
    spec:
      securityContext:
        seccompProfile:
          type: Localhost
          localhostProfile: operator/default/log.json
      containers:
        - name: log-container
          image: quay.io/security-profiles-operator/test-nginx-unprivileged:1.21
  3. 다음 명령을 실행하여 로그 보강기 출력을 검사합니다.

    $ oc -n openshift-security-profiles logs -f ds/spod log-enricher

    예 7.1. 출력 예

    …
    I0623 12:59:11.479869 1854764 enricher.go:111] log-enricher "msg"="audit"  "container"="log-container" "executable"="/" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=3 "syscallName"="close" "timestamp"="1624453150.205:1061" "type"="seccomp"
    I0623 12:59:11.487323 1854764 enricher.go:111] log-enricher "msg"="audit"  "container"="log-container" "executable"="/" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=157 "syscallName"="prctl" "timestamp"="1624453150.205:1062" "type"="seccomp"
    I0623 12:59:11.492157 1854764 enricher.go:111] log-enricher "msg"="audit"  "container"="log-container" "executable"="/" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=157 "syscallName"="prctl" "timestamp"="1624453150.205:1063" "type"="seccomp"
    …
    I0623 12:59:20.258523 1854764 enricher.go:111] log-enricher "msg"="audit"  "container"="log-container" "executable"="/usr/sbin/nginx" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=12 "syscallName"="brk" "timestamp"="1624453150.235:2873" "type"="seccomp"
    I0623 12:59:20.263349 1854764 enricher.go:111] log-enricher "msg"="audit"  "container"="log-container" "executable"="/usr/sbin/nginx" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=21 "syscallName"="access" "timestamp"="1624453150.235:2874" "type"="seccomp"
    I0623 12:59:20.354091 1854764 enricher.go:111] log-enricher "msg"="audit"  "container"="log-container" "executable"="/usr/sbin/nginx" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=257 "syscallName"="openat" "timestamp"="1624453150.235:2875" "type"="seccomp"
    I0623 12:59:20.358844 1854764 enricher.go:111] log-enricher "msg"="audit"  "container"="log-container" "executable"="/usr/sbin/nginx" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=5 "syscallName"="fstat" "timestamp"="1624453150.235:2876" "type"="seccomp"
    I0623 12:59:20.363510 1854764 enricher.go:111] log-enricher "msg"="audit"  "container"="log-container" "executable"="/usr/sbin/nginx" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=9 "syscallName"="mmap" "timestamp"="1624453150.235:2877" "type"="seccomp"
    I0623 12:59:20.454127 1854764 enricher.go:111] log-enricher "msg"="audit"  "container"="log-container" "executable"="/usr/sbin/nginx" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=3 "syscallName"="close" "timestamp"="1624453150.235:2878" "type"="seccomp"
    I0623 12:59:20.458654 1854764 enricher.go:111] log-enricher "msg"="audit"  "container"="log-container" "executable"="/usr/sbin/nginx" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=257 "syscallName"="openat" "timestamp"="1624453150.235:2879" "type"="seccomp"
    …

7.7.8. Webhook 구성

프로필 바인딩 및 프로필 기록 오브젝트에서는 Webhook를 사용할 수 있습니다. 프로필 바인딩 및 레코딩 오브젝트 구성은 Security Profiles Operator에서 관리하는 MutatingWebhookConfiguration CR입니다.

웹 후크 구성을 변경하기 위해 spod CR은 failurePolicy,namespaceSelector, objectSelector 변수를 수정할 수 있는 webhookOptions 필드를 노출합니다. 이를 통해 Webhook를 "soft-fail"로 설정하거나 네임스페이스의 하위 집합으로 제한하여 웹 후크가 실패, 기타 네임스페이스 또는 리소스에 영향을 미치지 않도록 할 수 있습니다.

절차

  1. 다음 패치 파일을 생성하여 spo- records=true 로 레이블이 지정된 Pod만 기록하도록 recording.spo.io 웹 후크 구성을 설정합니다.

    spec:
      webhookOptions:
        - name: recording.spo.io
          objectSelector:
            matchExpressions:
              - key: spo-record
                operator: In
                values:
                  - "true"
  2. 다음 명령을 실행하여 spod/spod 인스턴스를 패치합니다.

    $ oc -n openshift-security-profiles patch spod \
        spod -p $(cat /tmp/spod-wh.patch) --type=merge
  3. 결과 MutatingWebhookConfiguration 오브젝트를 보려면 다음 명령을 실행합니다.

    $ oc get MutatingWebhookConfiguration \
        spo-mutating-webhook-configuration -oyaml