Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 2111275

Summary: Permission denied creating or accessing files in a --mount=type=cache Dockerfile with buildah
Product: Red Hat Enterprise Linux 8 Reporter: David Guthrie <dguthrie>
Component: buildahAssignee: Aditya R <arajan>
Status: CLOSED WORKSFORME QA Contact: atomic-bugs <atomic-bugs>
Severity: high Docs Contact:
Priority: unspecified    
Version: 8.6CC: arajan, pthomas, tsweeney, umohnani
Target Milestone: rcFlags: tsweeney: needinfo-
pm-rhel: mirror+
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-08-22 21:49:17 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description David Guthrie 2022-07-26 23:00:18 UTC
Accessing files in a build mount using a Dockerfile with --mount=type=cache results in a permission denied

* All file actions result in permission denied.
* Examples that work with buildkit all fail

A simple Dockerfile 
~~~
FROM ubi8/ubi

RUN --mount=type=cache,target=/mycache  touch /mycache/myfile.txt
~~~

failed with permission denied.  Attempts to set user ids, change the permissions on the directory, etc, all fail with the same error.

Running an strace on the file touch withing the buildah container doesn't yield any useful results

write(2, "touch: ", 7touch: )                  = 7
write(2, "cannot touch '/mycache/myfile.tx"..., 34cannot touch '/mycache/myfile.txt') = 34
write(2, ": Permission denied", 19: Permission denied)     = 19
write(2, "\n", 1

Comment 1 Tom Sweeney 2022-07-27 12:41:02 UTC
@dguthrie can I ask for a few more details please?  At first blush, it looks like you may have not volume mounted /mycache.  Can you please let us know:

1)  Were you running this a root or a rootless user
2)  What was the buildah command that you used?

Comment 3 David Guthrie 2022-07-27 20:16:34 UTC
Hi @tsweeney and @arajan 

The initial command was this:

$ buildah build --layers=true  -t localhost/testlayers:v1 .

I had to used --cap-add to have it allow strace. I did try it with setenforce 0 and 1. There are no messages that show up in the selinux logs.

$ buildah build --layers=true  -t localhost/testlayers:v1 --cap-add SYS_PTRACE .

Okay, it does work if I set use both ",z" and set the user to root

~~~
FROM ubi8/ubi

ARG UID=0
ARG GID=0

USER ${UID}:${GID}
RUN --mount=type=cache,uid=${UID},gid=${GID},target=/mycache,z touch /mycache/test.txt
RUN --mount=type=cache,uid=${UID},gid=${GID},target=/mycache,z mkdir -p /mycache/foo/bar
~~~

If I change the user ID to something else, like 1000, it fails.

Comment 5 David Guthrie 2022-08-01 14:57:50 UTC
Hi @arajan,

One thing I did notice is that if I run it once with the 'z' flag, then I can thereafter take the z flag off and it will still work with that same cached path. It seems to be reusing the same cached pat, but remembering the how it was created (i.e. z) rather than treating the path with the 'z' and different than the one without.

What I mean is

RUN --mount=type=cache,uid=${UID},gid=${GID},target=/mycache touch /mycache/test.txt

-- Permission denied

RUN --mount=type=cache,uid=${UID},gid=${GID},target=/mycache,z touch /mycache/test.txt

-- Success

RUN --mount=type=cache,uid=${UID},gid=${GID},target=/mycache touch /mycache/test.txt

-- Success

Where the UID is 0, of course.