Study/K8S

Docker Security

monitor 2023. 3. 19. 13:06

Security


docker user 지정

docker run ubuntu sleep 3600

 


cli

docker run --user=1000 ubuntu sleep 3000

Dockerfile

FROM ubuntu
USER 1000

컨테이너 안의 루트 유저는 루트 유저의 호스트와 다릅니다.

docker run --privileged를 사용해서 런 시켜야 컨테이너의 루트 사용자 처럼 행동합니다.

 


Kuberbetes Security

pod - level security

apiVersion: v1
kind: Pod
metadata:
    name: web-pod
spec:
    securiyContext:
        runAsUser: 1000
       containers:
        - name: ubuntu
          image: ubuntu
          command: ["sleep","3600"]

Container - level security

apiVersion: v1
kind: Pod
metadata:
    name: web-pod
spec:
       containers:
        - name: ubuntu
          image: ubuntu
          command: ["sleep","3600"]
          securiyContext:
            runAsUser: 1000
          capabilities:
              add:["MAC_ADMIN"]

 

 


기존 Pod를 내리고 변경 할 때의 팁

 

kubectl replace --force -f <바꾼.yaml 파일> //같은 이름의 pod를 내리고 replace한다.