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

Is there a way to run /kaniko/executor as non-root user inside container to build an image? #2146

Open
karthiravich opened this issue Jun 24, 2022 · 14 comments
Labels
area/container For all bugs related to the kaniko container area/security feat/non-root issue/root-user kind/enhancement New feature or request kind/feature-request kind/security needs-discussion Items which need more discussion before commitment ok-to-close? possible-dupe priority/p0 Highest priority. Break user flow. We are actively looking at delivering it. priority/p1 Basic need feature compatibility with docker build. we should be working on this next.

Comments

@karthiravich
Copy link

I am trying to run /kaniko/executor in corporate OKD cluster to build docker images as part of CI process using Jenkins. This is the first time we are trying to introduce kaniko in our OKD cluster .

The Jenkins agent workload runs as pod inside the OKD cluster and kaniko runs as a container within the pod.

I could see the kaniko file system is root owned. The current CI process in the org requires the runner pods to execute as non root in the OKD cluster.

Is there a way I can execute the /kaniko/executor as non-root user instead of root?

Kaniko image - gcr.io/kaniko-project/executor:v1.5.1-debug

PS: I tried to build the /kaniko/executor from source and tried adding full permissions (chmod -R 777) to /kaniko and /workspace directories in the Dockerfile and built the new image.

When tried to execute the /kaniko/executor command, got the below error.

Error: error resolving dockerfile path: copying dockerfile: chown /kaniko/Dockerfile: operation not permitted

Any suggestions to get this work?

@karthiravich
Copy link
Author

Just to add more info - Similar issue reported here - #2122

But the fix recommended to use runAsUser: 0 for securityContext would not work in my case. Would like to know if there is any other alternative to make it work?

@hown3d
Copy link
Contributor

hown3d commented Jun 24, 2022

Kaniko currently relies on being run as root. Rootless execution is currently not implemented since it would need executing inside user namespace and map uids/gids.

@karthiravich
Copy link
Author

@hown3d Thanks for the information. Do you know if that feature of running kaniko as non-root user is being considered and if it is planned for some release version?

@hown3d
Copy link
Contributor

hown3d commented Jun 28, 2022

I don't think that running as non-root is currently on the roadmap. If you really need rootless execution for builds of dockerfiles, I would use buildah.

@karthiravich
Copy link
Author

I tried executing the buildah inside OKD 3.11, but could not proceed with that option as well . That's why thought of using kaniko.

Kept getting the below error

Storing signatures DEBU[0003] Start untar layer ERRO[0003] Error while applying layer: ApplyLayer exit status 1 stdout: stderr: potentially insufficient UIDs or GIDs available in user namespace (requested 0:42 for /etc/gshadow): Check /etc/subuid and /etc/subgid: lchown /etc/gshadow: invalid argument DEBU[0003] Error pulling candidate docker-registry/ci/baseimage:latest: Error committing the finished image: error adding layer with blob "sha256:35807b77a593c1147d13dc926a91dcc3015616ff7307cc30442c5a8e07546283": ApplyLayer exit status 1 stdout: stderr: potentially insufficient UIDs or GIDs available in user namespace (requested 0:42 for /etc/gshadow): Check /etc/subuid and /etc/subgid: lchown /etc/gshadow: invalid argument error creating build container: Error committing the finished image: error adding layer with blob "sha256:35807b77a593c1147d13dc926a91dcc3015616ff7307cc30442c5a8e07546283": ApplyLayer exit status 1 stdout: stderr: potentially insufficient UIDs or GIDs available in user namespace (requested 0:42 for /etc/gshadow): Check /etc/subuid and /etc/subgid: lchown /etc/gshadow: invalid argument

@hown3d
Copy link
Contributor

hown3d commented Jun 28, 2022

Sounds alot like this issue: containers/buildah#4049

@karthiravich
Copy link
Author

Thanks for sharing . I will take a look at it and come back!

@karthiravich
Copy link
Author

Hello. Thank you for sharing the previous link related to buildah issue. I was able to build the latest buildah image from RH catalog, and used it inside the OKD cluster and it worked :).

@mpeaton-ng
Copy link

Neither buildah, nor executor will perform root user build operations for me on OCP without runAsUser:0. This is horseshit.

@mirekphd
Copy link

mirekphd commented Apr 22, 2023

It's enough to add --cap-drop=all to drop all capabilities in the official docker run example from here to reproduce the problem, causing an error when kaniko executor tries to copy the Dockerfile to a root-owned location inside the container:
Error: error resolving dockerfile path: copying dockerfile: chown /kaniko/Dockerfile: operation not permitted

But this issue was raised 4 years ago and tagged "wontfix" here: #681

@aaron-prindle aaron-prindle added priority/p0 Highest priority. Break user flow. We are actively looking at delivering it. priority/p1 Basic need feature compatibility with docker build. we should be working on this next. needs-discussion Items which need more discussion before commitment possible-dupe ok-to-close? feat/non-root area/container For all bugs related to the kaniko container kind/feature-request kind/enhancement New feature or request area/security kind/security issue/root-user labels Jun 21, 2023
@idrissneumann
Copy link

Just so you know, I reproduce the issue recently :

Screenshot 2023-07-19 at 15 21 20

With this pipeline: https://github.com/idrissneumann/action-kaniko/actions/runs/5600342381/jobs/10242584402

And this pr (that tries to change the user that is running the process): https://github.com/idrissneumann/action-kaniko/pull/4/files

@mmohamed
Copy link

Hi guys, i'm facing this issue also, do i need to keep this on track or i must to forget about running kaniko container as non root user to build images ?

@Tahedah
Copy link

Tahedah commented Mar 18, 2024

Hey, I'm also running into this issue. Running as non root is sadly required for me as well as using a stricter securityContext for the Kaniko container. If there are any updates on this topic, I would be happy to hear about it.

@zhangguanzhang
Copy link

any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/container For all bugs related to the kaniko container area/security feat/non-root issue/root-user kind/enhancement New feature or request kind/feature-request kind/security needs-discussion Items which need more discussion before commitment ok-to-close? possible-dupe priority/p0 Highest priority. Break user flow. We are actively looking at delivering it. priority/p1 Basic need feature compatibility with docker build. we should be working on this next.
Projects
None yet
Development

No branches or pull requests

9 participants