Skip to content

Commit 1cd06e5

Browse files
committed
builder/daemonless: pass through /dev/kvm if present
Currently, if `devices.kubevirt.io/kvm` resources are requested in the build object, the resource request makes it to the build pod, but it doesn't really have any visible effect because the nested build process itself doesn't have access to it. The only reason we'd have `/dev/kvm` in our pod is if the user wants to use it in their build. So just pass it through if we find it. The use case for this is being able to build artifacts which would normally require privileges. One example includes base bootable container (bootc) images. Building these currently requires privileges because it itself uses containerization features. In the future, this should work with user namespacing, currently in Tech Preview. However, because we need not just uid 0 but `CAP_SYS_ADMIN`, and capabilities would still be restricted by default, we would still require access to non-default SCCs. (And of course, the builder would also have to be adapted to pass through the capabilities.) Another example is building disk images and shipping them in container images. This is done for example by Kubevirt and podman-machine. Two common ways to build disk images currently are via loopback devices or virtualization. The former can't be used because loopback devices are not namespaced and require privileges. This patch enables the latter. Using virtualization enables us to build these artifacts all while using the _default_ OpenShift restricted SCC.
1 parent 42fe165 commit 1cd06e5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pkg/build/builder/daemonless.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,13 @@ func buildDaemonlessImage(sc types.SystemContext, store storage.Store, isolation
298298
// in runtime-tools's generator logic.
299299
seccompProfilePath := "/usr/share/containers/seccomp.json"
300300

301+
// If we have /dev/kvm, pass it down to the build process since it likely means
302+
// that it was allocated to us with that expectation.
303+
devices := []string{}
304+
if _, err := os.Stat("/dev/kvm"); err == nil {
305+
devices = append(devices, "/dev/kvm")
306+
}
307+
301308
options := imagebuildah.BuildOptions{
302309
ContextDirectory: contextDir,
303310
PullPolicy: pullPolicy,
@@ -334,6 +341,7 @@ func buildDaemonlessImage(sc types.SystemContext, store storage.Store, isolation
334341
MaxPullPushRetries: DefaultPushOrPullRetryCount,
335342
PullPushRetryDelay: DefaultPushOrPullRetryDelay,
336343
SkipUnusedStages: types.OptionalBoolFalse,
344+
Devices: devices,
337345
}
338346

339347
if os.Getenv("BUILDAH_QUIET") == "true" {

0 commit comments

Comments
 (0)