Repository navigation
core: key a declaring module's calls on the credentials they borrowed, not the session - #15238
Merged
Merged
Conversation
sipsma
force-pushed
the
sipsma/git-clients-borrowed-credentials
branch
from
November 20, 2026 00:44
ad32cdb to
fb62c2e
Compare
tiborvass
approved these changes
Nov 20, 2026
sipsma
force-pushed
the
sipsma/git-clients-borrowed-credentials
branch
from
November 20, 2026 01:36
fb62c2e to
838bfba
Compare
A call's result requires a session resource, such as a secret or socket, when it depends on one, which mostly comes through the call's inputs: its key names the resource, so a session without it can't even ask. But a resolver can reach a session's resources during its work, and a key computed before the work can't name those: credentials the session lends to code the call runs are one case. Until now the only way to protect such a result was to put the whole session in the key, so no other session was ever served it, whether or not the work used anything the session held. RequireSessionResourcesOf lets the resolver say, as it returns, which results it used. The call's result gets a dependency on each session resource in their closures, added in the same critical section that indexes the call's key, so the usual check refuses the result to a session that hasn't loaded the same resources and serves it to one that has. A result that borrowed nothing requiring a resource is unchanged. When the call returns a result the cache already holds under another key, that result is the one that gains the requirement, so its other callers are refused it too unless they hold the resource. Signed-off-by: Erik Sipsma <[email protected]>
…session Since a module's config could declare git clients, every function of such a module had the session in its cache key, because its code may serve a declared client with credentials the session lends. Whether or not a function served a client or used a credential, no new session was served its result, on any engine. The key keeps the declared clients' digest, so a changed or removed declaration still misses. In place of the session, a call of such a module tracks what its work borrows, and its result requires the session resources those results required (dagql.RequireSessionResourcesOf): - Serving a declared client records the module source it resolved, which requires the token or SSH agent it was fetched with, and nothing for a repository anyone can read. It records on the function call whose work the serving client does, the nearest of the client and its ancestors that a call created, so a module entrypoint's process counts too. - Every module call result the work obtains, executed or from cache, null results included, is recorded as well: another module that borrowed can hand back a string, which carries no dependency on how it was computed. - A module entrypoint keys the process it starts on the call's recipe digest, which no longer changes per session. For a call that tracks borrowing the process is keyed on the session too, so a session refused the call's result doesn't get the process's output either. It runs only when the call misses. A session that hasn't loaded the same credential computes its own result, one that has is served it, and calls that borrowed nothing are served to every session. An entrypoint member's call, such as prebuild's, tracks nothing, since its result isn't a module function's. Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
sipsma
force-pushed
the
sipsma/git-clients-borrowed-credentials
branch
from
November 20, 2026 02:09
838bfba to
18c7eb4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since #14493, a module's code can serve a git client that its
dagger.tomldeclares, and the engine resolves it with the git credentials of the session that called it. To keep a result built with one session's credentials away from other sessions, #14493 put the session id in the cache key of every function of a module that declares any git client. It did so whether or not the function served a client or used a credential.So no new session is ever served those functions' results, on any engine, warm or fresh. On a copy of dagger/dagger's own pull-request checks, 19 checks call such a function directly, and on a same-commit rerun on a warm engine they run it again: 355 s of rerun time across them. go-client/test's rerun on a warm engine takes 25 to 27 s, against about 4 s for a check that is served whole.
What changes
The key keeps the declared clients' digest, so a changed or removed declaration still misses, as #14493 intended. The session id goes. In its place, a call's result requires exactly the credentials its work actually borrowed, through the session-resource check the cache already uses for secrets and sockets:
The mechanism is a small dagql hook,
RequireSessionResourcesOf, besideDeclinePersistenceandExpireBy. A resolver calls it with the results it borrowed through, and the cache gives the call's result a dependency on each session resource in their closures. That happens in the same critical section that indexes the call's key, so no lookup is served the result before it carries the requirement. A resolver that borrows nothing changes nothing.Results
What a later session gets
Each case was tested on this change and on main. A first session with the right token runs a call that serves a private declared client, plus two calls above it that return its string. One is in a module that declares a git client, the other in a module that doesn't. A new session then runs each call:
Main and this change read the same in all nine cells. The last column is how main already behaves: a module that declares no git client has no session in its key. This change neither opens that nor closes it.
The secret the engine creates for a lent token is created in the module's own client, so its handle is scoped to the module's implementation (
core/client_resource.go). A session outside that module's code can't bind it, which is why the forged secret name misses.One behavior does change. If module code catches
serveModule's authentication failure and returns normally, that outcome is now cached across sessions, so a later session that has the credential is served the failure. Before, the session in the key kept them apart. Generated clients return the error instead, so the function fails and nothing is cached.Tests
core/integration/module_serve_git_trust_test.go, new subtests:dagql/cache_borrowed_resources_test.go: a borrowed resource gates the result; a borrowed result that requires nothing adds nothing; a returned shared result gains the requirement for its other callers too; a detached result is refused.#15130 also edits
core/modfunc.go, next to the git clients digest. It changes how local clients are keyed, not this, and the two don't interact.