본문으로 건너뛰기

Security Context


정보

Docker Security에 대한 사전 지식이 없다면 Docker Security 글 참조

Security Context

개념

  • 쿠버네티스의 securityContextPod나 컨테이너의 권한 및 접근 제어 설정을 정의하는 필드이다.
  • Docker에서 사용자와 권한을 관리하기 위해 docker run --user--cap-add 옵션을 사용하는 것과 유사한 기능이다.
    • 프로세스를 실행할 사용자 ID 설정, Linux Capabilities 추가/삭제 등

설정 방법

  • securityContextPod레벨, 컨테이너 레벨 모두에서 구성할 수 있다.

Pod 레벨 예시

apiVersion: v1
kind: Pod
metadata:
name: web-pod
spec:
securityContext:
runAsUser: 1000
containers:
- name: ubuntu
image: ubuntu
command: ["sleep", "3600"]
  • 위처럼 설정하면 해당 Pod에 존재하는 모든 컨테이너는 User ID 1000으로 실행된다.
  • Pod레벨에서는 capabilities를 설정할 수 없다.

컨테이너 레벨 예시

apiVersion: v1
kind: Pod
metadata:
name: web-pod
spec:
containers:
- name: ubuntu
image: ubuntu
command: ["sleep", "3600"]
securityContext:
runAsUser: 1000
capabilities:
add: ["KILL"]
  • 위처럼 설정하면 ubuntu 컨테이너만 User ID 1000으로 실행되며, KILL Linux Capabilities를 얻는다.

레퍼런스