scope: allow unprivileged delegation on scopes

Previously it was possible to set delegate property for scope, but you
were not able to allow unprivileged process to manage the scope's cgroup
hierarchy. This is useful when launching manager process that  will run
unprivileged but is supposed to manage its own (scope) sub-hierarchy.

Fixes #21683
This commit is contained in:
Michal Sekletar
2022-08-04 17:01:13 +02:00
committed by Lennart Poettering
parent a552061ebb
commit 03860190fe
7 changed files with 143 additions and 17 deletions
+14
View File
@@ -3,6 +3,16 @@
set -eux
set -o pipefail
test_scope_unpriv_delegation() {
useradd test ||:
trap "userdel -r test" RETURN
systemd-run --uid=test -p User=test -p Delegate=yes --slice workload.slice --unit workload0.scope --scope \
test -w /sys/fs/cgroup/workload.slice/workload0.scope -a \
-w /sys/fs/cgroup/workload.slice/workload0.scope/cgroup.procs -a \
-w /sys/fs/cgroup/workload.slice/workload0.scope/cgroup.subtree_control
}
if grep -q cgroup2 /proc/filesystems ; then
systemd-run --wait --unit=test0.service -p "DynamicUser=1" -p "Delegate=" \
test -w /sys/fs/cgroup/system.slice/test0.service/ -a \
@@ -31,6 +41,10 @@ if grep -q cgroup2 /proc/filesystems ; then
# And now check again, "io" should have vanished
grep -qv io /sys/fs/cgroup/system.slice/cgroup.controllers
# Check that unprivileged delegation works for scopes
test_scope_unpriv_delegation
else
echo "Skipping TEST-19-DELEGATE, as the kernel doesn't actually support cgroup v2" >&2
fi