All technological notes.
Security Context
a field of pod definition to control container security
used to define privilege and access control settings for a Pod or Container.
Pod.spec.securityContext field
Pod.spec.containers.securityContext field
securityContext.runAsUser:
root(0)securityContext.runAsUser:
securityContext.fsGroup:
securityContext.supplementalGroups:
securityContext.supplementalGroupsPolicy
supplementary groups for the container processes in a pod.Merge:
/etc/group for the container’s primary user will be merged.Strict:
fsGroup, supplementalGroups, or runAsGroup fields are attached as the supplementary groups of the container processes./etc/group for the container’s primary user will be merged.securityContext.capabilities
apiVersion: v1
kind: Pod
metadata:
name: demo-capabilities
spec:
containers:
- name: demo
image: busybox:1.28
command: ["sh", "-c", "sleep 1h"]
securityContext:
capabilities:
add: ["NET_ADMIN", "SYS_TIME"]
securityContext.seccompProfile
seccompProfile.type:
RuntimeDefault, Unconfined, and LocalhostseccompProfile.localhostProfile:
securityContext:
seccompProfile:
type: RuntimeDefault
---
securityContext:
seccompProfile:
type: Localhost
localhostProfile: my-profiles/profile-allow.json
# demo-sc.yaml
apiVersion: v1
kind: Pod
metadata:
name: demo-sc
spec:
securityContext:
runAsUser: 1000
runAsGroup: 3000
fsGroup: 2000
supplementalGroups: [4000]
volumes:
- name: sec-ctx-vol
emptyDir: {}
containers:
- name: sec-ctx-demo
image: ubuntu
command: ["sh", "-c", "sleep 1h"]
volumeMounts:
- name: sec-ctx-vol
mountPath: /data/demo
securityContext:
allowPrivilegeEscalation: false
kubectl apply -f demo-sc.yaml
# pod/demo-sc created
kubectl exec -it demo-sc -- sh
id
# uid=1000 gid=3000 groups=2000,3000,4000