Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple uid/gid mappings [1/2] #10307

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

henry118
Copy link
Member

@henry118 henry118 commented Jun 6, 2024

Enhance user namespace implementation to support multi-entry uid/gid mappings.

This is 1st patch (out of 2) that supports multiple entries of uid/gid configurations. This patch focuses on the "slow" path that requires chown on every file in the root FS. uidmapped mounts implementation will be covered in a separate PR.

This implementation has changes in the following area:

  1. Ported the IdentityMapping implementation from idtools package in Moby.
  2. Added a few container opt funcs to take multiple uid/gid mappings.
  3. Allowing multiple --uidmap, --gidmap options in ctr run command.

An sample command to run a container with remapped foo user:

ctr run --uidmap 0:100000:1000 --uidmap 1000:201795:1 --uidmap 1001:10000000:64535 --gidmap 0:100000:100 --gidmap 100:1001:1 --gidmap 101:10000000:65435 --user foo <image> test bash

I hope the implementation makes sense and I'm looking forward to your feedback :)

@henry118 henry118 changed the title update ctr run to support multiple uid/gid mappings Support multiple uid/gid mappings Jun 6, 2024
cmd/ctr/commands/run/run_unix.go Fixed Show fixed Hide fixed
pkg/idtools/idtools.go Fixed Show fixed Hide fixed
pkg/idtools/idtools.go Fixed Show fixed Hide fixed
pkg/idtools/idtools.go Fixed Show fixed Hide fixed
pkg/idtools/idtools.go Fixed Show fixed Hide fixed
@henry118 henry118 changed the title Support multiple uid/gid mappings Support multiple uid/gid mappings [1/2] Jun 6, 2024
@estesp
Copy link
Member

estesp commented Jun 28, 2024

/test pull-containerd-node-e2e

@estesp estesp added this to the 2.0 milestone Jun 28, 2024
@estesp
Copy link
Member

estesp commented Jun 28, 2024

I'm adding to 2.0 milestone; @containerd/maintainers let me know if anyone thinks it should not be in 2.0

@@ -45,11 +47,11 @@ import (
)

var platformRunFlags = []cli.Flag{
&cli.StringFlag{
&cli.StringSliceFlag{
Name: "uidmap",
Usage: "Run inside a user namespace with the specified UID mapping range; specified with the format `container-uid:host-uid:length`",
Copy link
Member

Choose a reason for hiding this comment

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

I think the usage string (for this and gidmap) needs to reflect that it is now a slice/list of maps; at least the first clause should end with mapping range(s); could also add at the end a new clause: ", separate multiple mappings with a comma"

Copy link
Member Author

Choose a reason for hiding this comment

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

After this change, the help message for this option becomes the following.

--uidmap container-uid:host-uid:length [ --uidmap container-uid:host-uid:length ]  Run inside a user namespace with the specified UID mapping range; specified with the format container-uid:host-uid:length

I think the additional [] will indicate the option is a slice. But I think updating the "mapping range" to "mapping ranges" was a good call out. I will make the update in the next revision.

Signed-off-by: Henry Wang <henwang@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants