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

Fix #9 - add support for --chown flag to COPY #250

Closed
wants to merge 14 commits into from

Conversation

pmcq
Copy link

@pmcq pmcq commented Jul 24, 2018

#9

To test, I've built an image locally and used it to run dockerfiles with COPY --chown flag succesfully. All existing unit tests pass, however I don't see any existing tests on util.CopyDir/CopyFile or CopySymlink that need modification.

Since the user running the testcases isn't going to be a root user, it wouldn't be allowed to chown a file to someone else, so any testcases I wrote around the chown logic was failing for permission denied reasons.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@priyawadhwa
Copy link
Contributor

Hey @pmcq , looks like you need to sign the CLA and fix some linting errors for travis to pass.

@pmcq
Copy link
Author

pmcq commented Jul 25, 2018

Hi, sorry, I'm currently working with my company internally to get the corporate CLA signed but I think it could be a couple of days for this to get set up so I might have to put this on hold until that goes through. I can close this for now and re-open when that's finished or whatever you would prefer. Thanks.

@priyawadhwa
Copy link
Contributor

No rush, feel free to keep it open if that's easier.

@googlebot
Copy link

CLAs look good, thanks!

pmcq added 2 commits August 3, 2018 16:23
…hared between USER and COPY commands. Update COPY commands to chown files/directories/symlinks appropriately
@pmcq
Copy link
Author

pmcq commented Aug 6, 2018

Hi I believe the CLAs are all set and I fixed up some merge conflicts on my end

@sharifelgamal
Copy link
Contributor

All of our integration tests are failing with an invalid userid error:

time="2018-08-06T17:58:48Z" level=info msg="Unpacking layer: 0" time="2018-08-06T17:58:48Z" level=info msg="Not adding /dev because it is whitelisted" time="2018-08-06T17:58:48Z" level=info msg="Not adding /etc/hostname because it is whitelisted" time="2018-08-06T17:58:48Z" level=info msg="Not adding /etc/hosts because it is whitelisted" time="2018-08-06T17:58:48Z" level=info msg="Not adding /proc because it is whitelisted" time="2018-08-06T17:58:48Z" level=info msg="Not adding /sys because it is whitelisted" time="2018-08-06T17:58:48Z" level=info msg="Not adding /var/run because it is whitelisted" time="2018-08-06T17:58:48Z" level=info msg="Taking snapshot of full filesystem..." time="2018-08-06T17:58:49Z" level=info msg="cmd: copy [context/foo]" time="2018-08-06T17:58:49Z" level=info msg="dest: foo" time="2018-08-06T17:58:49Z" level=error msg="user: invalid userid "

@priyawadhwa
Copy link
Contributor

You can find instructions for running integration tests locally here!

@pmcq
Copy link
Author

pmcq commented Aug 7, 2018

I don't have a GCP account but can start the process of setting that stuff up for integration tests then. I have run the normal unit tests, and built some images locally.

@priyawadhwa
Copy link
Contributor

@pmcq thanks! let me know if you run into any issues

@pmcq
Copy link
Author

pmcq commented Aug 16, 2018

I've fixed up the code a little so that the images are now being built correctly but I can't get the integration tests to pass locally. At the end of the build I keep getting a Failed to push message and a Get https://gcr.io/v2/token?scope.... exit status 1. I am able to manually docker push the image to my gcr.io registry, but I can't seem to get kaniko to pick up the auth token correctly in the integration tests. Any advice on this?

@dlorenc
Copy link
Contributor

dlorenc commented Aug 23, 2018

Is this ready to merge?

@pmcq
Copy link
Author

pmcq commented Aug 31, 2018

I just performed another merge from master to fix some merge conflicts, all tests are still passing.

@oleh-ozimok
Copy link

Any news about this feature?

@24el
Copy link

24el commented Nov 15, 2018

Very useful feature

@bobcatfish
Copy link
Contributor

Hey @pmcq ! We'd like to give this another review, looks like there's a conflict that needs to be updated? Let us know when we should take a look again! (or if you want us to resolve the conflicts and get the PR merged, that's fine too!)

@naliferov
Copy link

Wait for this feature!

@pmcq
Copy link
Author

pmcq commented Nov 19, 2018

I'm taking a look at addressing the merge conflict and will try to re-push before I go on vacation this week.

Copy link
Contributor

@priyawadhwa priyawadhwa left a comment

Choose a reason for hiding this comment

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

Thanks for rebasing so quickly! I left a few comments.

return "", "", err
}

uidStr, gidStr, err := GetUserFromUsername(userStr, groupStr)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you can return GetUserFromUsername(userStr, groupStr) here

// It returns a list of files it copied over
func CopyDir(src, dest string) ([]string, error) {
func CopyDir(src string, dest string, chownUID int, chownGid int) ([]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this can be simplified to (src, dest string, uid, gid int)

return nil, err
}
} else if fi.Mode()&os.ModeSymlink != 0 {
// If file is a symlink, we want to create the same relative symlink
if err := CopySymlink(fullPath, destPath); err != nil {
if err := CopySymlink(fullPath, destPath, chownUID, chownGid); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

should these be uid and gid instead of chownUID and chownGid? I think with that change determineChownUIDGid won't need to be called again in CopySymlink

Copy link
Author

Choose a reason for hiding this comment

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

My thought here was since CopySymlink is exported it could be called in other places that didn't have the resolved uid/gid (or to allow callers to those functions to specify "keep uid the same", e.g. https://github.com/GoogleContainerTools/kaniko/pull/250/files#diff-a29f0f6c0a35589007a1c4e592f5c189R166) and that it would be less error-prone for callers if determineChownUIDGid was called within CopySymlink/CopyFile. I agree that expectation could be changed and I can change this if you'd like.

Copy link
Author

Choose a reason for hiding this comment

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

Hi @priyawadhwa - what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense -- we can keep the determineChownUIDGid in both places, but let's still pass in uid and gid in this function since it's a bit cleaner

Copy link
Author

Choose a reason for hiding this comment

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

okay I can do that but it would have to be int(uid) and int(gid) (since those values are uint32s but the other functions expect signed ints which determineChownUIDGid returns) - I wasn't sure if the type casting to signed was frowned upon or not.

return nil, err
}
} else {
// ... Else, we want to copy over a file
if err := CopyFile(fullPath, destPath); err != nil {
if err := CopyFile(fullPath, destPath, chownUID, chownGid); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above, should these be uid and gid?

Copy link
Contributor

@priyawadhwa priyawadhwa left a comment

Choose a reason for hiding this comment

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

This is looking really good! Could you just add to our copy integration test Dockerfile so that we can test this change?

return nil, err
}
} else if fi.Mode()&os.ModeSymlink != 0 {
// If file is a symlink, we want to create the same relative symlink
if err := CopySymlink(fullPath, destPath); err != nil {
if err := CopySymlink(fullPath, destPath, chownUID, chownGid); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense -- we can keep the determineChownUIDGid in both places, but let's still pass in uid and gid in this function since it's a bit cleaner

// If the given uid/gid are negative, returns the uid/gid from the
// file info.
// Otherwise returns the given uid/gid
func determineChownUIDGid(fileInfo os.FileInfo, chownUID, chownGid int) (uint32, uint32) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: let's call this determineChownUidGid

Copy link
Author

Choose a reason for hiding this comment

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

the linter actually raised errors when using uid or Uid here - https://travis-ci.org/GoogleContainerTools/kaniko/builds/457513881 I forgot to also look at renaming Gid to GID (which I guess it didn't check against)

// for the corresponding user as a string, replacing any build arguments
// and environment variables. Group is not required to be specified, and
// if left off, gid will be empty
func GetUIDGidFromUserString(commandUserStr string, replacementEnvs []string) (string, string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: getUidGidFromUserString

@pmcq
Copy link
Author

pmcq commented Dec 20, 2018

I actually don't think I will have any time soon to get this PR ready for approval - I wasn't able to get integration tests running (always get some auth issues with gcr) and will be busy with work/holidays. If someone else can pick this up that would be nice but I'll probably stick with my fork until then.

@pmcq pmcq closed this Dec 20, 2018
@Rowern
Copy link

Rowern commented Feb 12, 2019

@pmcq do you think I can pick up where you left ? Or would you consider continuing to work on this ?
(It would be a game changer for us as our images do need to copy with specific owner)

@bobcatfish
Copy link
Contributor

@pmcq do you think I can pick up where you left ? Or would you consider continuing to work on this ?
(It would be a game changer for us as our images do need to copy with specific owner)

@Rowern based on @pmcq 's last comment it sounds like you can go for it! :D 🎉

@pmcq
Copy link
Author

pmcq commented Feb 12, 2019

Correct I will not be working on this any longer. There are also some problems I ran into with kaniko not unpacking base layers and since it uses /etc/passwd to resolve usernames you have to use numeric user IDs instead of strings or make another tweak - #477 (comment).

@swistaczek
Copy link

@Rowern is there any new PR where I can watch progress for this fix? It's really important for my team :).

@huapox
Copy link

huapox commented May 13, 2019

How's it going?

@tequilarista tequilarista added the help wanted Looking for a volunteer! label Aug 2, 2019
@tejal29 tejal29 reopened this Sep 20, 2019
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@tejal29
Copy link
Contributor

tejal29 commented Sep 20, 2019

Since @pmcq hasnt signed CLA from patrick@algorithmia.io I am going to close this pr and create another one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Looking for a volunteer! size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.