예시
CAP_CHOWN: 파일 소유자 변경 가능
CAP_DAC_OVERRIDE / CAP_DAC_READ_SEARCH: 파일 접근 제어 권한 무시 가능
CAP_NET_BIND_SERVICE: 낮은 포트(0~1023)에 바인딩 가능
CAP_SYS_ADMIN: 시스템 관리 작업 수행 가능
Kubernetes에서는 Linux Capabilites를 통해 루트 사용자의 모든 권한을 부여하지 않고 컨테이너 프로세스에 특정 권한을 부여 (add)하거나 제거 (drop)할 수 있음
참고: Linux Capabilities의 형식은 CAPXXX으로 되어 있음. 그러나 Kuberentes Manifest에 기능을 적용할 때는 CAP상수 부분을 생략해야 함. 예를 들어 CAP_SYS_TIME을 추가하려면 SYS_TIME으로 설정 필요
apiVersion: v1
kind: Pod
metadata:
name: security-context-demo-4
spec:
containers:
- name: sec-ctx-4
image: gcr.io/google-samples/node-hello:1.0
securityContext:
capabilities:
add: ["NET_ADMIN", "SYS_TIME"]
출처: https://learn.snyk.io/lesson/container-does-not-drop-all-default-capabilities/
$ cat /proc/1/status
...
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 00000000a80425fb
CapAmb: 0000000000000000
...
$ capsh --decode=00000000a80425fb
0x00000000a80425fb=cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_net_bind_service,cap_net_raw,cap_sys_chroot,cap_mknod,cap_audit_write,cap_setfcap
apiVersion: v1
kind: Pod
metadata:
name: security-context-demo-4
spec:
containers:
- name: sec-ctx-4
image: gcr.io/google-samples/node-hello:1.0
securityContext:
capabilities:
add: all
$ cat /proc/1/status
...
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 0000001fffffffff
CapAmb: 0000000000000000
...
$ capsh --decode=0000001fffffffff
0x0000001fffffffff=cap_chown,cap_dac_override,cap_dac_read_search,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_linux_immutable,cap_net_bind_service,cap_net_broadcast,cap_net_admin,cap_net_raw,cap_ipc_lock,cap_ipc_owner,cap_sys_module,cap_sys_rawio,cap_sys_chroot,cap_sys_ptrace,cap_sys_pacct,cap_sys_admin,cap_sys_boot,cap_sys_nice,cap_sys_resource,cap_sys_time,cap_sys_tty_config,cap_mknod,cap_lease,cap_audit_write,cap_audit_control,cap_setfcap,cap_mac_override,cap_mac_admin,cap_syslog,35,36
apiVersion: v1
kind: Pod
metadata:
name: security-context-demo-4
spec:
containers:
- name: sec-ctx-4
image: gcr.io/google-samples/node-hello:1.0
securityContext:
capabilities:
drop: all
$ cat /proc/1/status
...
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 0000000000000000
CapAmb: 0000000000000000
...
$ capsh --decode=0000000000000000
0x0000000000000000=
(1) root 계정 / CAP_SYS_TIME 추가
# date
Mon Nov 20 16:16:08 KST 2023
# date -s '19 APR 2012 22:00:00'
Thu Apr 19 22:00:00 KST 2012
# date
Thu Apr 19 22:00:02 KST 2012
(2) root 계정 / CAP_SYS_TIME 제거
# date
Mon Nov 20 16:34:47 KST 2023
# date -s '19 APR 2012 22:00:00'
date: cannot set date: Operation not permitted
Thu Apr 19 22:00:00 KST 2012
# date
Mon Nov 20 16:35:23 KST 2023
(3) 일반 사용자 계정 / CAP_SYS_TIME 추가
$ date
Mon Nov 20 16:12:48 KST 2023
$ date -s '19 APR 2012 22:00:00'
date: cannot set date: Operation not permitted
$ date
Mon Nov 20 16:12:48 KST 2023
→ Super User 계정이면서 CAP_SYS_TIME 기능이 추가된 경우에만 시간 변경 가능
$ ls -l
total 72
drwxr-xr-x 2 root root 4096 Nov 20 15:02 function
drwxr-xr-x 1 root root 4096 Sep 15 13:28 node_modules
-rw-r--r-- 1 root root 61168 Sep 15 13:28 package-lock.json
-rw-r--r-- 1 root root 476 Sep 15 13:28 package.json
$ chmod 755 package.json
chmod: changing permissions of 'package.json': Operation not permitted
$ chown root package.json
chown: changing ownership of 'package.json': Operation not permitted
$ ls -l
total 72
drwxr-xr-x 2 root root 4096 Nov 20 15:02 function
drwxr-xr-x 1 root root 4096 Sep 15 13:28 node_modules
-rw-r--r-- 1 root root 61168 Sep 15 13:28 package-lock.json
-rw-r--r-- 1 root root 476 Sep 15 13:28 package.json
# ls -l
total 72
drwxr-xr-x 2 root root 4096 Nov 20 15:02 function
drwxr-xr-x 1 root root 4096 Sep 15 13:28 node_modules
-rw-r--r-- 1 root root 61168 Sep 15 13:28 package-lock.json
-rw-r--r-- 1 root root 476 Sep 15 13:28 package.json
# chmod 755 package.json
# chown functionuser package.json
chown: changing ownership of 'package.json': Operation not permitted
# ls -l
total 72
drwxr-xr-x 2 root root 4096 Nov 20 15:02 function
drwxr-xr-x 1 root root 4096 Sep 15 13:28 node_modules
-rw-r--r-- 1 root root 61168 Sep 15 13:28 package-lock.json
-rwxr-xr-x 1 root root 476 Sep 15 13:28 package.json