Skip to content

new host i/o API, dynamic gateway sessions - #3421

Closed
vito wants to merge 7 commits into
dagger:mainfrom
vito:dynamic-hostdirs
Closed

vito wants to merge 7 commits into
dagger:mainfrom
vito:dynamic-hostdirs

Conversation

@vito

@vito vito commented Oct 18, 2022 •

Copy link
Copy Markdown
Contributor

context: #3401

based on #3418 - will rebase after it's merged for a tidier diff

This is a large refactor in service of having the following API:

host {
  directory(path: String!): Directory!
  workdir: Directory!
}

directory {
  export(path: String!): Boolean!
}

# container/file export not implemented yet

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.Session which doubles as a SolveOpt config 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 LocalDirs but 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

@vito
vito requested review from aluzzardi and shykes October 18, 2022 18:11
@shykes

shykes commented Oct 18, 2022

Copy link
Copy Markdown
Contributor

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.

Just to double-check, the term "session" does not appear in the public API here, right?

@vito

vito commented Oct 18, 2022

Copy link
Copy Markdown
Contributor Author

@shykes correct - internal-only

@shykes

shykes commented Oct 18, 2022

Copy link
Copy Markdown
Contributor
host {
  directory(path: String!): Directory!
  workdir: Directory!
}

directory {
  export(path: String!): Boolean!
}

# container/file export not implemented yet

LGTM :)

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 LocalDirs but 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.

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 /Users, allow?").

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 :)

@vito
vito force-pushed the dynamic-hostdirs branch 3 times, most recently from 6bae637 to 18e882b Compare October 18, 2022 20:33
@aluzzardi

Copy link
Copy Markdown
Contributor

In all core interfaces, the gateway client is now replaced by a *core.Session which doubles as a SolveOpt config builder and establishes new gateway connections on-demand.

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

@vito vito left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.v0 frontend and taking SingleRef().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.

Comment thread engine/engine.go Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok admittedly it's kind of confusing seeing "NewSession" here when we expressly don't open a Buildkit session at this point anymore. 😅

Comment thread engine/engine.go Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread project/project.go Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vito
vito force-pushed the dynamic-hostdirs branch 2 times, most recently from 3328cb4 to 76481cd Compare October 19, 2022 23:20
vito added 5 commits October 20, 2022 17:29
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]>
and refactor other host tests to use dagger go sdk *_*

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the dynamic-hostdirs branch from 76481cd to a716841 Compare October 20, 2022 21:30
@sipsma

sipsma commented Oct 24, 2022

Copy link
Copy Markdown
Contributor

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).

caching a dir for the entirety of the API server, seems less correct.

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 Exec and Publish results in a resyncing of the local dir. And in general any time we do a solve that has a local dir anywhere in its DAG (even distantly related) the local dir will need to be resynced.

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.

  • To be very clear, this behavior exists to a slightly lesser extent before this PR due to the fact that we currently have to implement exports by opening a new session. That however has always been a wart in need of fixing (actually since v0.2) via upstream enhancements, not desired behavior.
    • I could have sworn we had an issue open for this, but I can't find it right now. Depending on the outcome of this discussion, I'll make a new one. There's a buildkit one here though.
  • So my concern with the approach of always resyncing local dirs is not so much that it introduces any new problems, it's that it increases their occurrence and embeds the problematic behavior further into the design.

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 syncFromHost. The directory returned there is then guaranteed immutable for the duration of your client (i.e. the thing returned by dagger.Client or the duration of your callback in engine.Start).

That's just the schema/ux though. As for how to actually implement it, there's a few possibilities:

  1. Local dir syncing is actually just a session attachable, it gets setup automatically here.
    • I am wondering if we can just not tell the buildkit client about local dirs in the solve opts and then register our own implementation of the session attachable that does it instead.
    • I traced through this idea a while ago when looking into something unrelated where I was getting frustrated w/ the local dir implementation and concluded that we'd most likely need to make a few small upstream changes or just fork the buildkit client code (not server). I can't remember why right now, but if we need to go down that route maybe it's worth it provided the changes are relatively small.
  2. There are fields in SolveOpt that are meant to support cases where sessions can be shared and re-used, which might (?) be helpful to us here.
    • However, when I've asked in the past Tonis said the feature was only half implemented and isn't actually useful yet.
    • Just something to keep in mind in case finishing the feature upstream could help us here.
  3. (Not realistic in the short term) abandon use of buildkit localdir sync and just implement our own over services (i.e. rsync-as-a-service)

1 above is probably the most realistic short term option, but it needs a bit more experimentation to be validated. If it works though, it should give us a path to supporting dynamic loading of local dirs while not having to split every solve into separate sessions (and thus force resyncs every solve).


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.

@vito

vito commented Oct 24, 2022

Copy link
Copy Markdown
Contributor Author

@sipsma Thanks, that's a great example!

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.

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 .json file alongside every .tgz which builds the same .tgz bit-for-bit. But I messed up the first release of Bass because I used a host path as an input for one tiny part of it, so its .json files only worked on my machine, and only for a time. 😅

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 bash scripts on their machine where the risks you mention are also present. With that framing I would actually expect it to sync every time, though it'd definitely be slick if it only synced the delta for repeated calls somehow.


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. :)

@sipsma

sipsma commented Oct 25, 2022

Copy link
Copy Markdown
Contributor

@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:

  1. Any time you use a container image w/out a fixed digest, every query should check the tag and re-run if it's changed
  2. Any time you use a git source w/out a fixed commit, every query should check the ref and re-run if it's changed
  3. Same as above for use of HTTP source w/out checksum
  4. Honestly, probably have to disable internet access for any exec ops and instead force all external resources to be provided via source ops (following the above rules)

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'm just playing devil's advocate here since it might save us some effort.

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.

@sipsma

sipsma commented Oct 25, 2022

Copy link
Copy Markdown
Contributor

though it'd definitely be slick if it only synced the delta for repeated calls somehow

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

@vito

vito commented Oct 26, 2022

Copy link
Copy Markdown
Contributor Author

@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.

I think if we were to fully embrace that idea it would have a ton of implications besides just local dirs:

  1. Any time you use a container image w/out a fixed digest, every query should check the tag and re-run if it's changed
  2. Any time you use a git source w/out a fixed commit, every query should check the ref and re-run if it's changed
  3. Same as above for use of HTTP source w/out checksum

A few points:

  • I'm not interested in making users fully embrace reproducible builds. Even I only want that sometimes.
  • I forgot git ref/image digest resolution was sticky within a session! That'll definitely add some risk to today's examples. Didn't mean to change that with this PR, and I don't think we're ready for it yet, so good catch. 😱
  • Checking on every query seems closer to what we'd want with an external engine, as opposed to resolving git refs/image tags once for the entire engine. We were already confused by this via the Playground when it cached a git query until it was restarted. One alternative is to tie queries to per-client sessions, but I don't think we need that either.
  • I don't agree that fully embracing reproducible builds has the above consequences for the user. I think if we do our job right users shouldn't ever feel the need to specify image digests/commit SHAs (unless they really want to), and I don't think that's at odds with reproducible builds.

4. Honestly, probably have to disable internet access for any exec ops and instead force all external resources to be provided via source ops (following the above rules)

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 apt-get they should totally be able to, they just shouldn't expect their builds to be 100% reproducible. As you suggested, a tool this restrictive would just push people away from reproducible builds. We'd do a greater service to the world by allowing them to gradually adopt them, whether they know they are or not. 😉

I'll expand on these thoughts below.

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.

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 ContainerID/DirectoryID, but the DirectoryID from a git.branch.tree doesn't actually specify a commit, it relies on the session to resolve it. They're also too opaque; I can't easily audit a FooID to see if I'm affected by a CVE. Maybe we don't care about this use case right now, but I think we may someday with all the increased attention to software supplychain security. I'm happy to keep this as a differentiator for Bass but I think it'd be even cooler if every user of Dagger got this "for free" across all languages.

If we had proper recipes I don't think we would need to care about session state, which feels like a big win. The DirectoryID from git.branch.tree would contain an exact commit and I could pass it around willy-nilly, not caring about server state (including restarts/reconnects). We could do something similar for image digest resolution: folks are already pre-assigning client.Container().From(image) in basically every example so it doesn't seem like a big change to turn that into a tag resolution that returns an ImageID that we pass to From instead.

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.

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.

Looking into this now!

@vito vito mentioned this pull request Oct 26, 2022
@vito

vito commented Oct 29, 2022

Copy link
Copy Markdown
Contributor Author

Superseded by #3560 in the short-term, closing for clarity

@vito vito closed this Oct 29, 2022
@sipsma

sipsma commented Oct 30, 2022 •

Copy link
Copy Markdown
Contributor

@vito

go back to a monolithic session for now, but I don't think we want this forever

Totally agree, continuing to rely on buildkit sessions now is just a practical compromise until we have better solutions ready to go.

If people want to run non-reproducible commands and YOLO apt-get they should totally be able to, they just shouldn't expect their builds to be 100% reproducible. As you suggested, a tool this restrictive would just push people away from reproducible builds. We'd do a greater service to the world by allowing them to gradually adopt them, whether they know they are or not.

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.

If we had proper recipes I don't think we would need to care about session state, which feels like a big win. The DirectoryID from git.branch.tree would contain an exact commit and I could pass it around willy-nilly, not caring about server state (including restarts/reconnects).

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 Container().From("alpine:latest").ID(), the ID returned to them would not still have "latest", it would have whatever the resolved SHA is at that time.

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.

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.

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 latest->sha for a container image, you can resolve path->content checksum for local dirs. Once you have that content checksum sha, it serves as your pinned version.

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.

  • The difference is that whereas the container image SHA is probably accessible to any buildkit host in the world, the content check sha is almost certainly only valid on this particular host (and only until it is pruned). You can't reverse the mapping from checksum->contents in the same way that you can pull an image from its SHA.
  • That doesn't really change anything about the logic above though; it just means recipes (or pinning policies) aren't necessarily always portable from one buildkitd to another. But that's fine, I don't think we need IDs to be portable like that unless they truly are portable (i.e. don't use local sources). If you try to reproduce something not reproducible, you get an error.

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.

  • The Buildkit pinning PR does not yet include support for local dirs, I'm presuming at least partially because the implementation of the above is much easier said than done.

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 :-)

I'm happy to keep this as a differentiator for Bass

Also, I'm very curious for more details about the Bass features you alluded to here!

@vito

vito commented Oct 31, 2022 •

Copy link
Copy Markdown
Contributor Author

Sounds like you're breaking out a discussion for this so I'll be brief and just bring closure to this discussion. 🙂

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.

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!

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 Container().From("alpine:latest").ID(), the ID returned to them would not still have "latest", it would have whatever the resolved SHA is at that time.

Makes total sense if so.

100%

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.

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.

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.

  • The difference is that whereas the container image SHA is probably accessible to any buildkit host in the world, the content check sha is almost certainly only valid on this particular host (and only until it is pruned). You can't reverse the mapping from checksum->contents in the same way that you can pull an image from its SHA.

  • That doesn't really change anything about the logic above though; it just means recipes (or pinning policies) aren't necessarily always portable from one buildkitd to another. But that's fine, I don't think we need IDs to be portable like that unless they truly are portable (i.e. don't use local sources). If you try to reproduce something not reproducible, you get an error.

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.

100% makes sense to me as a path to supporting stable local dirs without a monolithic session.

Also, I'm very curious for more details about the Bass features you alluded to here!

The main difference is that Bass places more emphasis on the "universal/context-free" property of its recipes. Whereas in Dagger ContainerID etc. are an internal intermediate representation opaque to the user, in Bass they're meant to be published and consumed by anyone anywhere.

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, (emit recipe *stdout*), and pipe it to bass --export.

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. :)

@vito vito mentioned this pull request Nov 4, 2022
1 of 10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants