Description
Allocate a dedicated non-root UID for the container. Before setting runAsUser, check how the UID maps to users on the host or shared volumes.
Potential impact
If the mapped UID owns accessible files, the container may gain another user’s file access. Changing the UID can also deny access to files the app needs.
Remediation
Check container overrides, runAsGroup and volume ownership, and remove unused host mounts. Test that the app can access its own files and that other users’ private files stay protected.
Examples
The image must support the chosen UID, and volume permissions must allow that user the access it needs.
Before
apiVersion: v1
kind: Pod
metadata:
name: security-context-demo-2
spec:
securityContext:
runAsUser: 1000
containers:
- name: sec-ctx-demo-2
image: gcr.io/google-samples/node-hello:1.0
securityContext:
runAsUser: 2000
allowPrivilegeEscalation: false
The container’s UID 2000 overrides the Pod default of 1000.
After
apiVersion: v1
kind: Pod
metadata:
name: security-context-demo-2
spec:
securityContext:
runAsUser: 10000
containers:
- name: sec-ctx-demo-2
image: gcr.io/google-samples/node-hello:1.0
securityContext:
runAsUser: 10100
allowPrivilegeEscalation: false
After the change, the container’s UID 10100 overrides the Pod default of 10000. Even above 10000, verify the actual mapping and file permissions.