Repository navigation
Conversation
Just to double-check, the term "session" does not appear in the public API here, right? |
|
@shykes correct - internal-only |
LGTM :)
I think we can re-introduce a solid security model on top of this new system. We can reliably add hooks to individual access to each host directory: for example for interactive prompt, load trust information from a config file, run custom policy hooks... The only difference is that those hooks will make a decision based on the real path, rather than an abstract ID. This is the same security model as eg. filesystem sandboxing in MacOS ("this app wants access to The big remaining unknown is: what does this look like when we spin out the engine from the CLI, losing in the process the guarantee that the engine is local? That is a major question but I think we can cross that bridge when we get to it. TLDR: ship it :) |
6bae637 to
18e882b
Compare
I remember @sipsma pointing out there are some pretty big side effects in doing this, especially around state guarantees / cache management. I don't remember the specifics but I'd say it's safer to wait for his feedback on this one |
There was a problem hiding this comment.
Sounds good. I was wondering if there was an underlying reason for having a single session. I'll keep looking for gotchas in the meantime.
Some hunches:
- Building with
dockerfile.v0frontend and takingSingleRef().ToState()and then using it in another session works fine. - LocalDirs are uploaded for each different call, which makes sense to me. The alternative, caching a dir for the entirety of the API server, seems less correct. Maybe this is the same as before. Update: reworded for clarity, added test.
There was a problem hiding this comment.
Ok admittedly it's kind of confusing seeing "NewSession" here when we expressly don't open a Buildkit session at this point anymore. 😅
There was a problem hiding this comment.
This makes it so we wait on any/all mirrorChs to finish and then finally stop the progress UI. If we close this without waiting it'll panic (send on closed channel).
There was a problem hiding this comment.
This is one trade-off; we have to be careful to include all local dirs that appear in the path leading up to a session.Build.
WithLocalDirs is additive and handles deduping to make this pretty easy, but ya still gotta remember to do it.
3328cb4 to
76481cd
Compare
Previously the engine would establish a single Buildkit gateway connection immediately, meaning we had to know all of the LocalDirs upfront for the entire engine runtime. In all core interfaces, the gateway client is now replaced by a *core.Session which doubles as a SolveOpt state manager and establishes new gateway connections on-demand. Signed-off-by: Alex Suraci <[email protected]>
also:
* just put a slice of dirs in FooID, since always we just use the dir as
the id anyway
* TestHostLocalDirWrite -> TestDirectoryExport
* bring back cargo-culted but now more grokkable directory access LLB
note for future readers:
* I think SharedKeyHint tells Buildkit how to synchronize concurrent
runs of the same task. The key value "hints" to Buildkit that they can
be de-duplicated.
* LocalUniqueID is a random value, we want it to be stable, mainly
motivated by tests so I can assert invariants like this:
host.workdir == host.directory(".")
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
and refactor other host tests to use dagger go sdk *_* Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
76481cd to
a716841
Compare
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
|
I 100% agree with the general idea of allowing dynamic loading of local directories rather than forcing them to all be specified up front (with the aforementioned security model being layered on top later).
The type of situation where this behavior becomes a dealbreaker for me is something like this: wd := c.Host().Workdir().ID()
ctr := c.Container().From("foo").WithMountedDirectory(wd, "/mnt")
ctr = ctr.Exec("build something")
_, err := ctr.Exec("run a test").Stdout()
if err != nil {
panic("the test failed :-(")
}
// the test passed! publish the image
ctr.Publish("somewhere:latest")The problem is that when we split everything into its own session, every call to So what can happen is that you do the build, run the test, the test passes, then someone or something comes in and changes your local directory and now you are going to publish an image containing contents that might not actually pass the test you ran.
There are other side effects and potential problems introduced by running every solve in separate sessions (some stuff around buildkit code that defaults to using any session it can find, some possible performance issues involving cache imports and frequent unecessary rechecking of local dir sync state, etc.). However they are either issues we'd have to deal with anyways when switching to multitenant-like architectures or otherwise not dealbreakers, so I will spare you the wall of text (happy to expand if helpful though). In terms of alternate suggestions, I think it may be a good goal to make the synchronization of local dirs from host to buildkit very explicit on part of the users. What do you think about something like this in terms of schema: type Directory {
...
# merge the contents of hostPath from the host into destPath in the directory
syncFromHost(hostPath: String!, destPath: String!) Directory! # not tied to name "syncFromHost", placeholder
...
}That would make the step where synchronization happens very explicit; it's just when you call That's just the schema/ux though. As for how to actually implement it, there's a few possibilities:
Let me know if this makes sense to you. There's a zillion issues intertwined with all this (didn't even mention the possible connections with hypothetical namespacing support) so it's kind of hard to think about all at once; could easily be overlooking something or missing context that changes the variables of the decision of what to do here. |
|
@sipsma Thanks, that's a great example!
I see what you're saying, but I would argue that we shouldn't care. Here's my reasoning: data uploaded from the host machine is inherently not reproducible. Any artifact shipped from it is a mystery. One of the coolest things we have the opportunity to do with Dagger is not only let people build + publish artifacts, but publish the entire recipe of everything that went into it. If any non-reproducible state goes into that recipe (besides secrets) the whole thing becomes pretty pointless. Reproducible builds has always been one of my goals with Bass: each release ships a So I think it would be more appropriate for Dagger's API to cater to reproducible builds and frame host dir uploads as a local dev/tinkering tool. If people want to use host dirs for publishing, that's fine, but they should have roughly the same expectations as with running All that being said, there may be other reasons to go through with the changes you suggest (e.g. in order to sync smaller deltas, or maybe some other session/namespacing related things), and I'm not dogmatically against it. I'm just playing devil's advocate here since it might save us some effort. :) |
|
@vito I totally get where you're coming from but I think if we were to fully embrace that idea it would have a ton of implications besides just local dirs:
The world would be a better place if everyone could+would follow all the reproducibility best practices, but on a practical level I think it's just going to take a long time for everyone to reach the point where they can do so. We can+should encourage this (use fixed digests, disable internet access when you can, etc.), have guides on reproducibility, create extensions that follow reproducible practices (or wrap tools like nix and apko), etc. But there's probably going to be many cases where that's just not going to happen yet (for good reasons and bad). And so if we purposely make our features even less reproducible (i.e. local dirs can mutate between every query rather than every session) in order to encourage users to follow more reproducible practices, I suspect we'll just lose many of them rather than encourage them to do better. So I think we are better off accepting that users are going to use unreproducible sources like localdirs but then give them to opportunity to use them more safely. Part of that requires that external state synchronized into Buildkit is pinned for at least the duration of the session. So in the example from before, even though you can't reproduce the contents of the localdir, at least you can test what you build with them and then be confident that what you export is not going to change out from under you in the next query. There's more to it than just that, but that seems like it would have to be a starting point.
I think there's a chance that plugging in our own local dir session attachable might be relatively straightforward in terms of implementation. That would allow us to get arbitrary localdirs are runtime while avoiding the whole need for dynamic sessions. I think it's worth a quick shot to see how much effort it will require. |
btw, while it's orthogonal to the other discussion, this is actually how buildkit's filesync works by default. There is also an LLB option to disable it and just always sync every file (not sure why). So the possible performance degradation is more just that every sync still needs to perform the comparisons needed for the delta, which could still matter at huge scales but is definitely much better than forcing a full sync every time |
|
@sipsma I agree that we need to support folks who don't want to fully commit to reproducible builds, and I don't think that's at odds with what I'm suggesting. Sorry for the wall of text. The tl;dr is that I'll look into making our own filesync attachable interface and go back to a monolithic session for now, but I don't think we want this forever, and I want to clarify my idea of reproducible builds and how it relates to sessions, just so we're on the same page.
A few points:
I don't think this is an implied requirement for reproducible builds at all. Bootstrapping from a pinned image and running commands to fetch versioned/checksummed data should be just as reproducible as a Buildkit source. If people want to run non-reproducible commands and YOLO I'll expand on these thoughts below.
I'm not sure if you mean to frame it this way, but I think "reproducible builds" carries a stigma that it means "the user has to painstakingly specify every version ahead of time" when to me it really just means "the user can see all the versions that went into an artifact and reproduce it from those versions." When/how those versions are provided to the build is immaterial to the end result, and we can make that UX as good or as painful as we want. We don't have to make the user's life harder. We can support the nice UX of "just give me the latest until I say otherwise" while still giving users reproducible builds. We just need to provide some kind of recipe after-the-fact that contains the pinned version that "latest" resolved to, and make it possible to rebuild, publish, audit, and build further upon that recipe. This is the approach I took with Bass. We almost have these recipes today with If we had proper recipes I don't think we would need to care about session state, which feels like a big win. The My point is that recipes are great because they keep the API stateless and let people gradually adopt reproducible builds, but they become pointless if the user is publishing from a host dir, and publishing is when you'd want these recipes the most. Everything else can be versioned, whether it's up-front or just-in-time. Host dirs cannot, and are never reproducible, whether they're pinned for a session or not. I don't want to force users into a painful-but-safer workflow, because I don't think we should be making the safer workflow painful, either. I'm mainly hesitant to build an illusion that using host dirs for publishing is safe. Sure, your build + tests might pass, and it feels safer to take the exact same bits and publish them, but it feels more "technically pure" than actually safe. What if those bits contain credentials? What if you changed the directory during or before the file sync because it hadn't gotten to that part of your script yet? What if you accidentally vendored proprietary code that's normally fetched at runtime using a token? etc. etc. All this being said (I'm so sorry) I'm not blocking this direction, because it seems like a cool and useful primitive at the API layer, and it'll be pretty annoying to sync the workdir repeatedly for other use cases. Hell maybe you've got some weird workflow where you want to kick off a big non-publishing-related pipeline that runs a bunch of things against your workdir, but you want to keep working after you've seen it upload the context. That seems perfectly fine to me. Thank you for coming to my TED talk.
Looking into this now! |
|
Superseded by #3560 in the short-term, closing for clarity |
Totally agree, continuing to rely on buildkit sessions now is just a practical compromise until we have better solutions ready to go.
Awesome, yeah I agree with pretty much everything you said here. Re-reading what I wrote before, I definitely misinterpreted the direction you were going and then I also kind of started drifting off to tangentially related thoughts, that's my bad. I'm glad we're discussing it in detail either way though.
Yes this is all super interesting. I was thinking about pinning yesterday after seeing this Buildkit PR again in passing and wondering if it could be a path to freedom from sessions (not yet, in time maybe). First, let me double-check I'm understanding what you're saying in terms of recipes. It's not conceptually that far from what we do with IDs today, with the exception that when an ID is returned all occurences of non-pinned version specified are replaced with resolved/pinned versions, right? So even if the user called Makes total sense if so. I guess the slight variation inspired by that source pinning PR (or maybe this is just what you were suggesting all along) would be to make source pinning configuration a separate "entity" that can be passed alongside queries and also updated based on data returned from queries. So then your "recipe" doesn't change (still references "latest" rather than a SHA), it's just that there's optionally a policy stapled to your recipe with the pinned versions to use for each ingredient. Just trying to imagine what this could possibly ever look like in code, maybe: // Clients are now internally initialized with a pinning policy. By default, it's initially empty
// You can also optionally provide something like `WithSourcePolicy` to Connect
client, err := dagger.Connect()
// When you use the client, it sends the pinning policy alongside each request.
// Here's it's empty, so "alpine:latest" will be resolved to a SHA by the builder.
// That SHA gets returned to you w/ the query result.
// Client will then (by default) update its own pinning policy to now use that SHA
_, err := client.Container().From("alpine:latest").Exec(...).Stdout()
// So then future queries from the same client will use that new pinning policy
// e.g. this will tell buildkit to use the same SHA rather than resolving latest
_, err = client.Container().From("alpine:latest").Exec(...).Stdout()
// The above is just the default behavior for users who don't care and want the same degree
// of stability that sessions previously provided (sources are sticky for the duration of
// the `client` object).
//
// There'd also be interfaces on `client` for reading+modifying the pinning policy for users who care about that
// (either because they want to or their company forces them to, etc.).This approach is WAY more complicated than just updating the returned recipe to have pinned versions. I'm just throwing it out there cause it might align w/ buildkit's direction and have some other benefits, but I have 0% confidence in anything right now, just thinking out loud. There's a million variations on all these ideas we can think through too.
I think this aspect of host dirs is the only place where we might diverge a bit still (unless I'm misinterpreting again). I have the sense that it should be possible to use source pinning for state synced from a host in the almost the exact same way you can pin sources like container images and git repos. Just like you can resolve When you send subsequent queries that utilize the localdir pinned to that SHA, buildkitd (or daggerd, whatever) sees the content checksum, looks in its cache for it and uses it if found, erroring otherwise.
Does that make any sense? Once again thinking out loud, coherency not guaranteed. Also to be clear, I don't think the above is possible yet with Buildkit, I'm imagining we change things upstream and/or switch to our own sync method outside of buildkit's local source.
Overall, we should probably move this discussion to an actual separate github discussion and get others involved. It's touching on a ton of crucial topics we need to figure out soon. I'll think about it some more and make a separate discussion on Monday if no one else has, but feel free to on your own too if you beat me to it :-)
Also, I'm very curious for more details about the Bass features you alluded to here! |
|
Sounds like you're breaking out a discussion for this so I'll be brief and just bring closure to this discussion. 🙂
All good! Folks get really passionate and extreme about reproducible builds sometimes so I totally understand the motivation to rein things and make sure UX is always top priority. I should have also been clearer in my original comment. :) Glad we're on the same page, this is a great discussion!
100%
Yeah, for me this reaches the same goal, it's just a different path to getting there. To me a "recipe" is any serializable format that you can publish and others can consume without any extra context or state needed. The structure of that format and the process by which it was constructed doesn't matter too much.
👍
100% makes sense to me as a path to supporting stable local dirs without a monolithic session.
The main difference is that Bass places more emphasis on the "universal/context-free" property of its recipes. Whereas in Dagger For example, anyone can copy the gigantic JSON blob from any build on Bass Loop and run it themselves. This process of building recipes happens transparently as you write Bass code and is further leveraged as the only way to get artifacts out of Bass and onto the host machine. You build up a recipe, Bass's recipes are also human readable (ish - TODO: pretty-renderer). Anyone can audit them after-the-fact to see what exactly went into it, which I imagine to be helpful when CVEs come out. It might be better for them to be machine-readable in that case though, lending merit to the idea of separating pinned versions into a separate field, though that raises more questions around how to "key" versions in a machine-grokkable format. Not sure if there are standards in progress here. Publishing recipes also means people don't have to trust that a binary is what someone claims it is; they can inspect the recipe, build it themselves, and verify that the sha256 of their asset matches the sha256 of the published one. Note that none of this is possible if any part of the recipe depends on a host dir, so that's where my bias against using them for publishing comes from. You'll have a recipe, but it'll point to random paths and not even attempt to verify the content digest/etc. edit: to be clear, I don't find much of this particularly novel, and there may be more effective ways to accomplish these goals, but so far I haven't run into anything else like it. :) |
context: #3401
based on #3418 - will rebase after it's merged for a tidier diffThis is a large refactor in service of having the following API:
I just now got tests passing, so I'm submitting this for any early feedback/course correction.
The Refactor
Previously the engine would establish a single Buildkit gateway connection immediately, meaning we had to know all of the LocalDirs upfront for the entire engine runtime.
In all core interfaces, the gateway client is now replaced by a
*core.Sessionwhich doubles as aSolveOptconfig builder and establishes new gateway connections on-demand.I think this is an appropriate use of the term "session" as it maps 1:1 a Buildkit session (ok, technically a creator of them, but I'm not gonna call it a factory). I'm totally open to other suggestions though as it tends to be a word that's overused.
Note that this means the API now allows unfettered read/write access to the host filesystem. There are no longer flags for allowlisting local directories. If we actually want that for security reasons we can go back to a static
LocalDirsbut I suspect the rest of this refactor is still worthwhile since we probably don't want a single gateway session once we have a long-running external engine.TODO
directory.export, and come up with a pattern forcontainer.exportandfile.export