Skip to content

parent: exclude the own UID/GID from the subid ranges - #623

Merged
AkihiroSuda merged 3 commits into
rootless-containers:masterfrom
AbhinavMir:subid-range-containing-own-id
Sep 19, 2026
Merged

AkihiroSuda merged 3 commits into
rootless-containers:masterfrom
AbhinavMir:subid-range-containing-own-id

Conversation

@AbhinavMir

Copy link
Copy Markdown
Contributor

/etc/subuid and /etc/subgid can contain a range that covers the user's own
ID, e.g. `dog:1001:1` for the user `dog` with the UID 1001. The own ID is
already mapped to the ID 0 in the user namespace, so such a range makes
newuidmap map the same host ID twice. The kernel rejects an overlapping
map, and newuidmap fails with "write to uid_map failed: Invalid argument".

Remove the own ID from the ranges before the map is built. A range that
contains the own ID in the middle is split into two ranges, so no host ID
is lost.

Signed-off-by: abhinavmir <atg271@gmail.com>
The own UID/GID is silently removed from the subid ranges. An admin cannot
see why the container gets fewer sub-IDs than /etc/subuid grants.

Print a warning for each range that contains the own ID. The warning names
the file, the range, and the own ID, and it says that the own ID is already
mapped in the user namespace.

The warning appears once per range. `withoutSelfID` stays free of logging:
it returns the removed ranges, and the caller prints them.

Signed-off-by: abhinavmir <atg271@gmail.com>
@AkihiroSuda

Copy link
Copy Markdown
Member

How to test?

@AbhinavMir

Copy link
Copy Markdown
Contributor Author

End-to-end on Linux, as a user whose subuid range contains their own UID:

echo "$USER:$(id -u):1"      | sudo tee    /etc/subuid /etc/subgid
echo "$USER:100000:65536"    | sudo tee -a /etc/subuid /etc/subgid
rootlesskit true

Before: newuidmap: write to uid_map failed: Invalid argument.
After: exits 0 with a warning naming the offending range.

@AkihiroSuda AkihiroSuda added this to the v3.2.0 milestone Sep 3, 2026
Comment thread pkg/parent/parent.go Outdated
The warning messsage was incorrectly assuming SubidSourceStatic mode

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>

@AkihiroSuda AkihiroSuda left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda
AkihiroSuda merged commit 86684d6 into rootless-containers:master Sep 19, 2026
16 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants