Skip to content

Comments

Partial refactor of UID/GID usage to a new struct#33362

Merged
tonistiigi merged 7 commits intomoby:masterfrom
dnephin:refactor-uid-maps
Jun 7, 2017
Merged

Partial refactor of UID/GID usage to a new struct#33362
tonistiigi merged 7 commits intomoby:masterfrom
dnephin:refactor-uid-maps

Conversation

@dnephin
Copy link
Member

@dnephin dnephin commented May 23, 2017

Related to #32989 and #32904

Improve the interfaces exposed by idtools with some new structs.

In order to move CopyOnBuild into the builder we need access to id mappings. Instead of passing around slices, expose a struct with the necessary behaviour.

This PR converts all uses of idtools, except for graphdrivers.

@dnephin dnephin changed the title Partial refactor of UID/GID usage to use a unified struct. Partial refactor of UID/GID usage to a new struct May 23, 2017
@dnephin dnephin force-pushed the refactor-uid-maps branch 2 times, most recently from cbc3ddf to adf35c7 Compare May 24, 2017 15:32
@dnephin dnephin force-pushed the refactor-uid-maps branch 2 times, most recently from ae1dce3 to ae41030 Compare May 24, 2017 18:50
@dnephin dnephin requested review from tiborvass and vdemeester May 25, 2017 03:56
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to ignore the error here (and in lots of other calls to RootPair) ?

Copy link
Member Author

@dnephin dnephin May 25, 2017

Choose a reason for hiding this comment

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

Mainly just because that's what the old code did: https://github.com/moby/moby/pull/33362/files#diff-1a1f3e7ad9b1d7584e2d3e7d0c4c3db9L969

According to the comment the default values are correct if there is no remapping.

I'm not sure what error is possible here. I'll take another look. Maybe it doesn't make sense to return an error at all.

Copy link
Member

Choose a reason for hiding this comment

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

fair enough 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

The only way for this function to return an error is if the idMaps are non-nil, and they don't have an entry for the root user. I don't know if there is any case where that can happen.

Maybe it would be better to error out in the NewIDMappings() during startup. Instead of checking the same error condition every time it's used. The mapping never changes so it seems like it would make more sense that way.

Copy link
Member

Choose a reason for hiding this comment

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

yep probably. cc @estesp 👼

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at the setup code again I notice this feature is not support on windows, so we don't have to worry about that case.

Remapping to the root user is already checked in NewIDMappings(), so I'm going to remove the error on RootPair().

@dnephin dnephin force-pushed the refactor-uid-maps branch 2 times, most recently from 3d8e034 to 80152ac Compare May 31, 2017 21:56
@estesp
Copy link
Contributor

estesp commented Jun 1, 2017

This looks reasonable to me. Just tried to use the labels to get a single "userns" build for validating the changes against the integration tests, but not sure if Gordon is doing anything :)

@tonistiigi
Copy link
Member

LGTM

I made a config change to allow userns rebuilding but that service needs to be redeployed before it becomes available.

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🐯

@estesp
Copy link
Contributor

estesp commented Jun 2, 2017

So can someone manually force a userns Jenkins run just for completeness?

@mlaventure
Copy link
Contributor

I manually started a job for this PR with userns enabled (https://jenkins.dockerproject.org/job/Docker-PRs-userns/14852). There's one failure with plugins:

18:54:52 ----------------------------------------------------------------------
18:54:52 FAIL: docker_cli_plugins_test.go:429: DockerSuite.TestPluginUpgrade
18:54:52 
18:54:52 docker_cli_plugins_test.go:436:
18:54:52     dockerCmd(c, "run", "--rm", "-v", "bananas:/apple", "busybox", "sh", "-c", "touch /apple/core")
18:54:52 /go/src/github.com/docker/docker/pkg/testutil/cmd/command.go:64:
18:54:52     t.Fatalf("at %s:%d - %s", filepath.Base(file), line, err.Error())
18:54:52 ... Error: at cli.go:48 - 
18:54:52 Command:  /usr/local/bin/docker run --rm -v bananas:/apple busybox sh -c touch /apple/core
18:54:52 ExitCode: 126
18:54:52 Error:    exit status 126
18:54:52 Stdout:   
18:54:52 Stderr:   container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/var/lib/docker/427680.427680/plugins/f57dfa7dac0a7dbf8b6be302b1e4ed3af4df1794a9e20f519fc129846d9c0e84/rootfs/mnt/volumes/bananas/_data\\\" to rootfs \\\"/var/lib/docker/427680.427680/vfs/dir/e9aabbbfec67f77b0d87dc843a70ccd6c0c5647bc1d4a390a3fcff0cc0b94265\\\" at \\\"/apple\\\" caused \\\"stat /var/lib/docker/427680.427680/plugins/f57dfa7dac0a7dbf8b6be302b1e4ed3af4df1794a9e20f519fc129846d9c0e84/rootfs/mnt/volumes/bananas/_data: permission denied\\\"\""
18:54:52 /usr/local/bin/docker: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/var/lib/docker/427680.427680/plugins/f57dfa7dac0a7dbf8b6be302b1e4ed3af4df1794a9e20f519fc129846d9c0e84/rootfs/mnt/volumes/bananas/_data\\\" to rootfs \\\"/var/lib/docker/427680.427680/vfs/dir/e9aabbbfec67f77b0d87dc843a70ccd6c0c5647bc1d4a390a3fcff0cc0b94265\\\" at \\\"/apple\\\" caused \\\"stat /var/lib/docker/427680.427680/plugins/f57dfa7dac0a7dbf8b6be302b1e4ed3af4df1794a9e20f519fc129846d9c0e84/rootfs/mnt/volumes/bananas/_data: permission denied\\\"\"".
18:54:52 
18:54:52 
18:54:52 Failures:
18:54:52 ExitCode was 126 expected 0
18:54:52 Expected no error
18:54:52 
18:54:52 
18:54:52 
18:54:52 ----------------------------------------------------------------------

@dnephin
Copy link
Member Author

dnephin commented Jun 5, 2017

Thanks @mlaventure . I tried running that test (locally) with master and it fails the same way. I'm doing a full run on jenkins here: https://jenkins.dockerproject.org/job/Docker-PRs-userns/14854/console to show the failure. It looks like Tonis ran the userns-master build, but it skipped the test with "docker_cli_plugins_test.go:429: DockerSuite.TestPluginUpgrade (unmatched requirement Network)".

It looks like the last run of userns was September 2016, which is before this test was added. I think this test may never have worked with userns.

@estesp
Copy link
Contributor

estesp commented Jun 5, 2017

Yes, this test won't be successful on userns because of an external volume that won't be mapped to have write perms. from the remapped UID running in the container. For most tests like this, we skip for userns rather than complicate the test setup. Thanks for executing a test run @mlaventure

@dnephin
Copy link
Member Author

dnephin commented Jun 5, 2017

Moved to code-review. Tests are green

@vieux
Copy link
Contributor

vieux commented Jun 6, 2017

LGTM ping @tiborvass

dnephin added 7 commits June 7, 2017 11:44
The test was failing because TarOptions was using a non-pointer for
ChownOpts, which meant the check for nil was never true, and
createTarFile was never using the hdr.UID/GID

Signed-off-by: Daniel Nephin <[email protected]>
There is no case which would resolve in this error. The root user always exists, and if the id maps are empty, the default value of 0 is correct.

Signed-off-by: Daniel Nephin <[email protected]>
@dnephin dnephin force-pushed the refactor-uid-maps branch from 80152ac to 93fbdb6 Compare June 7, 2017 15:45
@tonistiigi tonistiigi merged commit 34536c4 into moby:master Jun 7, 2017
@GordonTheTurtle GordonTheTurtle added this to the 17.06.0 milestone Jun 7, 2017
@dnephin dnephin deleted the refactor-uid-maps branch June 8, 2017 19:04
corhere added a commit to corhere/moby that referenced this pull request Mar 11, 2022
Existing code which uses []IDMap relies on zero-valued fields to be
valid, empty mappings. So if we want to successfully finish the
refactoring started in moby#33362, their replacement therefore also needs to
have a useful zero value which represents an empty mapping. Ideally this
would be accomplished by changing IdentityMapping to be a pass-by-value
type so that there would be no nil pointers to worry about, but
*IdentityMapping values are already used extensively within BuildKit so
we cannot do that without also refactoring BuildKit in lockstep. We can,
however, do the next best thing: modify all the associated functions so
that they are well-behaved when called on a nil pointer.

Signed-off-by: Cory Snider <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants