始めに
Security Contextとは、個々のコンテナに対するセキュリティ設定のこと。
コンテナ、Podレベルで設定できる。
Dockerでは、以下のように、コンテナの実行に際して、User IDを指定できる。
docker run --user=1001 ubuntu(image) sleep 1000
それと同じようなことを、k8sで実行できる。
YAML
---
apiVersion: v1
kind: Pod
metadata:
name: xxxxx
namespace: default
## User ID 1010で、sleep Commandを実行する。
spec:
securityContext:
runAsUser: 1010
containers:
- command:
- sleep
- "3000"
image: xxxxx
name: xxxxx
---
apiVersion: v1
kind: Pod
metadata:
name: xxxxx
namespace: default
spec:
containers:
- command:
- sleep
- "3500"
image: xxxxx
name: xxxxx
## root userとして、SYS_TIMEを実行。
securityContext:
capabilities:
add: ["SYS_TIME"]
なお、Podレベルで設定すると、設定はPod内の全てのコンテナに引き継がれる。
Podレベルか、コンテナレベルどちらで設定するかは、
単に、securityContext:をspec:に含めて書くか、spec:containers:の中に書くか、の違いで反映できる。
参考
https://kubernetes.io/ja/docs/concepts/security/pod-security-standards/
Kubernetes完全ガイド (impress top gear)
https://www.udemy.com/course/certified-kubernetes-administrator-with-practice-tests/
参考にさせていただきました。ありがとうございます。
備考
何か間違っている記載ありましたら教えていただけると嬉しいです。