Course contentsShow
← Cloud and Infrastructure
Lesson 1402 of 2,98928. Kubernetes SecurityFree lesson

Filesystem Group and Ownership

Set fsGroup and supplemental groups to control file permissions for volumes mounted in pods.

Filesystem Group and Ownership

What you'll learn: How to control file permissions for volumes mounted in Kubernetes pods using fsGroup and supplemental groups.

The Problem with Default File Permissions

When Kubernetes mounts a volume into a pod, the files inside may have ownership and permissions that don't match the user or group your container runs as. This creates permission denied errors when your application tries to read or write files.

Think of it like moving into a shared apartment where all the closets are locked with someone else's key — you need the right credentials to access them.

Using fsGroup

The fsGroup field in a pod's security context tells Kubernetes to change the group ownership of all files in mounted volumes to a specific group ID. Your container processes can then access those files if they run as a member of that group.

apiVersion: v1
kind: Pod
metadata:
  name: fs-group-demo
spec:
  securityContext:
    fsGroup: 2000
  containers:
  - name: app
    image: nginx
    volumeMounts:
    - name: data
      mountPath: /data
  volumes:
  - name: data
    emptyDir: {}

In this example, all files under /data will be owned by group ID 2000, and the directory will have the group setgid bit set so new files inherit this group.

Supplemental Groups

You can also add the container user to additional groups using supplementalGroups, giving access to files owned by those groups without changing the files themselves.

securityContext:
  supplementalGroups: [3000, 4000]

Key Takeaway: Use fsGroup to ensure mounted volume files are accessible to your pod's processes by setting consistent group ownership, and add supplementalGroups when you need access to multiple group-owned resources.