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: getUIDandGID is able to resolve non-existing users and groups #2106

Merged
merged 24 commits into from
Jul 12, 2022

Conversation

hown3d
Copy link
Contributor

@hown3d hown3d commented May 23, 2022

Signed-off-by: Höhl, Lukas lukas.hoehl@accso.de

Fixes #1456

Description
A common pattern in dockerfiles is to provide a plain uid and gid number, which doesn't neccesarily exist inside the os.

Currently, an error accurs, specifying, that the user and group doesn't exist.
This PR changes the logic to lookup the users and groups only if the chown command can't be parsed into a valid uint32.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
  • Adds integration tests if needed.

Reviewer Notes

  • The code flow looks good.
  • Unit tests and or integration tests added.

Release Notes

chown flag in Dockerfile COPY statement can specify non-existing user/group

A common pattern in dockerfiles is to provide a plain uid and gid number, which doesn't neccesarily exist inside the os.

Signed-off-by: Höhl, Lukas <lukas.hoehl@accso.de>
Copy link
Collaborator

@imjasonh imjasonh left a comment

Choose a reason for hiding this comment

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

In this case I'd love to have an integration test Dockerfile that chowns to a non-existent user, then checks later that it's owned by that user, even though that user doesn't exist. Do you think that's something we could add to this PR?

Otherwise, this looks great, and thank you so much for working on this! 👍

pkg/commands/user.go Show resolved Hide resolved
pkg/util/command_util.go Show resolved Hide resolved
pkg/util/command_util.go Show resolved Hide resolved
Höhl, Lukas added 3 commits May 23, 2022 16:46
Signed-off-by: Höhl, Lukas <lukas.hoehl@accso.de>
Signed-off-by: Höhl, Lukas <lukas.hoehl@accso.de>
Signed-off-by: Höhl, Lukas <lukas.hoehl@accso.de>
@hown3d
Copy link
Contributor Author

hown3d commented May 23, 2022

In this case I'd love to have an integration test Dockerfile that chowns to a non-existent user, then checks later that it's owned by that user, even though that user doesn't exist. Do you think that's something we could add to this PR?

Otherwise, this looks great, and thank you so much for working on this! 👍

I added a Dockerfile, is there something I need to configure inside the integration tests themself?

Signed-off-by: Höhl, Lukas <lukas.hoehl@accso.de>
pkg/util/command_util.go Outdated Show resolved Hide resolved
Signed-off-by: Höhl, Lukas <lukas.hoehl@accso.de>
pkg/util/command_util.go Outdated Show resolved Hide resolved
@hown3d
Copy link
Contributor Author

hown3d commented May 27, 2022

@imjasonh This should be ready to go now, added some more tests for other functions involving the user retrieval process.

@imjasonh imjasonh mentioned this pull request Jun 1, 2022
github runner had the exact uid that i was testing on, so the groups were not empty

Signed-off-by: Höhl, Lukas <lukas.hoehl@accso.de>
@imjasonh imjasonh mentioned this pull request Jun 7, 2022
Höhl, Lukas added 2 commits June 7, 2022 22:21
Signed-off-by: Höhl, Lukas <lukas.hoehl@accso.de>
Signed-off-by: Höhl, Lukas <lukas.hoehl@accso.de>
@hown3d
Copy link
Contributor Author

hown3d commented Jun 13, 2022

I'm currently stuck regarding an issue building this dockerfile
All action in kaniko are executed as root, right? How does it come, that opening a file (as root), which got created in a previous stage, can be denied by the kernel? File permissions on the created file are 420. Isn’t root able to open all files, regardless of permissions and ownership?
I’m running into an access denied error from os.Create like https://github.com/GoogleContainerTools/kaniko/runs/6782183403?check_suite_focus=true#step:6:118 all the time, which is thrown here:

dest, err := os.Create(path)

Maybe a second pair of eyes can spot the mistake, since I don't know why this error appears.

The error can't be reproduced on my WSL workstation, but appears in the github actions and mac running the integration tests.

Höhl, Lukas added 4 commits June 24, 2022 18:41
Signed-off-by: Höhl, Lukas <lukas.hoehl@accso.de>
Signed-off-by: Höhl, Lukas <lukas.hoehl@accso.de>
Signed-off-by: Höhl, Lukas <lukas.hoehl@accso.de>
Höhl, Lukas added 2 commits July 12, 2022 14:33
Signed-off-by: Höhl, Lukas <lukas.hoehl@accso.de>
@imjasonh imjasonh merged commit aad03dc into GoogleContainerTools:main Jul 12, 2022
@msuperina
Copy link

@imjasonh Thank you for approving this MR. I am struggling to find info about which release this fix would land in, any chance you could advise ? I can see MR for #2117 but this fix is not highlighted there - I am possibly mistaken though...

@msuperina msuperina mentioned this pull request Jul 24, 2022
4 tasks
@gabyx
Copy link
Contributor

gabyx commented Jul 25, 2022

Great!

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.

COPY with --chown command should not require user or group IDs to exist
4 participants