Kubernetes 1.20: Granular Control of Volume Permission Changes
Authors: Hemant Kumar, Red Hat & Christian Huffman, Red Hat
Kubernetes 1.20 brings two important beta features, allowing Kubernetes admins and users alike to have more adequate control over how volume permissions are applied when a volume is mounted inside a Pod.
Allow users to skip recursive permission changes on mount
Traditionally if your pod is running as a non-root user (here.
But one side-effect of setting When configuring a pod’s security context, set You can learn more about this in . Although the previous section implied that Kubernetes always recursively changes permissions of a volume if a Pod has a So how do we know when to apply recursive permission changes and when we shouldn't? For in-tree storage drivers, this was relatively simple. For
Previously, whenever a CSI volume was mounted to a Pod, Kubernetes would attempt to automatically determine if the permissions and ownership should be modified. These methods were imprecise and could cause issues as we already mentioned, depending on the storage type. The CSIDriver custom resource now has a Three FSGroupPolicy values are available as of Kubernetes 1.20, with more planned for future releases. The only configuration needed is defining Depending on feedback and adoption, the Kubernetes team plans to push these implementations to GA in either 1.21 or 1.22. This feature is explained in more detail in Kubernetes project documentation: . The
Those interested in getting involved with the design and development of CSI or any part of the Kubernetes Storage system, join the
fsGroup
is that, each time a volume is mounted, Kubernetes must recursively chown()
and chmod()
all the files and directories inside the volume - with a few exceptions noted below. This happens even if group ownership of the volume already matches the requested fsGroup
, and can be pretty expensive for larger volumes with lots of small files, which causes pod startup to take a long time. This scenario has been a
fsGroupChangePolicy
to "OnRootMismatch" so if the root of the volume already has the correct permissions, the recursive permission change can be skipped. Kubernetes ensures that permissions of the top-level directory are changed last the first time it applies permissions.securityContext:
runAsUser: 1000
runAsGroup: 3000
fsGroup: 2000
fsGroupChangePolicy: "OnRootMismatch"
Allow CSI Drivers to declare support for fsGroup based permissions
fsGroup
, this is not strictly true. For certain multi-writer volume types, such as NFS or Gluster, the cluster doesn’t perform recursive permission changes even if the pod has a fsGroup
. Other volume types may not even support chown()
/chmod()
, which rely on Unix-style permission control primitives..spec.fsGroupPolicy
field, allowing storage drivers to explicitly opt in or out of these recursive modifications. By having the CSI driver specify a policy for the backing volumes, Kubernetes can avoid needless modification attempts. This optimization helps to reduce volume mount time and also cuts own reporting errors about modifications that would never succeed.CSIDriver FSGroupPolicy API
fsGroupPolicy
is defined; this preserves the behavior from previous Kubernetes releases. Each volume is examined at mount time to determine if permissions should be recursively applied.How do I use it?
fsGroupPolicy
inside of the .spec
for a CSIDriver. Once that element is defined, any subsequently mounted volumes will automatically use the defined policy. There’s no additional deployment required!What’s next?
How can I learn more?
How do I get involved?