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 non-compliant Pods and their controllers (run on any machine with kubectl access):
  2. For each affected controller (Deployment, StatefulSet, DaemonSet, Job, CronJob, etc.), edit the manifest to set readOnlyRootFilesystem: true (run on any machine with kubectl access). Example for a Deployment:
    In each affected container (and initContainer if present) under spec.template.spec.containers[] (or initContainers[]), ensure:
    If securityContext already exists, add only the readOnlyRootFilesystem: true line.
  3. If a container needs a writable path, add an emptyDir and mount it (same kubectl edit session as step 2):
    • Under spec.template.spec.volumes:
    • Under the appropriate container:
    Adjust name and mountPath as needed for each workload.
  4. For standalone Pods that are not managed by a higher-level controller, export, edit, and re-apply (run on any machine with kubectl access):
    Edit /tmp/pod-POD_NAME.yaml:
    • Remove metadata.uid, metadata.resourceVersion, metadata.creationTimestamp, metadata.ownerReferences, status and other server-populated fields.
    • Under spec.containers[] and spec.initContainers[] set:
      and, if needed, add emptyDir + volumeMounts as in step 3. Apply:
  5. Wait for updated workloads to roll out and confirm Pods are running (run on any machine with kubectl access):
  6. Verification (run on any machine with kubectl access):
    Confirm the output is is_compliant=true or that all listed containers show is_compliant=true.
On any machine with kubectl access:
  1. Identify non‑compliant Pods (and their controllers)
Use the audit output you already have to see the owner= field (e.g. Deployment/StatefulSet/Job). You must edit the owning controller, not the live Pod.
  1. Patch a controller to set readOnlyRootFilesystem: true
Example: patch a Deployment in namespace my-app named web so all containers use a read‑only root filesystem:
If securityContext already exists, use:
Repeat for each non‑compliant controller (Deployment, StatefulSet, DaemonSet, Job, CronJob), adjusting the resource type, name, namespace, and container index as needed.
  1. Provide writable paths via emptyDir (when needed)
If an application needs to write to specific paths, mount emptyDir volumes there instead of leaving the root filesystem writable. Example manifest snippet:
Apply the manifest:
  1. Verification
After controllers have rolled out new Pods, re‑run the audit command from any machine with kubectl: