Repository navigation
Support configuring ownership (almost) everywhere - #4932
Conversation
65a12f6 to
a7bc4ed
Compare
+1 |
|
@marcosnils FWIW, I implemented that but ended up backing out. In the end it didn't seem to actually help more than it hindered. We went through a very similar thing before where we went from |
|
This is finally ready to go. There were two decisions I made but then backed out on:
|
d8fe4db to
c034963
Compare
|
Overall looks good to me. Nitpicky comment about the API (not leaning towards a way or another, just raising the question): Some attributes such as Would it make sense to have a |
|
@aluzzardi That's a good question. I think we need a mix of both, but not everything needs to be contextual. I think in general it's better to have per-call settings because having to deal with "temporary context" is pretty clunky. For example, I was motivated to add #4919 because I had a use case where I wanted to completely ignore the entrypoint for a single WithExec, and dealing with the contextual entrypoint is really awkward ( That being said, I think some things like It would also be nice to have anything that's "contextual" also be possible to set per-invocation, in the same way that you can do For this API, the closest analogue to a shell would be running As for |
sipsma
left a comment
There was a problem hiding this comment.
Would it also make sense to include WithMountTmpfs here so that users can set the owner of the root of the mount (even though obviously there will be nothing to chown under it)
There was a problem hiding this comment.
should this always be 0700? Or would it make sense to look at the permissions on the directory in the source and set it to be the same here? Or maybe that happens implicitly in the Copy below?
There was a problem hiding this comment.
Good catch, fixing this now + adding tests for keeping permissions
There was a problem hiding this comment.
I'm guessing it's not possible to use a source path mount for / so we have to use a copy? Just double checking
There was a problem hiding this comment.
Yeah, this doesn't seem to work.
I tried changing the test like this, which should approximate that approach:
diff --git a/core/integration/container_test.go b/core/integration/container_test.go
index b1e98866..b2e2f5e7 100644
--- a/core/integration/container_test.go
+++ b/core/integration/container_test.go
@@ -345,8 +345,8 @@ func TestContainerWithRootFSSubdir(t *testing.T) {
WithExec([]string{"go", "build", "-o", "/out/hello", "/src/main.go"})
out, err := c.Container().
- WithRootfs(ctr.Directory("/out")).
+ WithMountedDirectory("/", ctr.Directory("/out")).
WithExec([]string{"/hello"}).
Stdout(ctx)
require.NoError(t, err)
require.Equal(t, "Hello, world!\n", out)But it doesn't work. It works if I change /hello to /out/hello so it seems like Buildkit just ignores the source path argument when you remount /. 🤔
There was a problem hiding this comment.
Should probably add to the doc string here something that explains this will change the ownership of whole filesystem tree of source if it is set and the ownership of the mount point. Otherwise it would be easy to assume this changes all the files that have been cached, which IIUC is not the case
|
@sipsma AFAICT there isn't a way to set ownership for tmpfs mounts in Buildkit. 🤔 It only supports setting a size, and I can't do the I figured we can just skip it for now and submit a PR upstream if/when someone requests it. |
TODO: the other types of mounts Signed-off-by: Alex Suraci <[email protected]>
* WithFile * WithDirectory * WithNewFile Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
I'm not sure these are worth exposing; let's wait for a use case to come up. Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
nevermind. too much trouble for too little benefit. This reverts commit 908576434819e457e6d7ad51ab1a18078eb13732. Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Previously WithRootFS would ignore the given directory's relative path, which was necessary for this to work. Now we'll explicitly repoint the directory to /. Updated naming along the way. Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
I think this was originally done so it can be inherited at runtime, but that's no longer necessary, and it required "re-writing" container mounts at WithExec time which seemed strange. also remove Container.WithUser now that we don't need to do anything special there anymore Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
|
@sipsma Permissions issue fixed; ready for another look! 🙏 |
| withOwner := addContent(ctr, example.name, example.owner) | ||
| output, err := withOwner. |
There was a problem hiding this comment.
This could now be: 😁
output, err := ctr.
With(addContent(example.name, example.owner)).There was a problem hiding this comment.
Gave this ago but it just resulted in more code since each addContent then needs to return a function. In this case every call site does something different so I don't think it benefits as much from With vs. common middleware. Oh well!
| // NB: inheriting the user/group from the container was implemented, but we | ||
| // decided to back out for two reasons: |
There was a problem hiding this comment.
Looks like "three" reasons now. 😄
Signed-off-by: Alex Suraci <[email protected]>
| if srcDef == nil { | ||
| // e.g. empty cache mount | ||
| srcSt = llb.Scratch().File( | ||
| llb.Mkdir("/chown", 0o700, ownership.Opt()), |
There was a problem hiding this comment.
@vito Sorry for the late review, head was buried in debugging other stuff, but I think if you specify a mount point in an exec at a path that doesn't exist yet, buildkit defaults to 0755. So using 0700 here might technically be a deviation.
I really doubt this will ever matter, so I don't care if we leave it as is, just bringing it up in case you think it matters.
fixes #4739
Adds
owner: Stringto the following APIs:The(edit: nevermind - #4932 (comment)). The following formats are supported:Stringtype is a bit nebulous and might warrant its own scalarThis was a little tricky to implement because only some parts of Buildkit support resolving names to IDs. Luckily we can use the gateway API to just fetch
/etc/passwdand/etc/groupourselves, which this PR does so that everything supports names.Note: we only change ownership if explicitly told to in the API; it will not automatically chown to the container's "current user." See rationale in #4739 comments and in a comment for the test showing we don't inherit.