Detect Docker containers in nested cgroup hierarchies (rootless Docker) - #959
Open
MsfPablo wants to merge 2 commits into
Open
Detect Docker containers in nested cgroup hierarchies (rootless Docker)#959MsfPablo wants to merge 2 commits into
MsfPablo wants to merge 2 commits into
Conversation
The Docker column matched cgroup paths by prefix, requiring the container's cgroup to sit directly under /system.slice (rootful Docker) or /docker (cgroup v1). Rootless Docker nests the container scope under the invoking user's slice, e.g. /user.slice/user-1000.slice/user@1000.service/user.slice/docker-<id>.scope which matched neither branch, so the column was silently empty. Match a `docker-<id>.scope` or `docker/<id>` path component at any depth instead, requiring the ID to be a full 64-hex-digit component so unrelated units such as docker.service are not picked up.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
Dockercolumn identifies a process's container by matching its cgroup path with two hard-coded prefixes:This assumes the container's cgroup sits at a fixed place in the hierarchy. That holds for cgroup v1 (
/docker/<id>) and for rootful, systemd-managed Docker on cgroup v2 (/system.slice/docker-<id>.scope), but rootless Docker nests the container scope under the invoking user's slice:Neither branch matches, so the
Dockercolumn is silently empty for rootless Docker users even though the container ID is right there in the path.Fix
Search for a container cgroup component at any depth rather than requiring a specific prefix:
docker-<id>.scopeas a whole path component (rootful and rootless cgroup v2, and any other nesting)dockerfollowed by<id>(cgroup v1, including nested variants)To avoid becoming too permissive, the ID must be a complete component of exactly 64 hex digits — which is the form Docker container IDs take, and the form of the keys in the container-ID→name map this value is looked up in. So
docker.service,docker-desktop.scope, andprefix-docker-<id>.scopeare not matched.The extraction is pulled out into a standalone
container_id_from_cgroupfunction so it can be unit-tested directly. Behaviour for rootful Docker is unchanged.Tests
Five unit tests added in
src/columns/docker.rscovering cgroup v1, cgroup v2 rootful (existing behaviour), cgroup v2 rootless (the fix), a set of non-container cgroup paths, and a guard that the ID must be a whole path component.Verification
Because the affected code is
#[cfg(any(target_os = "linux", target_os = "android"))], it was checked against the Linux target from a macOS host:That one lint is pre-existing — it reproduces identically on an unmodified checkout (verified via
git stash), and this change introduces no new clippy findings.The new tests were executed by temporarily relaxing the
cfggate so the parsing function (pure string logic, platform-independent) builds on the host:I do not have a Linux machine with rootless Docker to hand, so the end-to-end behaviour is verified by the unit tests against the documented cgroup path shape rather than against a live rootless daemon. Happy to adjust if the maintainers' rootless setups produce a different path.
Disclosure: this change was written with AI assistance (Claude). It has been reviewed by me before submission.