Skip to main content

More Info:

Verifies readOnlyRootFilesystem is true. A writable root filesystem lets an attacker persist tools or modify binaries inside a running container.

Risk Level

Medium

Address

Security

Compliance Standards

  • Cloudanix Best Practice

Triage and Remediation

Remediation

Manual Steps

  1. Identify noncompliant pods and their owning controllers (run on any machine with kubectl access):
  2. For each affected controller (Deployment/DaemonSet/StatefulSet/Job/CronJob), export its manifest (run on any machine with kubectl access; adjust kind/name/namespace):
  3. Edit the manifest to set readOnlyRootFilesystem: true for each affected container, and, if writes are needed, define an emptyDir volume and mount it at the writable path (run on any machine with kubectl access):
    Example changes inside each affected container spec:
    Apply the same pattern to initContainers if present.
  4. Apply the updated controller manifest so new pods use a read-only root filesystem (run on any machine with kubectl access):
  5. If necessary, recreate existing pods so they pick up the new security context (run on any machine with kubectl access):
    The controller will create new pods with readOnlyRootFilesystem: true.
  6. Verify all non-system pods now have readOnlyRootFilesystem set to true (run on any machine with kubectl access):
On any machine with kubectl access:
  1. Identify a noncompliant Pod and its owning workload (Deployment/DaemonSet/Job, etc.):
  1. Export the owning workload manifest:
  1. Edit containers to use a read-only root filesystem and add a writable emptyDir for any paths that must be writable.
Example patch in /tmp/deployment-readonly-fix.yaml:
Apply the same securityContext.readOnlyRootFilesystem: true and emptyDir pattern to every container and initContainer that currently needs a writable path.
  1. Apply the updated manifest:
  1. (If the Pod is not controlled by a higher-level object, edit it directly; note this is not persistent across restarts):
Add under each container / initContainer:
And define any emptyDir volumes and volumeMounts needed for writable paths.
  1. Verification (same scope: any machine with kubectl):
Run the audit and confirm readOnlyRootFilesystem=true and is_compliant=true for all containers: