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

Error: error resolving dockerfile path: copying dockerfile: creating file: open /kaniko/Dockerfile: permission denied #1363

Closed
yashcodecollab opened this issue Jul 29, 2020 · 13 comments · Fixed by #2009
Labels
kind/question Further information is requested

Comments

@yashcodecollab
Copy link

Hi I am still running into the same issue. Is there a resolution for this @tejal29

Error: error resolving dockerfile path: copying dockerfile: creating file: open /kaniko/Dockerfile: permission denied

@yashcodecollab yashcodecollab changed the title Hi I am still running into the same issue. Is there a resolution for this @tejal29 Error: error resolving dockerfile path: copying dockerfile: creating file: open /kaniko/Dockerfile: permission denied Error: error resolving dockerfile path: copying dockerfile: creating file: open /kaniko/Dockerfile: permission denied Jul 29, 2020
@tejal29
Copy link
Member

tejal29 commented Aug 12, 2020

@yashcodecollab please specify --context=pathMounted/ and -f dockerfile as path relative to pathMounted

Does that make sense?
Please see examples in README

@tejal29 tejal29 added the kind/question Further information is requested label Aug 12, 2020
@TBBle
Copy link

TBBle commented Aug 13, 2020

Edit: Moved my bug to #1381.

I suspect the problem for @yashcodecollab is that the /kaniko directory in the container is not writeable, perhaps kaniko has been mounted with read-only root set?

@adhikasp
Copy link

adhikasp commented Dec 3, 2020

I got this exact same error

Error: error resolving dockerfile path: copying dockerfile: creating file: open /kaniko/Dockerfile: permission denied

The problem in my case was I am trying to run the kaniko container under non-root user. After changing back to root, it run fine.

@ttfreeman
Copy link

@adhikasp Kaniko is supposed to work with non-root user.

@TBBle
Copy link

TBBle commented Apr 28, 2021

Internally, Kaniko copies the given Dockerfile to /kaniko/Dockerfile, so it can only work with a non-root user, if the non-root user has permission to write to /kaniko.

So either the container in question was faulty and /kaniko is supposed to be world-writeable, or the kaniko container needs to be run as either root, or a specific UID that owns /kaniko.

@lvarin
Copy link

lvarin commented Jan 25, 2022

I am suffering from this problem as well. The only user/UID than can write in /kaniko and run kaniko is root/0:

/kaniko $ ls -alh
total 110M   
drwxr-xr-x    1 0        0           4.0K Apr 26  2021 .
drwxr-xr-x    1 0        0           4.0K Jan 25 11:42 ..

And this folder is a constant (If I read the code correctly:):

https://github.com/GoogleContainerTools/kaniko/blob/main/pkg/constants/constants.go#L31

@luidoc
Copy link

luidoc commented Feb 11, 2022

Hi I am still running into the same issue. Is there a resolution for this, running the kaniko container under non-root user.
../executor --dockerfile=Dockerfile --context=/kaniko/buildcontext --no-push
Error: error resolving dockerfile path: copying dockerfile: creating file: open /kaniko/Dockerfile: permission denied

opts.DockerfilePath = constants.DockerfilePath
DockerfilePath = "/kaniko/Dockerfile"

@imjasonh
Copy link
Collaborator

Basically, kaniko expects to run as root inside the container. There are a bunch of things that don't work as expected if that's not satisfied, including apparently this.

@very-doge-wow
Copy link

So what exactly is supposed to be the solution to this problem? As far as my understanding goes, kaniko was supposed to work without root privileges. I believe making the constant mentioned by @lvarin configurable would solve the issue, as users then could configure their own paths which ARE writable by non-root users.

@imjasonh
Copy link
Collaborator

imjasonh commented Mar 9, 2022

So what exactly is supposed to be the solution to this problem?

The solution to the problem is for someone to investigate this issue and fix it. It could even be you! 😄

This has also been requested in #1945, and as far as I know it should be possible. My main concern would be testing this path well end-to-end, since I wouldn't be surprised if there are lots of corners of the code that subtly assume /kaniko is the reserved directory.

@TBBle
Copy link

TBBle commented Mar 9, 2022

I don't think #1945 solves this issue, because even if you can move the KanikoDir, it'll still be owned by root in the published container image, per https://github.com/GoogleContainerTools/kaniko/blob/main/deploy/Dockerfile.

Although the README says that Kaniko (the binary) can run as a non-root user if you don't need it to do 'root-only' things, the same document strongly recommends to use Kaniko via the published container image, which does require running kaniko as root just to process the Dockerfile.

A solution for this ticket might be to simply change the Dockerfiles so that /kaniko is writable by all users.

@imjasonh
Copy link
Collaborator

imjasonh commented Mar 9, 2022

A solution for this ticket might be to simply change the Dockerfiles so that /kaniko is writable by all users.

That seems like an easy and worthwhile change. If someone sends me a PR I'll approve it 👍

claudex pushed a commit to claudex/kaniko that referenced this issue Mar 22, 2022
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
claudex added a commit to claudex/kaniko that referenced this issue Mar 22, 2022
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
@vvatlin
Copy link

vvatlin commented Jun 24, 2022

Still have the same issue

imjasonh pushed a commit that referenced this issue Jun 27, 2022
* Fix the /kaniko directory permissions in container

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 #1363

* Avoid blackbox tar file creation

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question Further information is requested
Projects
None yet
10 participants