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 the /kaniko directory permissions in container #2009

Merged

Conversation

claudex
Copy link
Contributor

@claudex claudex commented Mar 22, 2022

Fixes #1363

Description

Create /kaniko directory with world permission to allow the creation of
sub directories by any user when the executor is run as non root. This
can lower the security but shouldn't have any impact in a container.

The tar unpack is the only way I found to have a directory with specific
permission as the image is created from "scratch" which doesn't have any
tool to change the permission otherwise.

Submitter Checklist

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

  • Includes unit tests
    The container build will fail if there is an issue with the change
  • Adds integration tests if needed.
    The container build will fail if there is an issue with the change

See the contribution guide for more details.

Reviewer Notes

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

Release Notes

Examples of user facing changes:
- kaniko executor container can run as non root

Create /kaniko directory with world permission to allow the creation of
sub directories by any user when the executor is run as non root. This
can lower the security but shouldn't have any impact in a container.

The tar unpack is the only way I found to have a directory with specific
permission as the image is created from "scratch" which doesn't have any
tool to change the permission otherwise.

Fixes GoogleContainerTools#1363
@imjasonh
Copy link
Collaborator

How is kaniko.tar generated? I'm not comfortable having such an opaque file in this repo that we can't regenerate, or generate on-demand.

As an alternative to unpacking kaniko.tar into the FROM scratch image, can we set its ownership bits in previous build stages and copy them over in the final stage?

Also, ideally this kind of change would include some kind of test, or even manual testing instructions, to demonstrate that it works as intended. An automated test is ideal because we can run it on future changes to ensure they don't undo this behavior.

@claudex
Copy link
Contributor Author

claudex commented Mar 22, 2022

How is kaniko.tar generated? I'm not comfortable having such an opaque file in this repo that we can't regenerate, or generate on-demand.

Yes, sorry, I forgot to add it, it's just an tar from an empty directory. I will add a new commit with the file creation in the makefile.

As an alternative to unpacking kaniko.tar into the FROM scratch image, can we set its ownership bits in previous build stages and copy them over in the final stage?

I'm not an expert in docker, but I've tested it and it doesn't keep the permission. Maybe I've done it wrong.

Also, ideally this kind of change would include some kind of test, or even manual testing instructions, to demonstrate that it works as intended. An automated test is ideal because we can run it on future changes to ensure they don't undo this behavior.

I didn't find any automated test with the image creation to inspire me :) Do you have a link to an example where I can change the user ?

Use the Makefile to create the tar file use to create kaniko directory
in scratch container. This avoid having a "blackbox" binary file with
the empty directory.
@Carus11
Copy link

Carus11 commented Jun 27, 2022

For what its worth, I built an image with these changes and can confirm it fixed the specific issue about /kaniko permissions so that one wont see that error message when trying to use a different user when running the container.

@imjasonh imjasonh merged commit 3fd30ea into GoogleContainerTools:main Jun 27, 2022
@hown3d
Copy link
Contributor

hown3d commented Jun 28, 2022

I'm not really happy about this change since it broke every build outside of make:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants