CKS 시험 범위 정리

디오·2022년 4월 15일
1

참고

공부하면서 정리한 시험범위 및 문제 예상

  • 시험범위
    • Cluster Setup(10%)
      • Use Network security policies to restrict cluster level access
        • NetworkPolicy 설정하는 문제
        • default-deny-all
          apiVersion: networking.k8s.io/v1
          kind: NetworkPolicy
          metadata:
            name: default-deny-all
          spec:
            podSelector: {}
            policyTypes:
            - Egress
            - Ingress
      • Use CIS benchmark to review the security configuration of Kubernetes components (etcd, kubelet, kubedns, kubeapi)
        • kube-bench 결과를 바탕으로 위반사항 고치는 문제
          # 마스터 노드 검사
          ./kube-bench --config-dir `pwd`/cfg --config `pwd`/cfg/config.yaml master
          
          # 워커 노드 검사
          ./kube-bench --config-dir `pwd`/cfg --config `pwd`/cfg/config.yaml node
      • Properly set up Ingress objects with security control
        • ingress에 tls 설정하는 문제 ⇒ 인그레스 TLS
          • Create TLS Certificate & key
          • Create a Secret
          • Apply to ingress yaml
      • Protect node metadata and endpoints
        • NetworkPolicy 설정해서 metadata 서버 접근 못하게 하는 문제. 네임스페이스A 만 허용하도록 하는 변형 가능해보임.
        • 클라우드 프로바이더 metadata 서버 쪽으로 접근 못하게 설정. podSelector를 통해 특정 파드는 접근 열 수 있음.
          apiVersion: networking.k8s.io/v1
          kind: NetworkPolicy
          metadata:
            name: cloud-metadata-deny
          spec:
            podSelector: {}
            policyTypes:
            - Egress
            egress:
            - to:
              - ipBlock:
                  cidr: 0.0.0.0/0
                  except:
                  - 169.254.169.254/32
      • Minimize use of, and access to, GUI elements
        • kubernetes-dashboard 서비스어카운트 RBAC 설정하는 문제
          • Creating a Service Account User
          • Create ClusterRole
          • Create ClusterRoleBinding
          • Retrieve Bearer Token & Use
      • Verify platform binaries before deploying
        • sha512sum 으로 바이너리 해시값 비교하는 문제
    • Cluster Hardening(15%)
      • 🥸 Restrict access to Kubernetes API
        • 유저 생성하고 CERT 발급하고 kubeconfig 설정하고 해당 유저에게 롤 부여하는 문제
        • 시험환경의 kubeconfig가 복잡하기 때문에 출제 가능성은 낮아보임.
      • Use RBAC to minimize exposure
        • sa, role, rolebinding 만들고 Pod에 설정하는 내용으로 보임

          spec:
            serviceAccountName: deployment-viewer-sa
      • Exercise caution in using service accounts e.g. disable defaults, minimize permissions on newly created ones
        • 권한 & SA 생성하고 바인딩. 그리고 특정 파드에서 sa 사용하는 문제
      • Update Kubernetes frequently
    • System Hardening(15%)
      • Minimize host OS footprint (reduce attack surface)
        • privileged true로 되어있는 파드 검출하고 삭제하는 문제
          spec:
            securityContext:
              runAsUser: RunAsAny
              runAsGroup: RunAsAny
              fsGroup: RunAsAny
            # container will use host IPC namespace (Default is false)
            hostIPC: true
            # containers will use host network namespace (Default is false)
            hostNetwork: true
            # containers will use host pid namespace (Default is false)
            hostPID: true
            containers:
              - image: nginx:latsts
                name: web
                resources: {}
                securityContext:
                  # container will ran as root (Default is false)
                  privileged: true
      • Minimize IAM roles
        • aws, gcp 권한 잘 설정해라~
      • Minimize external access to the network
        apiVersion: networking.k8s.io/v1
        kind: NetworkPolicy
        metadata:
          name: deny-external-egress
        spec:
          podSelector: {}
          policyTypes:
          - Egress
          egress:
            to:
            - namespaceSelector: {}
      • Appropriately use kernel hardening tools such as AppArmor, seccomp
        • AppArmor & seccomp 프로파일 생성은 시험에 안나올 거고 생성된 프로파일 사용하는 정도만 나올듯
        • 🥸 AppArmor
          • aa-status 명령어로 프로파일 확인하고 포드 어노테이션 설정 container.apparmor.security.beta.kubernetes.io/<container_name>
            # controlplane
            apparmor_parser /root/profile
            aa-status | grep docker-nginx-custom
            
            # node01
            scp /root/profile node01:/root
            ssh node01
                apparmor_parser /root/profile
                aa-status | grep docker-nginx-custom
            apiVersion: v1
            kind: Pod
            metadata:
              annotations:
                container.apparmor.security.beta.kubernetes.io/secure: localhost/docker-nginx-custom
              name: secure
            spec:
              containers:
              - image: nginx
                name: secure
        • seccomp
          • kubelet seccomp 경로 확인 및 설정하고 해당 경로에 프로파일 저장
            • /var/lib/kubelet/seccomp/profiles
            • 모든 워커 노드에서 동일하게 작업
          • pod > securityContext > seccompProfile 설정
            apiVersion: v1
            kind: Pod
            metadata:
              name: audit-pod
              labels:
                app: audit-pod
            spec:
              securityContext:
                seccompProfile:
                  type: Localhost
                  # specfy violation.json or fine-grained.json
                  localhostProfile: profiles/audit.json
              containers:
              - name: test-container
                image: hashicorp/http-echo:0.2.3
                args:
                - "-text=just made some syscalls!"
                securityContext:
                  allowPrivilegeEscalation: false
    • Minimize Micro-Service Vulnerabilities(20%)
      • 🥸 Setup appropriate OS level security domains e.g. using PSP, OPA, security contexts
        • pod 또는 container 레벨 securityContext, runAsNonRoot, privileged 설정하는 내용
        • PSP 설정 문제 반드시 나올 것으로 예상함
          • 파드시큐리티폴리시 리소스가 생성되면 아무 것도 수행하지 않는다.

          • 이를 사용하려면 요청 사용자 또는 대상 파드의 서비스 어카운트는 정책에서 use 동사를 허용하여 정책을 사용할 권한이 있어야 한다.

            kubectl create role psp-access --verb=use --resource=podsecuritypolicies
            kubectl create rolebinding psp-access --role=psp-access --serviceaccount=default:default
        • securityContext
          • 루트 권한, 읽기쓰기 설정 같이 보안에 위협이 되는 설정을 가진 오브젝트 찾아서 삭제하는 문제.
      • Manage Kubernetes secrets
        • EncryptionConfiguration 설정해서 시크릿 암호화해서 저장하고 복호화 하는 문제
        • 컨테이너를 통한 시크릿 노출 확인하는 문제 볼륨, env, api-server
      • 🥸 Use container runtime sandboxes in multi-tenant environments (e.g. gvisor, kata containers)
        • 런타임클래스 생성하고 포드 스펙에 런타임 지정하고 커널명령어 실행하는 문제
          apiVersion: node.k8s.io/v1
          kind: RuntimeClass
          metadata:
            name: gvisor
          handler: runsc
          apiVersion: v1
          kind: Pod
          metadata:
            name: mypod
          spec:
            runtimeClassName: gvisor
            # ...
      • Implement pod to pod encryption by use of mTLS
        • istio가 필요한데 출제 어렵다고 봄
    • Supply Chain Security(20%)
      • Minimize base image footprint
        • Use Slim/Minimal Images than base images
        • Use Docker multi stage builds for lean
        • Use Distroless:
          • Distroless Images will have only your app & runtime dependencies
            • No package managers, shell, n/w tools, text editors etc
          • Distroless images are very small
      • 🥸 Secure your supply chain: whitelist allowed registries, sign and validate images
        • ✨ ImagePolicyWebhook Admission 설정하는 문제
          • kube-apiserver 매니패스트에서 폴리시 위치 확인하고 문제에 맞게 수정 --admission-control-config-file
          • 폴리시에 맞는 플러그인 설정 활성화 --enable-admission-plugins
          • config 경로에 있는 kubeconfig 도 확인
      • Use static analysis of user workloads (e.g.Kubernetes resources, Docker files)
        • Dockerfile 내용 보고 root 유저 같은 것들 요구사항에 변경하는 문제
        • kubesec 으로 yaml 검사하는 문제
          # run scan using kubesec
          kubesec scan pod.yaml
          # run kubesec locally on 8080 port
          kubesec http 8080 &
          #kubesec API invoke and scan
          curl -sSX POST --data-binary @”pod.yaml" https://v2.kubesec.io/scan
      • 🥸 Scan images for known vulnerabilities
        • trivy 사용해서 위험한 이미지 사용하는 파드 삭제하는 문제
          • $ trivy image python:3.4-alpine
    • Monitoring, Logging and Runtime Security(20%)
      • 🥸 Perform behavioral analytics of syscall process and file activities at the host and container level to detect malicious activities
        • Falco 룰 설정해서 특정 파드 혹은 이미지에서 발생하는 이벤트 추적하고 원하는 메세지 출력하는 문제
      • Detect threats within physical infrastructure, apps, networks, data, users and workloads
      • Detect all phases of attack regardless where it occurs and how it spreads
      • Perform deep analytical investigation and identification of bad actors within environment
      • 🥸 Ensure immutability of containers at runtime
        • 볼륨 쓰기 설정 못하게 설정하는 문제
        • readOnlyRootFilesystem = true, privileged=false
        • Enforce using PSP(Pod Security Policies) 전체에 적용됨
          apiVersion: policy/v1beta1
          kind: PodSecurityPolicy
          metadata:
            name: example
          spec:
            privileged: false
            readOnlyRootFilesystem: true
            runAsUser:
              rule: RunAsNonRoot
            seLinux:
              rule: RunAsAny
            supplementalGroups:
              rule: RunAsAny
            runAsUser:
              rule: RunAsNonRoot
            fsGroup:
              rule: RunAsAny
      • 🥸 Use Audit Logs to monitor access
        • Audit 로그 설정하는 문제
        • Audit log 설정 작성 (None, Metadata, Request, RequestResponse 순으로 데이터가 많아짐)
          apiVersion: audit.k8s.io/v1 # This is required.
          kind: Policy
          # Don't generate audit events for all requests in RequestReceived stage.
          omitStages:
            - "RequestReceived"rules:
            - namespace: ["prod-namespace"]
              verb: ["delete"]
              resources:
              - groups: " "resources: ["pods"]
                resourceNames: ["webapp-pod"]
              #None/Metadata/Request/RequestResponse
              level: RequestResponse
        • kube-apiserver 설정에서 아래 옵션 활성화하고 볼륨마운트도 꼭 해주기
          - --audit-log-path=/var/log/k8-audit.log
          - --audit-policy-file=/etc/kubernetes/audit-policy.yaml
          - --audit-log-maxage=10
          - --audit-log-maxbackup=5
          - --audit-log-maxsize=100
          ...
          volumeMounts:
            - mountPath: /etc/kubernetes/audit-policy.yaml
              name: audit
              readOnly: true
            - mountPath: /var/log/kubernetes/audit/
              name: audit-log
              readOnly: false
          ...
          volumes:
          - name: audit
            hostPath:
              path: /etc/kubernetes/audit-policy.yaml
              type: File
          
          - name: audit-log
            hostPath:
              path: /var/log/kubernetes/audit/
              type: DirectoryOrCreate
profile
디오디오

0개의 댓글