feat: add uid/gid StorageClass parameters for volume directory ownership #1252
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1252"
general
weight: 0.35
kginonredhat
What type of PR is this?
/kind feature
What this PR does / why we need it:
Adds optional
uidandgidStorageClass parameters (and matching static PVvolumeAttributes) so the driver canchownthe newly created NFS subdirectory. Today onlymountPermissionsexists; directories stay owned by root and unknown keys such aspermissions/uidare rejected.This came from a multi-tenant Kubernetes Slack discussion and is tracked in #1251 (related stale request: #183).
Behavior:
chownthe volume subdirectory inCreateVolumeafter mkdirNodePublishVolumeso static PVs workuid/gidinto the internal share-root mount (avoids chowning the NFS export root)chown(no_root_squashor an allowed squash uid)Which issue(s) this PR fixes:
Fixes #1251
Special notes for your reviewer:
PVC-level owner fields and annotation templating are out of scope (called out on the issue).
fsGroupremains supported and can still run after this chown.Does this PR introduce a user-facing change?:
``
release-note
``feat: add optional uid/gid StorageClass parameters to chown dynamically provisioned NFS directories
Manual steps to verify the fix
After creating a local Rootful kind cluster - important if you use rootless it can not do NFS kernel mounts.
1. export KUBECONFIG=~/.kube/config
2. compiling the new changes Rebuild the plugin
podman run --rm -v "$PWD:/src:Z" -w /src docker.io/library/golang:1.26 \
sh -c 'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod=vendor -o bin/amd64/nfsplugin ./cmd/nfsplugin'
3. # image (Dockerfile copies bin/amd64/nfsplugin → /nfsplugin)
podman build --build-arg ARCH=amd64 -t docker.io/library/nfsplugin:uidgid .
4. Load it into kind. With podman, archive load is the reliable path:
podman save docker.io/library/nfsplugin:uidgid | sudo kind load image-archive /dev/stdin --name nfs-csi
pullPolicy: Never later means kubelet will only use this image. It will not pull upstream canary.
5. Kind-on-podman: mask host USB devices
Privileged CSI pods can crash-loop when runc tries to bind-mount host USB devices. Hide them on the kind node:
sudo podman exec nfs-csi-control-plane sh -c \
'mkdir -p /run/empty-usb /dev/bus/usb; mountpoint -q /dev/bus/usb || mount --bind /run/empty-usb /dev/bus/usb'
This is an environment workaround, not part of the CSI feature.
6. Give the NFS server a filesystem it can export
Kernel nfsd cannot export overlayfs. Kind’s / is overlay, and the example server uses hostPath /nfs-vol. Put tmpfs there:
sudo podman exec nfs-csi-control-plane sh -c \
'mkdir -p /nfs-vol; mountpoint -q /nfs-vol || mount -t tmpfs -o size=512m tmpfs /nfs-vol; chmod 777 /nfs-vol; df -T /nfs-vol'
expected result
Filesystem Type 1K-blocks Used Available Use% Mounted on
tmpfs tmpfs 524288 0 524288 0% /nfs-vol
7. Install the CSI driver using Helm
This creates:
helm install csi-driver-nfs ./charts/latest/csi-driver-nfs \
--namespace kube-system \
--set image.nfs.repository=docker.io/library/nfsplugin \
--set image.nfs.tag=uidgid \
--set image.nfs.pullPolicy=Never \
--wait --timeout 3m
kubectl -n kube-system get pods -l app.kubernetes.io/instance=csi-driver-nfs
kubectl -n kube-system get deploy/csi-nfs-controller ds/csi-nfs-node \
-o jsonpath='{range .items[]}{.metadata.name}{" "}{.spec.template.spec.containers[?(@.name=="nfs")].image}{"\n"}{end}'
expected result
NAME READY STATUS RESTARTS AGE
csi-nfs-controller-5f46c55bc-fqncr 5/5 Running 0 3s
csi-nfs-node-jtgv8 3/3 Running 0 3s
csi-nfs-controller docker.io/library/nfsplugin:uidgid
csi-nfs-node docker.io/library/nfsplugin:uidgid
8. Start an NFS backend (not CSI)
Start an NFS backend (not CSI)
CSI-NFS does not ship an NFS server. This pod is just the share. It bind-mounts the kind node’s /nfs-vol as /exports and exports it with no_root_squash (needed for chown).
kubectl apply -f deploy/example/nfs-provisioner/nfs-server.yaml
kubectl -n default rollout status deploy/nfs-server --timeout=120s
kubectl logs deploy/nfs-server --tail=20
Look for Startup successful and /exports exported. Export validation failed means step 3 was skipped.
8. StorageClass — this is the new feature
provisioner: nfs.csi.k8s.io sends these parameters into CreateVolume. uid / gid are the new keys. Sidecars also inject PVC/PV name.
kubectl apply -f - <<'EOF'
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: nfs-csi
provisioner: nfs.csi.k8s.io
parameters:
server: nfs-server.default.svc.cluster.local
share: /
mountPermissions: "0770"
uid: "243"
gid: "243"
reclaimPolicy: Delete
volumeBindingMode: Immediate
mountOptions:
- nfsvers=4.1
EOF
expected result:
kginon@kginon-thinkpadp1gen7:~/k8s-projects/csi-driver-nfs$ kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
nfs-csi nfs.csi.k8s.io Delete Immediate false 18s
standard (default) rancher.io/local-path Delete WaitForFirstConsumer false 4h31m
9. PVC — this triggers CreateVolume
kubectl apply -f - <<'EOF'
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-nfs-uidgid
spec:
accessModes: [ReadWriteMany]
resources:
requests:
storage: 1Gi
storageClassName: nfs-csi
EOF
kubectl get pvc pvc-nfs-uidgid -w
kubectl get pvc pvc-nfs-uidgid -w
persistentvolumeclaim/pvc-nfs-uidgid created
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE
pvc-nfs-uidgid Pending pvc-116c3cd2-99be-4ca7-ab90-b87cf30b120b 0 nfs-csi <unset> 0s
pvc-nfs-uidgid Bound pvc-116c3cd2-99be-4ca7-ab90-b87cf30b120b 1Gi RWX nfs-csi <unset> 0s
What happens:
csi-provisioner calls CreateVolume on the controller nfs container.
Plugin mounts nfs-server:/ internally, mkdir’s a subdir named after the PV.
chmod 0770, then chown 243:243 on that subdir only (not the export root).
Unmounts; Kubernetes binds the PVC to a PV whose source is server:/<subdir>.
Watch it:
10. Pod — this triggers NodePublishVolume
kubectl apply -f - <<'EOF'
apiVersion: v1
kind: Pod
metadata:
name: uidgid-check
spec:
securityContext:
runAsUser: 243
runAsGroup: 243
fsGroup: 243
containers:
- name: pause
image: registry.k8s.io/e2e-test-images/busybox:1.36.1-1
command: ["sleep", "3600"]
volumeMounts:
- name: data
mountPath: /mnt/nfs
volumes:
- name: data
persistentVolumeClaim:
claimName: pvc-nfs-uidgid
EOF
kubectl wait --for=condition=Ready pod/uidgid-check --timeout=120s
Excepted result:
pod/uidgid-check created
pod/uidgid-check condition met
runAsUser/runAsGroup are so the process is 243 (otherwise you cannot write even if the dir is 243). fsGroup is kubelet’s extra pass (fsGroupPolicy: File); it can add the setgid s bit. The uid/gid on the directory should already be 243 from step 7.
11. Verify (plugin vs kubelet vs backing store)
what the pods sees
kginon@kginon-thinkpadp1gen7:~/k8s-projects/csi-driver-nfs$ kubectl exec uidgid-check -- ls -ldn /mnt/nfs
kubectl exec uidgid-check -- sh -c 'touch /mnt/nfs/from-pod && ls -ln /mnt/nfs/from-pod'
drwxrws--- 2 243 243 40 Aug 23 08:57 /mnt/nfs
-rw-r--r-- 1 243 243 0 Aug 23 09:03 /mnt/nfs/from-pod
sudo podman exec nfs-csi-control-plane ls -ln /nfs-vol
sudo podman exec nfs-csi-control-plane sh -c 'ls -ldn /nfs-vol/pvc-'
total 0
drwxrws---. 2 243 243 60 Aug 23 09:02 pvc-116c3cd2-99be-4ca7-ab90-b87cf30b120b
drwxrws---. 2 243 243 60 Aug 23 09:02 /nfs-vol/pvc-116c3cd2-99be-4ca7-ab90-b87cf30b120b
Expect:
/mnt/nfs → drwxrws--- 243:243
from-pod created as 243:243
kind node /nfs-vol/<pv-name> same ownership
/nfs-vol itself still root:root — only the PVC subdir was chown’d