Running Containers as Root
Deploying containers that run as the root user (UID 0) without proper justification, violating the principle of least privilege
Kubernetes pods deployed without proper security context configurations, allowing containers to run with excessive privileges, as root user, or with dangerous capabilities. These misconfigurations can lead to container escape, privilege escalation, and compromise of the underlying node and cluster.
# VULNERABLE: Pod without security context
apiVersion: v1
kind: Pod
metadata:
name: webapp
namespace: production
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80# SECURE: Pod with proper security context
apiVersion: v1
kind: Pod
metadata:
name: webapp
namespace: production
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1000
fsGroup: 1000
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 8080
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
volumeMounts:
- name: cache
mountPath: /var/cache/nginx
- name: run
mountPath: /var/run
volumes:
- name: cache
emptyDir: {}
- name: run
emptyDir: {}The vulnerable pod runs without security context, defaulting to root user with all capabilities and writable filesystem. The secure version enforces non-root execution, drops all capabilities, uses read-only root filesystem, and prevents privilege escalation.
Deploying containers that run as the root user (UID 0) without proper justification, violating the principle of least privilege
Sourcery automatically identifies kubernetes pod security context misconfigurations and many other security issues in your codebase.