You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WithMounted{File,Directory,Cache,Secret,Temp} operations are currently assigning root:root permissions inside the containers which makes any pipeline that doesn't use a root user fail.
Log output
#3 test
#3 0.147 uid=1000(foo) gid=1000(foo)
#3 DONE 0.3s
#3 test
0
#3 0.147 -rw-rw-r-- 1 root root 12 Mar 9 14:25 message.txt
As you can see from the repro steps, message.txt gets mounted as root even though current user is foo
Proposal: for File and Directory we can add withOwners(uid: Int, gid: Int) which seems to fit naturally alongside with withTimestamps(timestamp: Int) (chown vs chtimes).
Proposal: for File and Directory we can add withOwners(uid: Int, gid: Int) which seems to fit naturally alongside with withTimestamps(timestamp: Int) (chown vs chtimes).
+1. One thing that brings my attention is that {Container, Directory}.WithNewFile and Directory.WithNewDirectory API's have the permissions (chmod) option as a field argument. Would it be possible to consolidate?
For caches + secrets + sockets we can add mount options:
I think this feels weird because these three aren't so strictly tied to the idea of filesystems/permissions/etc. compared to files and directories. For example, Secret { withOwners } is pointless if the secret is only ever passed as an env var instead.
Right now I'm leaning towards sticking to mount options instead, just farming for dissent.
Arguably even File/Directory should be mount-time because the value is influenced by the running context (valid UID in container), as opposed to withTimestamps which applies to the object itself. In fact, there might be a way to support usernames instead of user IDS which seems like a major DX win.
Right now I'm leaning towards sticking to mount options instead, just farming for dissent.
yep, sharing the same feeling about this.
Arguably even File/Directory should be mount-time because the value is influenced by the running context (valid UID in container), as opposed to withTimestamps which applies to the object itself.
True. Another reason to add these as query arguments I guess?
In fact, there might be a way to support user_names_ instead of user IDS which seems like a major DX win.
yep, that'd be great. IIRC Dockerfiles have the same DX as well for --chown. I don't think it works for mounts though
True. Another reason to add these as query arguments I guess?
๐
yep, that'd be great. IIRC Dockerfiles have the same DX as well for --chown. I don't think it works for mounts though
It looks like this is easy (ish) for mounting files/directories. You can just use llb.WithUser("foo:foo") as long as the base of the llb.Copy operation stems from the filesystem. It'll resolve those names to IDs by looking at /etc/passwd on its own.
It seems a lot harder for secrets/sockets/caches. We'll have to manually load up /etc/passwd and /etc/group and resolve names to UIDs in that case. I'll try to implement it anyway, it's definitely a lot nicer to be able to use names everywhere rather than guess or print the ID beforehand.
Do we want container mounts to inherit the container's configured user by default? That seems to be the crux of the original report, but the title mentions explicitly configuring it.
I started implementing it, but it adds a bit of overhead (a copy + chmod for every mount), and I wonder if it's too surprising. For example maybe you want to keep ownership as-is when passing data from one container to another. I'm not sure when you would want to do that, and users in one container might not be present with the same ID in another, but maybe sometimes it matters?
If we pass withMountedFile with foo:foo, what would be the expected behavior?
Do we check in the host /etc/passwd to transform this foo:foo into the host uid:gid? Or do we check in the /etc/passwd in the container this file is mounted into?
What if we don't find it (in any of both cases), do we fall down to the default user (on host, that would be the user running the pipeline, on the container, it would be image's default)? Or do we fail with an error telling the mapping could not be found?
Do we check in the host /etc/passwd to transform this foo:foo into the host uid:gid? Or do we check in the /etc/passwd in the container this file is mounted into?
The latter
What if we don't find it (in any of both cases), do we fall down to the default user (on host, that would be the user running the pipeline, on the container, it would be image's default)? Or do we fail with an error telling the mapping could not be found?
The latter again, but now that you mention it, I'll add an explicit test ๐
There's a sneaky interaction here with WithTimestamps, and file timestamps in general: chown is technically a write, so it bumps the timestamps, causing this test to fail:
Seems like more evidence that we shouldn't automatically chown things. If it's opt-in, you can at least mount + chown and then fetch that directory back out and apply WithTimestamps to it.
The only reason I can think of is that the file is already chowned to 0:0 and somehow Buildkit does a no-op, but I don't know why that wouldn't apply to my local machine:
Do we want container mounts to inherit the container's configured user by default? That seems to be the crux of the original report, but the title mentions explicitly configuring it.
I would personally find it pretty surprising. Even though it adds some verbosity to the pipeline, having a magical inheritance of the uid/gid might become confusing. WDYT @helderco ?
Activity
dolanor commentedon Mar 28, 2023
related issue regarding secrets: #3323
[-]๐ WiithMounted[File,Directory,Cache,Secret,Temp} don't allow setting arbitrary uid/gid [/-][+]๐ WiithMounted{File,Directory,Cache,Secret,Temp} don't allow setting arbitrary uid/gid [/+][-]๐ WiithMounted{File,Directory,Cache,Secret,Temp} don't allow setting arbitrary uid/gid [/-][+]๐ WithMounted{File,Directory,Cache,Secret,Temp} don't allow setting arbitrary uid/gid [/+]mircubed commentedon Apr 10, 2023
talked with @vito, and he will take a look at this one.
marcosnils commentedon Apr 10, 2023
We were speaking with @grouville on Friday that this should also take into consideration
withFile, withDirectory, withNewFile, etcvito commentedon Apr 10, 2023
Proposal: for
FileandDirectorywe can addwithOwners(uid: Int, gid: Int)which seems to fit naturally alongside withwithTimestamps(timestamp: Int)(chownvschtimes).For caches + secrets + sockets we can add mount options:
Not sure about
withMountedTempyet.marcosnils commentedon Apr 11, 2023
+1. One thing that brings my attention is that
{Container, Directory}.WithNewFileandDirectory.WithNewDirectoryAPI's have thepermissions(chmod) option as a field argument. Would it be possible to consolidate?SGTM here!
vito commentedon Apr 11, 2023
I just realized we could technically make the same API change for these, it just feels a little odd for some reason:
I think this feels weird because these three aren't so strictly tied to the idea of filesystems/permissions/etc. compared to files and directories. For example,
Secret { withOwners }is pointless if the secret is only ever passed as an env var instead.Right now I'm leaning towards sticking to mount options instead, just farming for dissent.
Arguably even File/Directory should be mount-time because the value is influenced by the running context (valid UID in container), as opposed to
withTimestampswhich applies to the object itself. In fact, there might be a way to support usernames instead of user IDS which seems like a major DX win.Hmm...
marcosnils commentedon Apr 11, 2023
yep, sharing the same feeling about this.
True. Another reason to add these as query arguments I guess?
yep, that'd be great. IIRC Dockerfiles have the same DX as well for
--chown. I don't think it works for mounts thoughvito commentedon Apr 11, 2023
๐
It looks like this is easy (ish) for mounting files/directories. You can just use
llb.WithUser("foo:foo")as long as the base of thellb.Copyoperation stems from the filesystem. It'll resolve those names to IDs by looking at/etc/passwdon its own.It seems a lot harder for secrets/sockets/caches. We'll have to manually load up
/etc/passwdand/etc/groupand resolve names to UIDs in that case. I'll try to implement it anyway, it's definitely a lot nicer to be able to use names everywhere rather than guess or print the ID beforehand.vito commentedon Apr 13, 2023
Do we want container mounts to inherit the container's configured user by default? That seems to be the crux of the original report, but the title mentions explicitly configuring it.
I started implementing it, but it adds a bit of overhead (a copy + chmod for every mount), and I wonder if it's too surprising. For example maybe you want to keep ownership as-is when passing data from one container to another. I'm not sure when you would want to do that, and users in one container might not be present with the same ID in another, but maybe sometimes it matters?
dolanor commentedon Apr 14, 2023
If we pass
withMountedFilewithfoo:foo, what would be the expected behavior?Do we check in the host
/etc/passwdto transform thisfoo:foointo the host uid:gid? Or do we check in the/etc/passwdin the container this file is mounted into?What if we don't find it (in any of both cases), do we fall down to the default user (on host, that would be the user running the pipeline, on the container, it would be image's default)? Or do we fail with an error telling the mapping could not be found?
vito commentedon Apr 14, 2023
The latter
The latter again, but now that you mention it, I'll add an explicit test ๐
vito commentedon Apr 14, 2023
There's a sneaky interaction here with
WithTimestamps, and file timestamps in general:chownis technically a write, so it bumps the timestamps, causing this test to fail:Seems like more evidence that we shouldn't automatically
chownthings. If it's opt-in, you can at least mount + chown and then fetch that directory back out and applyWithTimestampsto it.vito commentedon Apr 15, 2023
Somehow the above test is passing in CI. ๐ค
The only reason I can think of is that the file is already chowned to
0:0and somehow Buildkit does a no-op, but I don't know why that wouldn't apply to my local machine:I noticed the dates above looked a little funny, so I pruned the Buildkit cache and re-ran and sure enough, it passes:
No idea why this would happen.
grouville commentedon Apr 17, 2023
I would personally find it pretty surprising. Even though it adds some verbosity to the pipeline, having a magical inheritance of the uid/gid might become confusing. WDYT @helderco ?