Skip to content

Hand a container's cgroup to the user it runs as - #865

Closed
MayCXC wants to merge 4 commits into
apple:mainfrom
MayCXC:cgroup-delegation
Closed

Hand a container's cgroup to the user it runs as#865
MayCXC wants to merge 4 commits into
apple:mainfrom
MayCXC:cgroup-delegation

Conversation

@MayCXC

@MayCXC MayCXC commented Aug 27, 2026

Copy link
Copy Markdown

Summary

A container that runs as somebody other than root cannot use the cgroup it was placed in: the kernel keeps it for whoever owns the directory, so anything nested inside that wants to hold its own work to a limit finds the tree closed. On a machine the service manager solves this by delegating a subtree to a user session. Nothing here does, because the runtime is what creates the cgroup, and so is already the one privileged to give it away.

Grant the user the directory, cgroup.procs, cgroup.threads and cgroup.subtree_control, which is what the kernel documents delegation to mean. The resource files stay where they are: they distribute the parent's resources rather than this cgroup's own, so the limits a container was given still bind everything it puts underneath.

A container asks for this through its configuration, and a pod's containers ask the same way.

Dependency and Merge Order

This targets stock apple/containerization:main and depends on #863. Please merge #863 first.

The head carries #863's three commits as prerequisites, because both PRs target stock main. After #863 merges this branch can take current main, leaving only the delegation change and its test.

Motivation and Context

This is what a nested runtime looks for. Rootless runc asks a service manager to delegate a cgroup, and without one it ends up with no cgroup at all, so a container runtime running inside a container cannot hold its own workloads to limits. The delegation set is the one the kernel's cgroup-v2 documentation names, not a guess:
https://github.com/opencontainers/runc/blob/main/docs/cgroup-v2.md

It is opt-in through the configuration, so nothing changes for containers that do not ask.

Testing

  • swift build and make check clean.
  • swift test: 603 tests in 83 suites passed.
  • Integration: container cgroup delegation runs a container as a non-root user and asserts it can place its own work under a limit, which fails without the delegation.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

MayCXC added 4 commits August 27, 2026 20:43
The reaper that runs at a concurrency of one deletes everything in the
test directory except the unpacked rootfs it means to preserve. It held
that rootfs path as FileManager reports it, under /var, and compared it
against the entries of contentsOfDirectory, which reports them under
/private/var, so the preserved path never matched any entry and the
rootfs was deleted along with the per-test files. The unpack coordinator
still held it as unpacked, so the next test opened a rootfs that was no
longer there and failed with a missing file error.

Resolve both sides with resolvingSymlinksInPathWithPrivate, which exists
for this difference between the two views of the same directory.
Tests guarded for Linux are compiled out on macOS, so `make test` reports
success without having run them, and nothing says so. The target that
does run them is not mentioned anywhere outside the makefile.
The default kernel the tests fetch had drifted from the one users run.
container installs kata 3.28.0 and its 6.18.15 kernel, while these tests
fetched 3.17.0, so the suite exercised a guest with a different feature
set to the one it is meant to represent. Nested runtimes are the visible
case: 3.17.0 was built without nf_tables, so a docker daemon inside a
container fails there and works on what ships.

Kata moved from xz to zstd between those releases, so the archive is no
longer named for its compression and tar is left to recognise it rather
than being told, which also holds if the format changes again.
A container that runs as somebody other than root cannot use the cgroup it
was placed in: the kernel keeps it for whoever owns the directory, so
anything nested inside that wants to hold its own work to a limit finds the
tree closed. On a machine the service manager solves this by delegating a
subtree to a user session. Nothing here does, because the runtime is what
creates the cgroup, and so is already the one privileged to give it away.

Grant the user the directory, cgroup.procs, cgroup.threads and
cgroup.subtree_control, which is what the kernel documents delegation to
mean. The resource files stay where they are: they distribute the parent's
resources rather than this cgroup's own, so the limits a container was
given still bind everything it puts underneath.

A container asks for this through its configuration, and a pod's containers
ask the same way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants