-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Fix copy chown settings to not default to real root #20446
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// +build !windows | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/docker/docker/pkg/integration/checker" | ||
"github.com/docker/docker/pkg/system" | ||
"github.com/go-check/check" | ||
) | ||
|
||
// Check ownership is root, both in non-userns and userns enabled modes | ||
func (s *DockerSuite) TestCpCheckDestOwnership(c *check.C) { | ||
testRequires(c, DaemonIsLinux, SameHostDaemon) | ||
tmpVolDir := getTestDir(c, "test-cp-tmpvol") | ||
containerID := makeTestContainer(c, | ||
testContainerOptions{volumes: []string{fmt.Sprintf("%s:/tmpvol", tmpVolDir)}}) | ||
|
||
tmpDir := getTestDir(c, "test-cp-to-check-ownership") | ||
defer os.RemoveAll(tmpDir) | ||
|
||
makeTestContentInDir(c, tmpDir) | ||
|
||
srcPath := cpPath(tmpDir, "file1") | ||
dstPath := containerCpPath(containerID, "/tmpvol", "file1") | ||
|
||
err := runDockerCp(c, srcPath, dstPath) | ||
c.Assert(err, checker.IsNil) | ||
|
||
stat, err := system.Stat(filepath.Join(tmpVolDir, "file1")) | ||
c.Assert(err, checker.IsNil) | ||
uid, gid, err := getRootUIDGID() | ||
c.Assert(err, checker.IsNil) | ||
c.Assert(stat.UID(), checker.Equals, uint32(uid), check.Commentf("Copied file not owned by container root UID")) | ||
c.Assert(stat.GID(), checker.Equals, uint32(gid), check.Commentf("Copied file not owned by container root GID")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use idtools.GetRootUIDGID here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, that would require that I have the mappings from within the daemon, but the tests can be run as a separate client (and in this case they are)--so the only option is to parse the output of what the server will tell me about itself.. which in this case is the fact we know the root dir of the daemon contains the root uid, gid info..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
TestDaemonUserNamespaceRootSetting is doing something similar and can be updated to use this new function.
Also, how is this testing against a userns enabled daemon, as mentioned in the function comment header?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True--absolutely!
Because one of our runs of
make test-integration-cli
in CI sets theDOCKER_REMAP_ROOT
setting and runs all tests against a daemon with userns enabled; appropriately named userns :)