Kubernetes, blockDevices & denied permissions
Mounting (block)devices on containers might result in permission errors (Permission denied) if pods have applied a securityContext. It's possible to configure this on containerd and get both of best worlds - fast device access and reduced permissions on containers.
We're currently quite diving into kubevirt and came upon an issue with block volumes that have been cloned using datavolume.
The datavolume looks like this
This creates a new PVC that will be attached. As we're running a recent version of kubevirt the virtlauncher pod runs as qemu user (= no root permissions).
The issue now is that the blockdevice is owned by root and gid 6 which result in the fact that qemu cannot attach the blockdevice to the VM.
As a result, the issue shows as following in the logs
After all - the permission mismatch results in the error that kubevirt can't map the blockdevice into the VM.
The solution is to adjust the containerd settings in such a way that block devices are mounted using the securityContext of the pod as owner.
or here
(sources: https://github.com/kubevirt/containerized-data-importer/issues/2378 & https://kubernetes.io/blog/2021/11/09/non-root-containers-and-devices/)
Just apply the change, restart containerd and new pods will be able to attach the disks as expected.