-
Notifications
You must be signed in to change notification settings - Fork 785
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
WORKDIR does not honor USER's uid&gid when creating the directory #2323
Comments
This is also reproducible with the most recent Buildah. The behavior is exactly the same.
|
@petr-motejlek I don't have quick access to test, will do so on Monday. If by chance you've time this weekend, could you try running this as root and let me know if this has the same issue then? My first suspicion is the specified WORKDIR isn't get the right privs set in rootless, but just a quick guess. |
certainly. Do you mean "as root" as in "docker run ... sudo buildah bud" ? If so, then the result is the same :( $ docker run -it --rm -v "$(pwd)":"$(pwd)":ro -w "$(pwd)" --privileged --net=host --security-opt label=disable --security-opt seccomp=unconfined --device /dev/fuse:rw quay.io/buildah/upstream:master sudo buildah bud -f prdel/Dockerfile prdel
STEP 1: FROM ubuntu:latest
Getting image source signatures
Copying blob fc878cd0a91c done
Copying blob d51af753c3d3 done
Copying blob 6154df8ff988 done
Copying blob fee5db0ff82f done
Copying config 1d622ef86b done
Writing manifest to image destination
Storing signatures
STEP 2: RUN useradd -r -s /bin/false -m -d /opt/my_project my_project
STEP 3: USER my_project
STEP 4: WORKDIR /opt/my_project/src
STEP 5: RUN id && ls -la && mkdir this_fails
uid=999(my_project) gid=999(my_project) groups=999(my_project)
total 8
drwxr-xr-x 2 root root 4096 Apr 25 18:05 .
drwxr-xr-x 3 my_project my_project 4096 Apr 25 18:05 ..
mkdir: cannot create directory 'this_fails': Permission denied
error building at STEP "RUN id && ls -la && mkdir this_fails": error while running runtime: exit status 1 |
Nice work diagnosing, |
Thanks @petr-motejlek . I think @rhatdan has a fix in progress with #2332 |
Nope not fixing this issue. |
Hmm. When I try this with Which version are you using? I'm wondering if this is a behavior that changed at some point. |
I am on cgroups V2 right now so can' t easily test right now. But the original code was attempting to do what we are doing now. |
Ok I just tried this out on Docker, and it does not change the label of the workdir |
@petr-motejlek Just checked on moby(docker) and the workdir gets setup as root there just like Podman.
|
Argh. This is just too mind-blowing. So, plain Docker indeed seems to create the workdir owned by ROOT. Yet, when I use DOCKER_BUILDKIT (which uses the BuildKit engine that comes with the Docker CLI), it will use USER. What moby(docker) did you use to test this (you said it's not setting the ownership there either)? (I am using docker-buildx, currently at version 0.4.1, released 6 days ago, and with that one, I can see the expected ownership (my_project)). I assume, even though this behavior might not be desired, you won't want to change buildah's code, unless upstream changes, huh? |
I ask, because this very well might be something that Docker does not implement (anymore), yet BuildKit does. |
and I should have reopened this prior. |
I used the latest upstream client of Docker that I could get. I think it was 1.18+, however, that was for when the ARG was declared above the FROM and then referenced again after the FROM. I've a suspicion something is off with the chown due to a recent change to stage handling, but I'd not yet run it down. |
Arg, too many issues, I meant to reopen #2192. |
I actually tested against I guess it is arguable, what is the correct behaviour. If you open a issue against upstream Docker to change the default, it would make it easier for us to follow. But if you have good arguments about what it should be then I am willing to push for it again. @nalind @vrothberg WDYT? |
I think this heavily depends on what is the generally expected usage for WORKDIR. I think the simplest case why one would use it is to affect the working directory of the image I am creating (parallel to what USER, EXPOSE, VOLUME, ... do). In this case, I would not expect it to create the directory at all. USER does not create a user. EXPOSE does not actually listen on any ports, it's just metadata. So is VOLUME, technically. The expanded case of using it in the middle of a Dockerfile as an alternative to So, honestly, my number 1 would be: only use WORKDIR as metadata indicator. Since we are already pass that, I think it would be better for it to honor USER. Reason? Well, think about a Dockerfile like this: FROM nginx:18.04
ARG user=nginx
USER $USER
WORKDIR /var/tmp/nginx
COPY --chown=$USER ./www ./
... It's obviously incomplete, and nginx might not be the best example, but there are cases where I, in theory, have no need to use The way things are, in this example the nginx user won't actually be able to access the working directory. Strike that. Writing this, I realized, WORKDIR might actually instead need I'll link the ticket for Docker, when I create it. |
Turns out there's already a request for this @ moby/moby#36677 |
And there's also moby/moby#34819 (related) about implementing |
Especially where the issue is two years old. |
Personally I would prefer the --chown, since that would not break existing users. |
Description
It seems that when Buildah's
WORKDIR
creates directories, it does not honor the currentUSER
. Bothdocker build
andDOCKER_BUILDKIT=1 docker build
with the same Dockerfile will honor it.Steps to reproduce the issue:
Describe the results you received:
With
docker buildx
:Notice
#7 0.967 drwxr-xr-x 2 my_project my_project 4096 Apr 25 12:32 .
With Buildah:
Notice
drwxr-xr-x 2 root root 4096 Apr 25 12:32 .
Describe the results you expected:
I would expect the directory to be owned by the user
my_project
and groupmy_project
.Output of
rpm -q buildah
orapt list buildah
:N/A
Output of
buildah version
:The text was updated successfully, but these errors were encountered: