Set Bind Mount Options on Volume Mounts
Kubernetes Docs · نسخهٔ f284a9e7c87f · CC BY 4.0 برای مستندات و مجوزهای همراه
<!-- overview -->
{{< feature-state feature_gate_name="VolumeBindMountOptions" >}}
This page shows how to apply security-related bind mount options (noexec, nodev, nosuid) to volume mounts in a Pod.
{{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
You need to have the VolumeBindMountOptions feature gate enabled on the API server and the kubelet. The container runtime must also support the mount_options field in the CRI Mount message.
<!-- steps -->
Create a Pod with bind mount options {#create-pod}
The .spec.containers[*].volumeMounts[*].bindMountOptions field accepts a list of bind mount flags. The allowed values are noexec, nodev, and nosuid.
For example, to mount an emptyDir volume at /tmp with noexec and nosuid so that binaries cannot be executed and set-user-ID bits are ignored:
{{% code_sample file="pods/bind-mount-options.yaml" %}}
- Create the pod on your cluster:
kubectl apply -f https://k8s.io/examples/pods/bind-mount-options.yaml- Verify the pod is running:
kubectl get pod bind-mount-options-demo- Check the mount options on the volume:
kubectl exec bind-mount-options-demo -- mount | grep /tmpThe output should include noexec and nosuid in the mount options.
- Verify that executing a binary on the mount fails:
kubectl exec bind-mount-options-demo -- sh -c 'cp /bin/ls /tmp/ls && /tmp/ls'The output is similar to:
sh: /tmp/ls: Permission denied- Delete the Pod that you created for this exercise:
kubectl delete pod bind-mount-options-demo{{% heading "whatsnext" %}}
- Learn more about bind mount options for volumes