FSGroup
#
Manage FSGroup Using Pod Security Context and CSI Driver SpecWe can manage permission change of volume using fsGroup. This helps non-root process to access the volume. CSI driver spec and Pod security context help us on when to apply permission change using fsGroup.
#
External Links Describing this Feature#
Implementation DetailsVolume ownership and permission are managed by kubelet. To mount CSI volume kubelet calls NodePublishVolume
implemented by SP
, after successful mount it tries to apply ownership and permission if required. Every volume in Kubernetes like configmap, secret, CSI volume implements Mounter
and Unmounter
interface. Volume ownership and permission are part of the SetUp
method of CSI Mounter.
#
ConfigurationStorage admin can set FSGroupPolicy
in CSI Driver spec with 3 values.
- ReadWriteOnceWithFSType - Modify the volume ownership and permissions to the defined
fsGroup
when theaccessMode
isRWO
andfsType
is set. - None - Mount the volume without attempting to modify volume ownership or permissions.
- File - Always attempt to apply the defined
fsGroup
to modify volume ownership and permissions regardless offsType
oraccessMode
.
Sample CSI Driver
Application developer can set PodFSGroupChangePolicy
in Pod spec with 2 values.
- OnRootMismatch - Only perform permission and ownership change if permissions of top-level directory do not match with expected permissions and ownership.
- Always - Always change the permissions and ownership to match
fsGroup
.
Sample Pod
#
Test PlansTest plans are a combination of:
- CSIDriver.Spec.FSGroupPolicy
- File
- None
- ReadWriteOnceWithFSType
- PersistentVolumeClaim.Status.AccessModes
- ReadWriteOnce
- ReadOnlyMany
- ReadWriteMany
LVM CSI driver supports only ReadWriteOnly access mode so updated combination:
- CSIDriver.Spec.FSGroupPolicy
- File
- None
- ReadWriteOnceWithFSType
- PersistentVolumeClaim.Status.AccessModes
- ReadWriteOnce
FSGroupPolicy
File
and ReadWriteOnceWithFSType
are equal for accesstype ReadWriteOnce
.
Here are the test cases -
- Deploy CSI Driver with
FSGroupPolicy
ReadWriteOnceWithFSType
initial and updated non-root process should be able to access the volume. - Deploy CSI Driver with
FSGroupPolicy
File
initial and updated non-root process should be able to access the volume. - Deploy CSI Driver with
FSGroupPolicy
None
initial and updated non-root process should not be able to access the volume. - For all
FSGroupPolicy
root process should be able to access volume. - If
fsGroup
is missing from the Pod spec then non-root process should not be able to access the volume.