Interview Prep/DevSecOps/Kubernetes Security

What does a hardened `securityContext` look like?

BeginnerConceptKubernetes Security
Answer
spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 10001
    fsGroup: 10001
    seccompProfile: { type: RuntimeDefault }
  containers:
  - name: api
    image: ghcr.io/acme/api@sha256:...
    securityContext:
      allowPrivilegeEscalation: false
      readOnlyRootFilesystem: true
      capabilities: { drop: ["ALL"] }

This passes the restricted profile. readOnlyRootFilesystem stops attackers dropping tools on disk; mount an emptyDir at /tmp if the app needs scratch space.

All DevSecOps questions Roadmap: Supply chain, secrets & identity

More on Kubernetes Security