Skip to main content

More Info:

The ability to create PersistentVolumes can be used to mount hostPath volumes and access the underlying node. Limit who can create them.

Risk Level

Medium

Address

Security

Compliance Standards

  • CIS Kubernetes

Triage and Remediation

Remediation

Manual Steps

  1. Identify all subjects that can create PersistentVolumes
    • Run on: any machine with kubectl access
    Save this list of ClusterRoles for review.
  2. Review the permissions in each identified ClusterRole
    • Run on: any machine with kubectl access
    For each displayed ClusterRole, decide if the create permission on persistentvolumes is truly required (e.g., storage admin vs general workloads).
  3. Map ClusterRoles with PV create permission to actual users/groups/service accounts
    • Run on: any machine with kubectl access
    Manually review each binding’s subjects to see which identities gain PV create capability.
  4. Decide and implement least-privilege changes
    For each ClusterRole where create on persistentvolumes is NOT strictly needed:
    • Edit the ClusterRole to remove create (and * if unused) for persistentvolumes:
      • Run on: any machine with kubectl access
      In the rules section, remove create from verbs for resources: ["persistentvolumes"], or split out a dedicated rule if other verbs are still required.
      If an identity needs only PV consumption, bind it instead to a narrower role that lacks PV create.
  5. If PV creation is needed, confine it to dedicated admin roles
    • Ensure only a small, storage-admin–style ClusterRole retains create on persistentvolumes.
    • Rebind ClusterRoleBindings so that:
      • General developers and application service accounts do NOT reference that ClusterRole.
      • Only designated admin groups/users (e.g., an ops group in your IdP) are subjects of the storage admin ClusterRoleBinding:
        Adjust the subjects list accordingly.
  6. Verify effective reduction of PV create access
    • Re-run the permission discovery and confirm only the intended ClusterRoles retain PV create:
    • Optionally, as a non-privileged user/service account, attempt to create a PersistentVolume and confirm it is rejected with a forbidden error.

Using kubectl

1. List all ClusterRoles that can create PersistentVolumesRun on: any machine with kubectl access.
If you don’t have jq, use:
Output indicating a problem:
Any ClusterRole name returned here grants create on persistentvolumes to whoever is bound to it. These roles need review to see if that permission is justified.

2. Inspect each identified ClusterRole’s rules in detailFor each ClusterRole name from step 1:
Review the rules: section, focusing on entries where:
Output indicating a problem:
  • Roles that are broad (e.g., verbs: ["*"] or resources: ["*"]) and include persistentvolumes.
  • Roles meant for general users, CI/CD, or application service accounts that also have create on persistentvolumes without a clear operational need.

3. Discover who actually gets these permissions (ClusterRoleBindings)For each problematic ClusterRole from step 2:
Without jq:
Then inspect each binding:
Output indicating a problem:
  • Bindings that grant the ClusterRole to:
    • system:authenticated, system:unauthenticated, or large groups (e.g., developers, ci-users) where most members do not need PV creation.
    • ServiceAccounts in namespaces unrelated to storage/cluster operations.
  • Any binding where you cannot clearly justify why that subject must create PersistentVolumes.

4. Verification after manual changesAfter you have manually updated or removed roles/bindings (via manifests or kubectl edit), re-run step 1:
Verification result interpretation:
  • If no ClusterRole names are returned, then no ClusterRole currently grants create on persistentvolumes.
  • If only a small, well-justified set of highly privileged operational roles are returned, you must confirm they are appropriate; if not, further manual adjustment is required.
How to run (any machine with kubectl access):
  • Save as report-pv-create-access.sh
  • Make executable: chmod +x report-pv-create-access.sh
  • Run: ./report-pv-create-access.sh
What indicates a problem:
  • Any ClusterRole or Role whose rules include:
    • resources: persistentvolumes with verbs containing create or *.
  • Especially concerning:
    • These roles bound to broad subjects, for example:
      • kind: Group, name: system:authenticated
      • kind: Group, name: system:masters (if that group is widely used)
      • ServiceAccounts used by application workloads rather than storage controllers.
  • For the summary section, any line like:
    • cluster-admin -> Group/system:authenticated
    • some-pv-manager -> ServiceAccount/default (ns:default) should be reviewed to confirm that subject truly requires PV creation rights.