kubernetes: volumeDevices mapping ignored when container is privileged
What happened: When using the raw block PV feature, if your container is privileged, then the volumeDevices.devicePath specified in the Pod spec are silently ignored by the container runtime since all host devices are mapped into the container at /dev.
This is an issue with the raw block feature since its inception and impacts all volume plugins and most runtimes (docker, containerd to name a few)
What you expected to happen: At least when the container’s devicePath is non-conflicting with the host (ie not in /dev), it should be mapped correctly.
I’m on the fence about what should happen if the devicePath is “/dev”. Disallowing “/dev” entirely would be a breaking change (even though it’s pretty non-functional today). Overriding “/dev” could also be a breaking change?
How to reproduce it (as minimally and precisely as possible):
apiVersion: v1
kind: Pod
metadata:
name: test
spec:
containers:
- image: debian:latest
imagePullPolicy: IfNotPresent
name: nginx
command: ["/bin/sh"]
args:
- "-c"
- "while true; do sleep 10;done"
securityContext:
privileged: true
volumeDevices:
- devicePath: /my-disk
name: disk1
volumes:
- name: disk1
persistentVolumeClaim:
claimName: disk1
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: disk1
spec:
volumeMode: Block
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
Anything else we need to know?: Current workaround for this issue is to have an unprivileged init container that copies the devices to an emptydir shared with the privileged container.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 45 (29 by maintainers)
@jingxu97
Suppose we have the following manifest
When I then run
kubectl exec test-pod -- ls -l /disksI getSo
ssd1mount is ignored in privileged mode and the device is instead available directly at/dev/sdf, which is completely arbitrary - next time it may be/dev/sdgor/dev/sdh, depending on what other PDs are attached to the node.However if I change
privilegedto false,ssd1is mounted successfullyBut in this case I can’t do anything with
nvme0n1because unprivileged pods are not allowed to write to block devices mounted as a hostPath (naturally, I need both devices writable).@akhilerm Can you share how you checked this issue with containerd?
Regarding how the devices are passed: