참고
공부하면서 정리한 시험범위 및 문제 예상
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
spec:
podSelector: {}
policyTypes:
- Egress
- Ingress
# 마스터 노드 검사
./kube-bench --config-dir `pwd`/cfg --config `pwd`/cfg/config.yaml master
# 워커 노드 검사
./kube-bench --config-dir `pwd`/cfg --config `pwd`/cfg/config.yaml node
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
sha512sum
으로 바이너리 해시값 비교하는 문제sa, role, rolebinding 만들고 Pod에 설정하는 내용으로 보임
spec:
serviceAccountName: deployment-viewer-sa
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
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: deny-external-egress
spec:
podSelector: {}
policyTypes:
- Egress
egress:
to:
- namespaceSelector: {}
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
/var/lib/kubelet/seccomp/profiles
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
파드시큐리티폴리시 리소스가 생성되면 아무 것도 수행하지 않는다.
이를 사용하려면 요청 사용자 또는 대상 파드의 서비스 어카운트는 정책에서 use
동사를 허용하여 정책을 사용할 권한이 있어야 한다.
kubectl create role psp-access --verb=use --resource=podsecuritypolicies
kubectl create rolebinding psp-access --role=psp-access --serviceaccount=default:default
볼륨
, env
, api-server
apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
name: gvisor
handler: runsc
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
runtimeClassName: gvisor
# ...
--admission-control-config-file
--enable-admission-plugins
# 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
trivy
사용해서 위험한 이미지 사용하는 파드 삭제하는 문제$ trivy image python:3.4-alpine
readOnlyRootFilesystem = true, privileged=false
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
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
- --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