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 (run on any machine with kubectl access):
  2. For each owning workload (Deployment/StatefulSet/DaemonSet/Job/CronJob) or standalone Pod found in step 1, export its manifest (run on any machine with kubectl access). Example for a Deployment:
    For a standalone Pod:
  3. Edit the manifest to set a read-only root filesystem (edit /tmp/workload.yaml on any machine with kubectl access):
    • Under each .spec.template.spec.containers[] and .spec.template.spec.initContainers[] (or .spec.containers[] / .spec.initContainers[] for a standalone Pod), ensure:
      If securityContext exists, add readOnlyRootFilesystem: true inside it.
  4. If the container needs writable paths, add emptyDir volumes and mount them (edit the same /tmp/workload.yaml):
    • Under spec.template.spec.volumes (or spec.volumes for a Pod) add, for each writable path:
    • Under the corresponding container’s volumeMounts:
    • Remove any reliance on writing to / or other parts of the root filesystem.
  5. Apply the updated manifest (run on any machine with kubectl access):
    For controllers (Deployments, etc.), this will roll out new pods. For standalone Pods, you may need to delete and recreate if they are not controlled:
  6. Verify compliance (run on any machine with kubectl access):
On any machine with kubectl access:
  1. Identify the non‑compliant Pod and its owner
If the Pod is controlled by a higher-level object (Deployment, StatefulSet, DaemonSet, Job, CronJob), you’ll see ownerReferences in the Pod spec. Always fix the controller, not the individual Pod.
  1. Patch a Deployment to use a read‑only root filesystem
Example for a Deployment owning the Pod:
If the container needs a writable path, also add an emptyDir volume and mount it:
  1. Equivalent manifest edits (for GitOps or IaC)
Edit your Deployment manifest (in Git or your IaC system) to include:
Apply it:
Use the corresponding kubectl patch/manifest changes for other controllers:
  • StatefulSet: kubectl patch statefulset <NAME> -n <NS> ...
  • DaemonSet: kubectl patch daemonset <NAME> -n <NS> ...
  • Job: kubectl patch job <NAME> -n <NS> ...
  • CronJob: kubectl patch cronjob <NAME> -n <NS> ...
  1. Verification
After the new Pods are running, rerun the audit (on any machine with kubectl):
Confirm that all relevant containers now show readOnlyRootFilesystem=true and is_compliant=true.