Skip to content

A user's own group is one of its supplementary groups, as with Docker - #360

Open
cloudlabworks wants to merge 1 commit into
libracoder:mainfrom
cloudlabworks:user-primary-gid-groups
Open

cloudlabworks wants to merge 1 commit into
libracoder:mainfrom
cloudlabworks:user-primary-gid-groups

Conversation

@cloudlabworks

Copy link
Copy Markdown

docker run --user 1000:1000 on Kiri gives a process with no supplementary
groups; Docker gives it 1000. The same for a named user and for
docker exec --user. Docker starts the list with the user's gid
(usr.AdditionalGids = []uint32{usr.GID} in moby's getUser,
daemon/oci_linux.go), then adds the /etc/group memberships and
--group-add. Kiri now does the same, in supplementary_groups.

Access through the primary group already worked (it is the process's gid);
what differed is getgroups(), id, and Groups: in /proc/self/status.

grep Groups /proc/self/status in alpine:latest, Apple silicon, macOS 27.0.1:

docker run ... Docker Engine 29.8.2 (OrbStack) Kiri 0.2.1 this PR
(no --user) 0 0 1 2 3 4 6 10 11 20 26 27 0 1 2 3 4 6 10 11 20 26 27 0 1 2 3 4 6 10 11 20 26 27
--user nobody 65534 (none) 65534
--user 1000:1000 1000 (none) 1000
--user nobody:nogroup 65533 (none) 65533
--user 65534:1234 1234 (none) 1234
--user 1000:1000 --group-add 2000 1000 2000 2000 1000 2000
--user nobody --group-add 2000 2000 65534 2000 2000 65534
exec --user 1000:1000 1000 (none) 1000
exec --user nobody 65534 (none) 65534

The list is sorted and deduplicated (the kernel sorts it anyway), so root
shows 0 once where Docker lists it twice.

One difference this PR leaves alone: for a numeric user that /etc/passwd
doesn't have (--user 1000 in alpine), Docker uses gid 0
(uid=1000 gid=0(root) groups=0(root)), and Kiri uses the uid as the gid
(uid=1000 gid=1000). So --user 1000 now shows Groups: 1000 on Kiri and
0 on Docker. Kiri's choice looks deliberate (resolve_user), so I did not
change it; say if you want it to match Docker.

Tests:

  • Unit test the_users_own_group_is_a_supplementary_group_as_with_docker
    (groups_from takes the group file's text, so it runs without a container).
  • e2e: user-groups-primary (-u 1000:1000 --group-add 2000 gives
    1000 2000) and user-groups-exec (exec -u nobody gives 65534). Both
    fail on 0.2.1 and pass with this change.

How it was tested: cargo test -p kiri-init in a rust:1-alpine container
(aarch64 Linux, Rust 1.100.0): 71 passed, 1 failed, where main gives 70 passed,
1 failed; the failure is linux::layers::tests::whiteout_becomes_char_device
on both (an unprivileged container). cargo clippy -p kiri-init --all-targets and cargo fmt --check report the same findings on main and
on this branch, none in the changed lines (one is in this function on main
too: the nested if over /etc/group members, collapsible_if, left as is
to keep the diff small). Then cargo xtask host on the Mac
and cargo xtask guest in that container, run as a second daemon: the table
above.

Platforms: kiri-init is the container runtime on all three systems (the VM
on a Mac, beside kiri on a Linux host, and in WSL on Windows), so the change
is the same everywhere. Run only on Apple silicon so far.

AndreKurait added a commit to AndreKurait/asagiri that referenced this pull request Nov 16, 2026
Adapt public Kiri PR #360, preserving its author and original date. Run and exec
now include their resolved primary group beside /etc/group and --group-add.
Keep Asagiri's existing gid 0 behavior for unknown numeric users and check it.

The enhanced run/exec fixture checks primary membership for all eleven user
forms and explicit group-add. Native dev.99 reproduced the missing membership;
the compiled Linux ARM64 production-helper and existing user-resolution unit
tests pass in an owned native-guest container, which was verified removed.
Full paired Docker/private-Asagiri run/exec validation remains pending CI.

Upstream-PR: libracoder/kiri#360
Upstream-Commit: 996fbc5cd4ae9fccc868770c168ee336b104f2ac
Co-authored-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <akurait@amazon.com>
AndreKurait added a commit to AndreKurait/asagiri that referenced this pull request Nov 16, 2026
Return RFC3339Nano SystemTime from the same daemon clock as container events.
This satisfies Compose 5.7's event-subscription precondition without waking a
sleeping VM. Add a paired Docker/private-Asagiri fixture that binds the clock
to retained volume events, checks later cutoffs and removes its owned volume.
The cold information test also checks the timestamp and sleeping guest state.

Register the strengthened public #360 user/group fixture on Docker as well
as Asagiri. Preserve the existing unknown-numeric-user primary group checks.

Native dev.99 reproduced missing SystemTime before any resource mutation.
Local workspace: 721 top-level Rust tests passed, four ignored; Linux ARM64
init test executables compile; shell checks and clock-parser controls pass.
Full daemon-time/Compose behavior still requires hosted and release validation.

Upstream-Issue: libracoder/kiri#346
Related-PR: libracoder/kiri#360
Compose-Source: https://github.com/docker/compose/blob/v5.7.1/internal/logstream/monitor.go
Signed-off-by: Andre Kurait <akurait@amazon.com>
docker run --user 1000:1000 gave a process with no supplementary groups;
Docker gives it 1000, the user's group. The same for a named user
(--user nobody: none on Kiri, 65534 on Docker) and for docker exec --user.
Docker starts the list with the user's gid (usr.AdditionalGids in moby's
getUser, daemon/oci_linux.go), then adds the /etc/group memberships and
--group-add. Kiri now does the same in supplementary_groups. The list is
sorted and deduplicated, so root shows 0 once where Docker lists it twice.

Access through the primary group already worked; what differed is
getgroups(), id, and Groups: in /proc/self/status.

Left alone: for a numeric user that /etc/passwd doesn't have (--user 1000
in alpine), Docker uses gid 0 and Kiri uses the uid as the gid
(resolve_user). That choice looks deliberate, so this change keeps it.

Tests:
- unit: the_users_own_group_is_a_supplementary_group_as_with_docker
  (groups_from takes the group file's text, no container needed)
- e2e: user-groups-primary (-u 1000:1000 --group-add 2000 gives 1000 2000)
  and user-groups-exec (exec -u nobody gives 65534); both fail on 0.2.1
  and pass with this change

Tested: cargo test -p kiri-init in rust:1-alpine (aarch64, Rust 1.100.0):
71 passed, 1 failed; main gives 70 passed, 1 failed (the same
layers::tests::whiteout_becomes_char_device, unprivileged container).
cargo clippy and cargo fmt --check: same findings as main, none new.
Then cargo xtask host + guest on Apple silicon, macOS 27.0.1, compared
with Docker Engine 29.8.2 (OrbStack). Run only on Apple silicon so far;
kiri-init is the runtime on all three platforms.
@cloudlabworks
cloudlabworks force-pushed the user-primary-gid-groups branch from 996fbc5 to 4a41280 Compare November 16, 2026 22:49
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.

1 participant