Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Kubernetes Day 3: Fixing File Permissions on Mounted Volumes and Docker Bind Mounts

A practical guide to mounted-file permission errors: compare process identity with path ownership, then apply a fix that fits the Kubernetes volume or Docker bind mount.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A pod can run as a non-root user and still receive “permission denied” on a mounted path: the process UID and GID are separate from the volume’s ownership and access rules. Diagnose both, then choose a fix supported by the volume type and storage driver. In Kubernetes, runAsUser and runAsGroup set process identity; fsGroup can provide group access to supported volumes. Docker host-path bind mounts are a related but distinct case, governed by host permissions and, in rootless mode, UID/GID mapping.

Why a mounted file or directory returns “permission denied”

Linux checks the running process’s user and groups against the file or directory’s owner, group, and mode bits. For a directory, the process also needs execute permission to traverse it; checking only the target file’s read or write bits can miss a restrictive parent directory. The mounted storage implementation may also affect ownership and access behavior.

As an Amazon Associate I earn from qualifying purchases.

In Kubernetes, runAsUser and runAsGroup set the process UID and primary GID. They do not, by themselves, make a mounted directory writable. Pod-level fsGroup is a separate group-access setting used for supported volumes. Which behavior applies depends on the volume type and storage driver. See the Kubernetes documentation on configuring a security context and volumes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Diagnose the identity and the mounted path

  1. Identify the volume and driver. Determine whether the path comes from a persistent volume, emptyDir, secret, configMap, or another source. For CSI-backed storage, check whether the driver supports VOLUME_MOUNT_GROUP.
  2. Inspect the process identity. Run id inside the container to see its UID, primary GID, and supplementary groups.
  3. Inspect numeric ownership and modes. Use ls -ln /path or stat /path inside the container. Check the file or directory and each parent directory in the path.
  4. Compare access requirements. Match the process UID and groups against the owner, group, and mode bits. Decide whether the application needs read, write, or directory traversal access, and grant only what it needs.
  5. Choose a volume-appropriate fix. Consider fsGroup only where the volume and driver support its group-access behavior. For ephemeral volume types, inspect their specific mode options and the application’s expectations instead.
  6. Check mount intent. For Docker bind mounts, verify host-side permissions and whether the mount is read-only. If Docker is rootless, also account for UID/GID mapping.

When Kubernetes fsGroup and fsGroupChangePolicy help

For supported volumes, Kubernetes normally adjusts ownership and permissions recursively when a Pod specifies fsGroup. The policy fsGroupChangePolicy controls that work: Always checks and changes permissions on each mount, while OnRootMismatch can skip the recursive change if the volume root already has the expected ownership and permissions. On a large volume, avoiding an unnecessary recursive traversal can reduce startup delay. The root’s ownership and permissions must remain consistent for the skip condition to be appropriate.

fsGroupChangePolicy does not apply to ephemeral secret, configMap, or emptyDir volumes. As Kubernetes states, “This field does not apply to ephemeral volume types such as secret, configMap, and emptyDir.” Do not treat setting fsGroup or the policy as a guaranteed recursive permission fix for those volume types.

CSI drivers may handle the mount group themselves

If a CSI driver supports the VOLUME_MOUNT_GROUP node capability, the driver handles the mount-group behavior. Kubernetes does not perform its own recursive ownership and permission change for that operation, so fsGroupChangePolicy has no effect on it. Confirm the storage class and driver behavior rather than assuming that all persistent volumes respond identically to fsGroup.

Example: Pod security-context field placement

This manifest illustrates where the fields appear; its emptyDir is not an example of a guaranteed recursive ownership fix. Use a supported persistent volume and validate its driver behavior when configuring ownership for production.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
apiVersion: v1
kind: Pod
metadata:
  name: permission-example
spec:
  securityContext:
    runAsUser: 1000
    runAsGroup: 3000
    fsGroup: 2000
    fsGroupChangePolicy: OnRootMismatch
  containers:
    - name: app
      image: example/image
      command: ["sh", "-c", "id && ls -ln /data && sleep 3600"]
      volumeMounts:
        - name: data
          mountPath: /data
  volumes:
    - name: data
      emptyDir: {}

The numeric IDs are illustrative, not universal recommendations. Pick values that align with the image, the files’ ownership, and the storage implementation. No manifest example can substitute for checking the identity and numeric permissions observed in the running container.

How Docker bind mounts differ

A Kubernetes volumeMount places a declared Pod volume at a container path. A Docker bind mount instead maps a host path directly into a container. Docker bind mounts are writable by default, and while mounted they hide any image content that was already at the destination path. Docker’s bind-mount documentation says, “Bind mounts have write access to files on the host by default.” Use a read-only mount if the container only needs to read the host files.

In Docker rootless mode, container UIDs and GIDs map to different host IDs, so ownership can look different inside the container and on the host. Check the mapping as well as host-side permissions using Docker’s UID/GID mapping documentation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose the least-permissive working configuration

  • Set the process UID and GID to the identity the application should use; do not expect those settings alone to change mounted-file ownership.
  • Use a supported group-access mechanism such as fsGroup only after confirming volume and driver behavior.
  • Consider OnRootMismatch when recursive permission work on a supported volume is costly and the root ownership invariant is maintained.
  • Keep mounts read-only when writes are unnecessary, and avoid broad permissions such as chmod 777 as a default fix. Broader modes weaken access controls and may not address UID/GID mapping or driver-specific behavior.

Kubernetes also documents bindMountOptions (noexec, nodev, nosuid) as an alpha, disabled-by-default feature beginning in v1.37. It requires container-runtime support and has no effect on Windows nodes; check the cluster version, feature gates, runtime, and node operating system before considering it. These options are not a general-purpose permission repair.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Docker Container Linux Devops Programming Coding T-Shirt
  • Docker, Docker Swarm, Docker Compose, Programmer, Developer, Coding, Programming, Software Engineer, Code, DevOps, Deploy, Deployment, Kubernetes, Salt, Puppet, Chef, Terraform, Container, AWS, Azure, Cloud, Geek, Funny, Computer, Software, Tech, IT
  • Integration, Scrum, Compile, Compilation, Science, Bug, Debug, Python, Linux, Java, Javascript, Scala, Dotnet, Kotlin
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.