Skip to content

Commit

Permalink
specgen, rootless: raise error with --device-cgroup-rule
Browse files Browse the repository at this point in the history
we were silently ignoring --device-cgroup-rule in rootless mode.  Make
sure an error is returned if the user tries to use it.

Closes: containers#18698

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Jun 26, 2023
1 parent 0357881 commit 0220f33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/specgen/generate/oci_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt
s.HostDeviceList = userDevices

// set the devices cgroup when not running in a user namespace
if isRootless && len(s.DeviceCgroupRule) > 0 {
return nil, fmt.Errorf("device cgroup rules are not supported in rootless mode or in a user namespace")
}
if !inUserNS && !s.Privileged {
for _, dev := range s.DeviceCgroupRule {
g.AddLinuxResourcesDevice(true, dev.Type, dev.Major, dev.Minor, dev.Access)
Expand Down
6 changes: 5 additions & 1 deletion test/system/030-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,11 @@ EOF
}

@test "podman run --device-cgroup-rule tests" {
skip_if_rootless "cannot add devices in rootless mode"
if is_rootless; then
run_podman 125 run --device-cgroup-rule="b 7:* rmw" --rm $IMAGE
is "$output" "Error: device cgroup rules are not supported in rootless mode or in a user namespace"
return
fi

run_podman run --device-cgroup-rule="b 7:* rmw" --rm $IMAGE
run_podman run --device-cgroup-rule="c 7:* rmw" --rm $IMAGE
Expand Down

0 comments on commit 0220f33

Please sign in to comment.