반응형
1. 개념
- 쿠버네티스는 컨테이너 실행 시 기본으로 root 권한으로 실행
- root 권한에서의 컨테이너 실행을 방지하기 위해 파드 또는 컨테이너 단위로 실행시킬 PID를 지정
2. SecurityContext 적용 비교
- SecurityContext를 적용하지 않은 경우(root로 실행)
apiVersion: v1
kind: Pod
metadata:
name: security-context-demo-1
spec:
containers:
- name: sec-ctx-demo
image: busybox:1.28
command: [ "sh", "-c", "sleep 1h" ]
- PID 확인
- SecurityContext를 파드 단위로 적용한 경우(PID 1000으로 실행)
apiVersion: v1
kind: Pod
metadata:
name: security-context-demo-2
spec:
securityContext:
runAsUser: 1000
containers:
- name: sec-ctx-demo
image: busybox:1.28
command: [ "sh", "-c", "sleep 1h" ]
- PID 확인
- SecurityContext를 컨테이너 단위로 적용한 경우(PID 2000으로 파드를 실행하지만 컨테이너는 PID 3000으로 실행)
apiVersion: v1
kind: Pod
metadata:
name: security-context-demo-3
spec:
securityContext:
runAsUser: 2000
containers:
- name: sec-ctx-demo
image: busybox:1.28
command: [ "sh", "-c", "sleep 1h" ]
securityContext:
runAsUser: 3000
- PID 확인
3. SecurityContext 옵션
- runAsUser : 파드 또는 컨테이너를 실행시킬 PID를 지정
- runAsGroup : 파드 또는 컨테이너를 실행시킬 GID를 지정
- fsGroup : 볼륨 마운트 시 활용할 PID를 지정
- runAsNonRoot : 컨테이너를 루트가 아닌 사용자로 실행할지 지정
반응형
'Kubernetes' 카테고리의 다른 글
Kubernetes PV·PVC 개념 및 설정 (0) | 2023.03.16 |
---|---|
Kubernetes 네트워크 정책(NetworkPolicy) 개념 및 설정1 (0) | 2023.03.16 |
Kubernetes 프라이빗 레포지토리(PrivateRepository) 개념 및 설정 (0) | 2023.03.16 |
Kubernetes 서비스어카운트(ServiceAccount) 개념 및 설정1 (0) | 2023.03.16 |
Kubernetes 클러스터 롤(ClusterRole) 개념 및 설정 (0) | 2023.03.16 |