Skip to content

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

Open
AbhinavMir wants to merge 2 commits into
rootless-containers:masterfrom
AbhinavMir:subid-range-containing-own-id
Open

parent: exclude the own UID/GID from the subid ranges#623
AbhinavMir wants to merge 2 commits into
rootless-containers:masterfrom
AbhinavMir:subid-range-containing-own-id

Conversation

@AbhinavMir

Copy link
Copy Markdown

/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
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.

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