Information in this document may be out of date
This document has an older update date than the original, so the information it contains may be out of date. If you're able to read English, see the English version for the most up-to-date information: Apply Pod Security Standards at the Cluster Level
ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๋ฅผ ํด๋ฌ์คํฐ ์์ค์ ์ ์ฉํ๊ธฐ
Note
์ด ํํ ๋ฆฌ์ผ์ ์๋ก์ด ํด๋ฌ์คํฐ์๋ง ์ ์ฉํ ์ ์๋ค.ํ๋ ์ํ๋ฆฌํฐ ์ด๋๋ฏธ์
(PSA, Pod Security Admission)์
๋ฒ ํ๋ก ๋ณ๊ฒฝ๋์ด v1.23 ์ด์์์ ๊ธฐ๋ณธ์ ์ผ๋ก ํ์ฑํ๋์ด ์๋ค.
ํ๋ ์ํ๋ฆฌํฐ ์ด๋๋ฏธ์
์ ํ๋๊ฐ ์์ฑ๋ ๋
ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋(Pod Security Standards)๋ฅผ
์ ์ฉํ๋ ์ด๋๋ฏธ์
์ปจํธ๋กค๋ฌ์ด๋ค.
์ด ํํ ๋ฆฌ์ผ์
baseline
ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๋ฅผ ํด๋ฌ์คํฐ ์์ค(level)์ ์ ์ฉํ์ฌ
ํ์ค ๊ตฌ์ฑ์ ํด๋ฌ์คํฐ์ ๋ชจ๋ ๋ค์์คํ์ด์ค์ ์ ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ ์ค๋ค.
ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๋ฅผ ํน์ ๋ค์์คํ์ด์ค์ ์ ์ฉํ๋ ค๋ฉด, ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๋ฅผ ๋ค์์คํ์ด์ค ์์ค์ ์ ์ฉํ๊ธฐ๋ฅผ ์ฐธ๊ณ ํ๋ค.
๋ง์ฝ ์ฟ ๋ฒ๋คํฐ์ค ๋ฒ์ ์ด v1.34์ด ์๋๋ผ๋ฉด, ํด๋น ๋ฒ์ ์ ๋ฌธ์๋ฅผ ํ์ธํ์.
์์ํ๊ธฐ ์ ์
์ํฌ์คํ ์ด์ ์ ๋ค์์ ์ค์นํ๋ค.
์ ์ฉํ ์๋ง์ ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋ ์ ํํ๊ธฐ
ํ๋ ์ํ๋ฆฌํฐ ์ด๋๋ฏธ์
์ ์ด์ฉํ์ฌ
enforce
, audit
, ๋๋ warn
๋ชจ๋ ์ค ํ๋๋ก
๋ด์ฅ ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๋ฅผ ์ ์ฉํ ์ ์๋ค.
ํ์ฌ ๊ตฌ์ฑ์ ๊ฐ์ฅ ์ ํฉํ ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๋ฅผ ๊ณ ๋ฅด๋ ๋ฐ ๋์์ด ๋๋ ์ ๋ณด๋ฅผ ์์งํ๋ ค๋ฉด, ๋ค์์ ์ํํ๋ค.
ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๊ฐ ์ ์ฉ๋์ง ์์ ํด๋ฌ์คํฐ๋ฅผ ์์ฑํ๋ค.
kind create cluster --name psa-wo-cluster-pss --image kindest/node:v1.24.0
๋ค์๊ณผ ๋น์ทํ๊ฒ ์ถ๋ ฅ๋ ๊ฒ์ด๋ค.
Creating cluster "psa-wo-cluster-pss" ... โ Ensuring node image (kindest/node:v1.24.0) ๐ผ โ Preparing nodes ๐ฆ โ Writing configuration ๐ โ Starting control-plane ๐น๏ธ โ Installing CNI ๐ โ Installing StorageClass ๐พ Set kubectl context to "kind-psa-wo-cluster-pss" You can now use your cluster with: kubectl cluster-info --context kind-psa-wo-cluster-pss Thanks for using kind! ๐
kubectl context๋ฅผ ์๋ก ์์ฑํ ํด๋ฌ์คํฐ๋ก ์ค์ ํ๋ค.
kubectl cluster-info --context kind-psa-wo-cluster-pss
๋ค์๊ณผ ๋น์ทํ๊ฒ ์ถ๋ ฅ๋ ๊ฒ์ด๋ค.
Kubernetes control plane is running at https://127.0.0.1:61350 CoreDNS is running at https://127.0.0.1:61350/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
ํด๋ฌ์คํฐ์ ๋ค์์คํ์ด์ค ๋ชฉ๋ก์ ์กฐํํ๋ค.
kubectl get ns
๋ค์๊ณผ ๋น์ทํ๊ฒ ์ถ๋ ฅ๋ ๊ฒ์ด๋ค.
NAME STATUS AGE default Active 9m30s kube-node-lease Active 9m32s kube-public Active 9m32s kube-system Active 9m32s local-path-storage Active 9m26s
--dry-run=server
๋ฅผ ์ฌ์ฉํ์ฌ ๋ค๋ฅธ ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๊ฐ ์ ์ฉ๋์์ ๋ ์ด๋ค ๊ฒ์ด ๋ณ๊ฒฝ๋๋์ง ํ์ธํ๋ค.- Privileged
kubectl label --dry-run=server --overwrite ns --all \ pod-security.kubernetes.io/enforce=privileged
๋ค์๊ณผ ๋น์ทํ๊ฒ ์ถ๋ ฅ๋ ๊ฒ์ด๋ค.
namespace/default labeled namespace/kube-node-lease labeled namespace/kube-public labeled namespace/kube-system labeled namespace/local-path-storage labeled
- Baseline
kubectl label --dry-run=server --overwrite ns --all \ pod-security.kubernetes.io/enforce=baseline
๋ค์๊ณผ ๋น์ทํ๊ฒ ์ถ๋ ฅ๋ ๊ฒ์ด๋ค.
namespace/default labeled namespace/kube-node-lease labeled namespace/kube-public labeled Warning: existing pods in namespace "kube-system" violate the new PodSecurity enforce level "baseline:latest" Warning: etcd-psa-wo-cluster-pss-control-plane (and 3 other pods): host namespaces, hostPath volumes Warning: kindnet-vzj42: non-default capabilities, host namespaces, hostPath volumes Warning: kube-proxy-m6hwf: host namespaces, hostPath volumes, privileged namespace/kube-system labeled namespace/local-path-storage labeled
- Restricted
kubectl label --dry-run=server --overwrite ns --all \ pod-security.kubernetes.io/enforce=restricted
๋ค์๊ณผ ๋น์ทํ๊ฒ ์ถ๋ ฅ๋ ๊ฒ์ด๋ค.
namespace/default labeled namespace/kube-node-lease labeled namespace/kube-public labeled Warning: existing pods in namespace "kube-system" violate the new PodSecurity enforce level "restricted:latest" Warning: coredns-7bb9c7b568-hsptc (and 1 other pod): unrestricted capabilities, runAsNonRoot != true, seccompProfile Warning: etcd-psa-wo-cluster-pss-control-plane (and 3 other pods): host namespaces, hostPath volumes, allowPrivilegeEscalation != false, unrestricted capabilities, restricted volume types, runAsNonRoot != true Warning: kindnet-vzj42: non-default capabilities, host namespaces, hostPath volumes, allowPrivilegeEscalation != false, unrestricted capabilities, restricted volume types, runAsNonRoot != true, seccompProfile Warning: kube-proxy-m6hwf: host namespaces, hostPath volumes, privileged, allowPrivilegeEscalation != false, unrestricted capabilities, restricted volume types, runAsNonRoot != true, seccompProfile namespace/kube-system labeled Warning: existing pods in namespace "local-path-storage" violate the new PodSecurity enforce level "restricted:latest" Warning: local-path-provisioner-d6d9f7ffc-lw9lh: allowPrivilegeEscalation != false, unrestricted capabilities, runAsNonRoot != true, seccompProfile namespace/local-path-storage labeled
- Privileged
์์ ์ถ๋ ฅ์์, privileged
ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๋ฅผ ์ ์ฉํ๋ฉด ๋ชจ๋ ๋ค์์คํ์ด์ค์์ ๊ฒฝ๊ณ ๊ฐ ๋ฐ์ํ์ง ์๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
๊ทธ๋ฌ๋ baseline
๋ฐ restricted
ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋์ ๋ํด์๋
kube-system
๋ค์์คํ์ด์ค์์ ๊ฒฝ๊ณ ๊ฐ ๋ฐ์ํ๋ค.
๋ชจ๋, ๋ฒ์ , ๋ฐ ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋ ์ค์
์ด ์น์
์์๋, ๋ค์์ ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๋ฅผ latest
๋ฒ์ ์ ์ ์ฉํ๋ค.
baseline
ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๋enforce
๋ชจ๋๋ก ์ ์ฉrestricted
ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๋warn
๋ฐaudit
๋ชจ๋๋ก ์ ์ฉ
baseline
ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๋
์์ธ ๋ชฉ๋ก์ ๊ฐ๊ฒฐํ๊ฒ ์ ์งํ๊ณ ์๋ ค์ง ๊ถํ ์์น(privilege escalations)์ ๋ฐฉ์งํ ์ ์๋
ํธ๋ฆฌํ ์ ์ถฉ์์ ์ ๊ณตํ๋ค.
์ถ๊ฐ์ ์ผ๋ก, kube-system
๋ด์ ํ๋๊ฐ ์คํจํ๋ ๊ฒ์ ๋ฐฉ์งํ๊ธฐ ์ํด,
ํด๋น ๋ค์์คํ์ด์ค๋ ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๊ฐ ์ ์ฉ๋์ง ์๋๋ก ์ ์ธํ ๊ฒ์ด๋ค.
์ฌ์ฉ ์ค์ธ ํ๊ฒฝ์ ํ๋ ์ํ๋ฆฌํฐ ์ด๋๋ฏธ์ ์ ์ ์ฉํ ๋์๋ ๋ค์์ ์ฌํญ์ ๊ณ ๋ คํ๋ค.
ํด๋ฌ์คํฐ์ ์ ์ฉ๋ ์ํ ์ํ์ ๋ฐ๋ผ,
restricted
์ ๊ฐ์ ๋ ์๊ฒฉํ ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๊ฐ ๋ ์ข์ ์๋ ์๋ค.kube-system
๋ค์์คํ์ด์ค๋ฅผ ์ ์ฉ ๋์์์ ์ ์ธํ๋ฉด ์ด ๋ค์์คํ์ด์ค์ ํ๋๊ฐprivileged
๋ก ์คํ๋ ์ ์๋ค. ์ค์ ์ฌ์ฉ ํ๊ฒฝ์์๋, ์ต์ ๊ถํ ์์น์ ์ค์ํ๋๋ก, ์ ๊ทผ์kube-system
๋ค์์คํ์ด์ค๋ก ์ ํํ๋ ์๊ฒฉํ RBAC ์ ์ฑ ์ ์ ์ฉํ ๊ฒ์ ๊ฐ๋ ฅํ ๊ถ์ฅํ๋ค.ํ๋ ์ํ๋ฆฌํฐ ์ด๋๋ฏธ์ ์ปจํธ๋กค๋ฌ๊ฐ ์ด๋ฌํ ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๋ฅผ ๊ตฌํํ๋ ๋ฐ ์ฌ์ฉํ ์ ์๋ ๊ตฌ์ฑ ํ์ผ์ ์์ฑํ๋ค.
mkdir -p /tmp/pss cat <<EOF > /tmp/pss/cluster-level-pss.yaml apiVersion: apiserver.config.k8s.io/v1 kind: AdmissionConfiguration plugins: - name: PodSecurity configuration: apiVersion: pod-security.admission.config.k8s.io/v1 kind: PodSecurityConfiguration defaults: enforce: "baseline" enforce-version: "latest" audit: "restricted" audit-version: "latest" warn: "restricted" warn-version: "latest" exemptions: usernames: [] runtimeClasses: [] namespaces: [kube-system] EOF
์ฐธ๊ณ :
`pod-security.admission.config.k8s.io/v1` ์ค์ ์ ์ฟ ๋ฒ๋คํฐ์ค v1.25 ์ด์์ ํ์๋ก ํ๋ค. ์ฟ ๋ฒ๋คํฐ์ค v1.23 ๊ณผ v1.24์ ๊ฒฝ์ฐ, [v1beta1](https://v1-24.docs.kubernetes.io/docs/tasks/configure-pod-container/enforce-standards-admission-controller/)์ ์ฌ์ฉํ๋ค. ์ฟ ๋ฒ๋คํฐ์ค v1.22์ ๊ฒฝ์ฐ, [v1alpha1](https://v1-22.docs.kubernetes.io/docs/tasks/configure-pod-container/enforce-standards-admission-controller/)์ ์ฌ์ฉํ๋ค.
API ์๋ฒ๊ฐ ํด๋ฌ์คํฐ ์์ฑ ๊ณผ์ ์์ ์ด ํ์ผ์ ์ฒ๋ฆฌํ ์ ์๋๋ก ๊ตฌ์ฑํ๋ค.
cat <<EOF > /tmp/pss/cluster-config.yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane kubeadmConfigPatches: - | kind: ClusterConfiguration apiServer: extraArgs: admission-control-config-file: /etc/config/cluster-level-pss.yaml extraVolumes: - name: accf hostPath: /etc/config mountPath: /etc/config readOnly: false pathType: "DirectoryOrCreate" extraMounts: - hostPath: /tmp/pss containerPath: /etc/config # optional: if set, the mount is read-only. # default false readOnly: false # optional: if set, the mount needs SELinux relabeling. # default false selinuxRelabel: false # optional: set propagation mode (None, HostToContainer or Bidirectional) # see https://kubernetes.io/ko/docs/concepts/storage/volumes/#๋ง์ดํธ-์ ํ-propagation # default None propagation: None EOF
์ฐธ๊ณ :
macOS์์ Docker Desktop๊ณผ KinD๋ฅผ ์ฌ์ฉํ๊ณ ์๋ค๋ฉด, Preferences > Resources > File Sharing ๋ฉ๋ด์์/tmp
๋ฅผ Shared Directory๋ก ์ถ๊ฐํ ์ ์๋ค.์ด๋ฌํ ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๋ฅผ ์ ์ฉํ๊ธฐ ์ํด ํ๋ ์ํ๋ฆฌํฐ ์ด๋๋ฏธ์ ์ ์ฌ์ฉํ๋ ํด๋ฌ์คํฐ๋ฅผ ์์ฑํ๋ค.
kind create cluster --name psa-with-cluster-pss --image kindest/node:v1.24.0 --config /tmp/pss/cluster-config.yaml
๋ค์๊ณผ ๋น์ทํ๊ฒ ์ถ๋ ฅ๋ ๊ฒ์ด๋ค.
Creating cluster "psa-with-cluster-pss" ... โ Ensuring node image (kindest/node:v1.24.0) ๐ผ โ Preparing nodes ๐ฆ โ Writing configuration ๐ โ Starting control-plane ๐น๏ธ โ Installing CNI ๐ โ Installing StorageClass ๐พ Set kubectl context to "kind-psa-with-cluster-pss" You can now use your cluster with: kubectl cluster-info --context kind-psa-with-cluster-pss Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community ๐
kubectl context๋ฅผ ์๋ก ์์ฑํ ํด๋ฌ์คํฐ๋ก ์ค์ ํ๋ค.
kubectl cluster-info --context kind-psa-with-cluster-pss
๋ค์๊ณผ ๋น์ทํ๊ฒ ์ถ๋ ฅ๋ ๊ฒ์ด๋ค.
Kubernetes control plane is running at https://127.0.0.1:63855 CoreDNS is running at https://127.0.0.1:63855/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
๊ธฐ๋ณธ ๋ค์์คํ์ด์ค์ ์์ฑํ ์ต์ํ์ ๊ตฌ์ฑ์ ๋ํ ํ๋ ๋ช ์ธ๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ์์ฑํ๋ค.
cat <<EOF > /tmp/pss/nginx-pod.yaml apiVersion: v1 kind: Pod metadata: name: nginx spec: containers: - image: nginx name: nginx ports: - containerPort: 80 EOF
ํด๋ฌ์คํฐ์ ํด๋น ํ๋๋ฅผ ์์ฑํ๋ค.
kubectl apply -f /tmp/pss/nginx-pod.yaml
๋ค์๊ณผ ๋น์ทํ๊ฒ ์ถ๋ ฅ๋ ๊ฒ์ด๋ค.
Warning: would violate PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "nginx" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "nginx" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "nginx" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "nginx" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost") pod/nginx created
์ ๋ฆฌํ๊ธฐ
kind delete cluster --name psa-with-cluster-pss
๋ฐ
kind delete cluster --name psa-wo-cluster-pss
๋ช
๋ น์ ์คํํ์ฌ
์์ฑํ๋ ํด๋ฌ์คํฐ๋ฅผ ์ญ์ ํ๋ค.
๋ค์ ๋ด์ฉ
- ๋ค์์ ๋ชจ๋ ๋จ๊ณ๋ฅผ ํ ๋ฒ์ ์ํํ๋ ค๋ฉด
์
ธ ์คํฌ๋ฆฝํธ๋ฅผ
์คํํ๋ค.
- ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋ ๊ธฐ๋ฐ์ ํด๋ฌ์คํฐ ์์ค ๊ตฌ์ฑ(configuration)์ ์์ฑ
- API ์๋ฒ๊ฐ ์ด ๊ตฌ์ฑ์ ์ฌ์ฉํ ์ ์๋๋ก ํ์ผ์ ์์ฑ
- ์ด ๊ตฌ์ฑ์ ์ฌ์ฉํ๋ API ์๋ฒ๋ฅผ ํฌํจํ๋ ํด๋ฌ์คํฐ๋ฅผ ์์ฑ
- kubectl context๋ฅผ ์๋ก ์์ฑํ ํด๋ฌ์คํฐ์ ์ค์
- ์ต์ํ์ ํ๋ ๊ตฌ์ฑ์ ์ํ yaml ํ์ผ์ ์์ฑ
- ํด๋น ํ์ผ์ ์ ์ฉํ์ฌ ์ ํด๋ฌ์คํฐ์ ํ๋๋ฅผ ์์ฑ
- ํ๋ ์ํ๋ฆฌํฐ ์ด๋๋ฏธ์
- ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋
- ํ๋ ์ํ๋ฆฌํฐ ์คํ ๋ค๋๋ฅผ ๋ค์์คํ์ด์ค ์์ค์ ์ ์ฉํ๊ธฐ