forked from opencontainers/runc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chown cgroup to process uid in container namespace
Delegating cgroups to the container enables more complex workloads, including systemd-based workloads. The OCI runtime-spec was recently updated to explicitly admit such delegation, through specification of cgroup ownership semantics: opencontainers/runtime-spec#1123 Pursuant to the updated OCI runtime-spec, change the ownership of the container's cgroup directory and particular files therein, when using cgroups v2 and when the cgroupfs is to be mounted read/write. As a result of this change, systemd workloads can run in isolated user namespaces on OpenShift when the sandbox's cgroupfs is mounted read/write. It might be possible to implement this feature in other cgroup managers, but that work is deferred. Signed-off-by: Fraser Tweedale <[email protected]>
- Loading branch information
1 parent
20feb5d
commit 9b347a9
Showing
4 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env bats | ||
|
||
load helpers | ||
|
||
function teardown() { | ||
teardown_bundle | ||
} | ||
|
||
function setup() { | ||
setup_busybox | ||
|
||
set_cgroups_path | ||
|
||
# configure a user namespace | ||
update_config ' .linux.namespaces += [{"type": "user"}] | ||
| .linux.uidMappings += [{"hostID": 100000, "containerID": 0, "size": 65536}] | ||
| .linux.gidMappings += [{"hostID": 100000, "containerID": 0, "size": 65536}] | ||
' | ||
} | ||
|
||
|
||
# Common routine for chowning mount points to the container user. | ||
# This can't live in setup() because it needs to be guarded by | ||
# `requires root`. | ||
function chown_mounts() { | ||
# chown test temp dir to allow host user to read it | ||
chown 100000 "$ROOT" | ||
|
||
# chown rootfs to allow host user to mkdir mount points | ||
chown 100000 "$ROOT"/bundle/rootfs | ||
} | ||
|
||
@test "runc exec (cgroup v2, ro cgroupfs, new cgroupns) does not chown cgroup" { | ||
requires root cgroups_v2 systemd | ||
|
||
chown_mounts | ||
|
||
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroup_chown | ||
[ "$status" -eq 0 ] | ||
|
||
runc exec test_cgroup_chown sh -c "stat -c %U /sys/fs/cgroup" | ||
[ "$status" -eq 0 ] | ||
[ "$output" = "nobody" ] # /sys/fs/cgroup owned by unmapped user | ||
} | ||
|
||
@test "runc exec (cgroup v2, rw cgroupfs, inh cgroupns) does not chown cgroup" { | ||
requires root cgroups_v2 systemd | ||
|
||
set_cgroup_mount_writable | ||
|
||
# inherit cgroup namespace (remove cgroup from namespaces list) | ||
update_config '.linux.namespaces |= map(select(.type != "cgroup"))' | ||
|
||
chown_mounts | ||
|
||
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroup_chown | ||
[ "$status" -eq 0 ] | ||
|
||
runc exec test_cgroup_chown sh -c "stat -c %U /sys/fs/cgroup" | ||
[ "$status" -eq 0 ] | ||
[ "$output" = "nobody" ] # /sys/fs/cgroup owned by unmapped user | ||
} | ||
|
||
@test "runc exec (cgroup v2, rw cgroupfs, new cgroupns) does chown cgroup" { | ||
requires root cgroups_v2 systemd | ||
|
||
set_cgroup_mount_writable | ||
|
||
chown_mounts | ||
|
||
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroup_chown | ||
[ "$status" -eq 0 ] | ||
|
||
runc exec test_cgroup_chown sh -c "stat -c %U /sys/fs/cgroup" | ||
[ "$status" -eq 0 ] | ||
[ "$output" = "root" ] # /sys/fs/cgroup owned by root (of user namespace) | ||
} |