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
{{ message }}
Repository navigation
Proposal: in-memory secret store for dynamic secrets #3442
Discussed this briefly with @aluzzardi today to gather context and unblock @jlongtine.
Looks like there are two options:
Option 1: (long-term), bigger effort: some sort of secret extension API to plug things like Vault, etc... as I understand that the ability to add secrets from the API (like in 0.2) is not gonna happen (for valid reasons). Also this API needs to be designed, reviewed and implemented. We know what it takes.
Option 2: (short-term): have a private API (under engine, hidden from the Go SDK) to allow for creating secrets. This will be intended to disappear (risk to leak, and to stay forever).
I guess option 2 is more viable to unblock dagger-cue, depending on the effort for option 1. If we go option 2, we should find a way to derisk, for instance hiding the call behind a feature flag (eg. if this weird env var isn't set, the code path is disabled).
Would it be possible for @sipsma or @vito to own this one? Note that I am not hinting any option here, the priority is to remove the blocker. There might be an option 3 that I don't see.
@jlongtine how absurd and awful of an idea is this: you currently can load secrets from env vars, so whenever you need to load a secret in dagger-cue you export an env var and then use that to load the secret in? Would need to be careful if dagger-cue ever forks off child processes of course. But could be a path to avoiding any changes to the API if it's plausible.
Maybe we should revisit the “no direct creation of secrets” rule, in case the circumstances have changed?
The initial motivation for “no direct creation” was to:
avoid leaking plaintext secrets into the “id” (serialized recipe). Because IDs are typically understood to be safe to copy paste, share etc.
avoid sending plaintext secrets on the wire
One major change is that we plan on making the engine remote; and our understanding of IDs and their role has evolved. So maybe it’s OK to create secrets directly after all?
TLDR my first guess would be either option 2 (hidden api call) or “option 2+” (regular api call). Skeptical about option 1 because it means rushing a pretty big design discussion for a short term problem.
Bunch of edge cases we run into. The model of API-based creation broke down in a few places. For instance, when added in an extension it only works on un-cached runs (cached runs return a SecretID without the extension having run AddSecret, resulting in a broken secret)
To add to the above -- edge cases are caused by "AddSecret" being very special. It's the only call that alters the internal API state (whereas all other calls are idempotent, multi tenant, etc -- AddSecret is not)
I'd prefer we don't rush into neither Option 1 (needs design) nor Option 2+ (ripple effects, not easily reversible). @vito is going to post a summary of Option 3 (do nothing in core, work around with the existing API)
Caveat: this will result in a SecretID that embeds the secret value in plaintext (albeit obfuscated below multiple layers of base64 ✨ security ✨). But maybe that's enough for now? As long as the SecretID itself isn't leaked this should still accomplish the goal of keeping its value out of the container layers.
This feels roughly the same level of risk as option 2 or introducing a dedicated "create secret" API, but the benefit is it already exists.
If you want to avoid leaking values into the SecretID you could instead leak them to the host filesystem and clean them up after:
os.WriteFile("/sekrits/bruce", []byte("im always angry"), 0600)
deferos.Remove("/sekrits/bruce")
client.Host().Directory("/sekrits").File("bruce").Secret()
// ... do API calls ...
For extra pizazz you could try using a fifo/pipe instead but we're skeptical that'll actually work. :P
Alternatively you could use env vars, but that's pretty sketchy too.
Between these two my preference would be the first one, since it's essentially what this issue proposes but feels like a workaround (which really it is).
If I understand correctly, Option 3 would be basically "all userland", no new API call either private or public? If so, that would be an ideal short term solution :)
@jlongtine how absurd and awful of an idea is this: you currently can load secrets from env vars, so whenever you need to load a secret in dagger-cue you export an env var and then use that to load the secret in? Would need to be careful if dagger-cue ever forks off child processes of course. But could be a path to avoiding any changes to the API if it's plausible.
An update: Using environment variables works! I've got that all up and running, and it unblocked me on a bunch of stuff. Thanks for all the help, everyone!
I had a good discussion today with @sipsma and @vito about this.
Our proposal as a first pass (with subsequent designs for extensions, etc) is to add a GraphQL API to allow the creation of new Secrets. This will add those secrets to the secret.Store, and allow for retrieval by Buildkit.
Everything feels pretty solid on implementation, but we still have some open questions around the API.
API Design
I had previously suggested one or the other of these:
extendtypeQuery {
"Load a secret from its ID"secret(id: SecretID): Secret!
}
typeSecret {
"The identifier for this secret"id: SecretID!
"Thevalueofthissecret"
plaintext: String!
"Createanewsecret"
new(plaintext: String!) Secret!
}
extendtypeQuery {
"Load a secret from its ID"secret(id: SecretID, plaintext: String): Secret!
}
With the following behavior:
if id == nil && plaintext == nil {
return err
} else if id != nil && plaintext == nil {
return the secret with id = id
} else if id != nil && plaintext != nil {
create a new secret with this id and plaintext, unless a secret with this id already exists (and return an error in this case)
} else if id == nil && plaintext != nil {
create a new secret with this plaintext, setting the id to sha256(plaintext)
}
For example, Bass constructs the Dagger client once on boot - it'll be awkward to use dynamic secrets here since the secrets don't exist until you use the runtime. I could move the Dagger client construction to each runtime call, but that might worsen performance (assuming dagger.Connect does engine session setup/etc.)
Also just realized this is actually an argument in favor of withSecret (#3442 (comment)) since I wouldn't need to carefully ensure secret names don't collide in shared session state with a long-lived client.
I don't have a lot of knowledge on BuildKit secret management. @jlongtine helped understand better but I feel I'm still not completely sure how it works.
I spent some time today in creating some diagram to share and be able to have feedback on my comprehension.
I had a first diagram that I presented to @jlongtine again.
(somehow, the mermaid interpreter from GitHub can't parse the code, so I put it in the annex)
So I thought the dagger-session would completely run in the Docker container, with the graphql server as well. But @jlongtine told me that the graphql server runs in the SDK (from the provisionning logic).
So the connection between the SDK and the Dagger Engine is not GraphQL based, but more gRPC for BuildKit Gateway?
Then, the graph would look like that:
So my questions are:
What is right? What is wrong in these diagrams?
Is the Dagger Session in the SDK client or in a container? (there was a dagger-engine-session container back in the old days, like, last week)
Related: Is the session attachable client-side or server-side? GraphQL Client? Or BuildKit Client?
Are the Secrets fetched from the host or from buildkit?
How does the secret provider communicate with the host?
through the session attachable, via dual-direction gRPC connection? With some sort of callback?
it doesn't communicate with the host and we serialize everything on the client and send to BuildKit in 1 direction/request?
Annex: mermaid code
1st Graph: GraphQL Server in the Dagger Engine
Details
graph LR
subgraph Host
subgraph UserCode[User Code]
code --> nsfe(["core.NewSecretFromHostEnv('MY_SECRET')"])
end
UserCode --> SDK
subgraph SDK
gqlbuilder[GraphQL query builder]
gqlbuilder -- build query --> hvs
hvs[ HostVariable secret ] ~~~ spc
spc[Secrets Provider Connection] --> pt
pt(["secret.PlainText()"]) --> ge(["os.GetEnv('MY_SECRET')"])
end
end
SDK -.- provision -.-> DaggerEngine
SDK -- GraphQL --> DaggerEngine
subgraph Docker
subgraph DaggerEngine
direction LR
subgraph GraphQLServer
gs[GraphQL Server] -- GraphQL to LLB --> LLB[LLB DAG]
LLB --- as(["llb.AddSecret( 'MY_SECRET' )"])
as ~~~ sa
sa[Session Attachable] ---> sp
sp[Secrets Provider] --> getSecret(["GetSecret('MY_SECRET')"])
end
GraphQLServer -- query gRPC --> BuildKit
subgraph BuildKit
bk[BuildKit]
end
GraphQLServer -- session connection --- BuildKit
BuildKit -- inject secrets from\n provider as file mounts --> Containers
subgraph Containers
c1[Container 1] --> c2[Container 2]
end
end
end
SDK == secrets provider session attachable connection === DaggerEngine
2nd Graph: GraphQL server in the SDK/Client
Details
graph TD
subgraph Host
direction LR
subgraph UserCode[User Code]
direction TB
code --> wev(["WithEnvironmentVariable('MY_SECRET')"])
end
wev --> gqlbuilder
subgraph SDK
direction TB
gqlbuilder[GraphQL query builder]
gqlbuilder -- build query --> gs
subgraph provisioner
end
subgraph GraphQLServer
gs[GraphQL Request] -- GraphQL to LLB --> LLBDAG{{LLB DAG}}
end
subgraph DaggerSession
bkgwClient[BuildKit Gateway client]
sa[Session Attachable] --- sp
sp[Secrets Provider] --> getSecret(["GetSecret('MY_SECRET')"])
getSecret --> pt
pt(["secretIDPayload{FromHostEnv: 'MY_SECRET'}.PlainText()"]) --> ge(["os.GetEnv('MY_SECRET')"])
end
end
end
bkSession -- "session connection (gRPC)" --- sa
provisioner -- provision --> DaggerEngine
subgraph Docker
subgraph DaggerEngine
direction LR
subgraph BuildKit
bkSession[Session]
solver
bkgwClient -- "query (gRPC)" --> bkSession
bkSession --> llbDAG{{"LLB DAG"}}
LLBDAG --> bkgwClient
llbDAG --> as(["llb.AddSecret( 'MY_SECRET' )"])
as -- GetSecret --> sp
end
ge ---> solver
solver -- inject secrets from\n provider as file mounts --> Containers
subgraph Containers
c1[Container 1] --> c2[Container 2]
end
end
end
Is the Dagger Session in the SDK client or in a container
dagger session is a (hidden) subcommand of our CLI. So the way it works is the SDK either finds a pre-existing CLI and uses that or it defaults to downloading one to ~/.cache/dagger and using that. It then invokes dagger session as a child process and communicates w/ it over localhost.
Related: Is the session attachable client-side or server-side? GraphQL Client? Or BuildKit Client?
Session attachables are implemented on the client-side. They are basically a way of allowing buildkit to reach back to the client and ask for something (secrets, a local dir sync, unix socket forward, etc.)
Are the Secrets fetched from the host or from buildkit?
They're fetched from the client, so the host that the client is on
How does the secret provider communicate with the host?
through the session attachable, via dual-direction gRPC connection? With some sort of callback?
Yes, session attachables work vi some grpc magic in the buildkit client code that creates a channel where buildkit can make requests to the client.
Note, I gave this design proposal a nickname ("in-memory secret store") to make it easier to distinguish from other design proposals for handling dynamic secrets. See #4426 (this issue is listed as "option B").
My 2c, the original name made more sense to me. This one implies a specific secret provider implementation, which wasn't the intent when @jlongtine opened it.
My 2c, the original name made more sense to me. This one implies a specific secret provider implementation, which wasn't the intent when @jlongtine opened it.
The problem is that we have several possible ways of "creating a new secret via the API", and we need a way to distinguish them. Right now we have "in-memory store" (store the value of the secrets in memory) + "helpers" (retrieve the value of secrets from helpers). What names did you have in mind?
We have reached consensus on another design for implementing dynamic secrets (this is "option A"; we are going for "option D"). I am closing this to reflect the decision.
Activity
jlongtine commentedon Oct 26, 2022
@vito mentioned #3124
samalba commentedon Nov 2, 2022
Discussed this briefly with @aluzzardi today to gather context and unblock @jlongtine.
Looks like there are two options:
I guess option 2 is more viable to unblock dagger-cue, depending on the effort for option 1. If we go option 2, we should find a way to derisk, for instance hiding the call behind a feature flag (eg. if this weird env var isn't set, the code path is disabled).
Would it be possible for @sipsma or @vito to own this one? Note that I am not hinting any option here, the priority is to remove the blocker. There might be an option 3 that I don't see.
sipsma commentedon Nov 2, 2022
@jlongtine how absurd and awful of an idea is this: you currently can load secrets from env vars, so whenever you need to load a secret in dagger-cue you export an env var and then use that to load the secret in? Would need to be careful if
dagger-cueever forks off child processes of course. But could be a path to avoiding any changes to the API if it's plausible.shykes commentedon Nov 2, 2022
Maybe we should revisit the “no direct creation of secrets” rule, in case the circumstances have changed?
The initial motivation for “no direct creation” was to:
One major change is that we plan on making the engine remote; and our understanding of IDs and their role has evolved. So maybe it’s OK to create secrets directly after all?
TLDR my first guess would be either option 2 (hidden api call) or “option 2+” (regular api call). Skeptical about option 1 because it means rushing a pretty big design discussion for a short term problem.
aluzzardi commentedon Nov 2, 2022
I'd prefer we don't rush into neither Option 1 (needs design) nor Option 2+ (ripple effects, not easily reversible). @vito is going to post a summary of Option 3 (do nothing in core, work around with the existing API)
vito commentedon Nov 2, 2022
You can actually create in-memory secrets already in a kind of round-about way:
Caveat: this will result in a
SecretIDthat embeds the secret value in plaintext (albeit obfuscated below multiple layers of base64 ✨ security ✨). But maybe that's enough for now? As long as theSecretIDitself isn't leaked this should still accomplish the goal of keeping its value out of the container layers.This feels roughly the same level of risk as option 2 or introducing a dedicated "create secret" API, but the benefit is it already exists.
If you want to avoid leaking values into the
SecretIDyou could instead leak them to the host filesystem and clean them up after:For extra pizazz you could try using a fifo/pipe instead but we're skeptical that'll actually work. :P
Alternatively you could use env vars, but that's pretty sketchy too.
Between these two my preference would be the first one, since it's essentially what this issue proposes but feels like a workaround (which really it is).
shykes commentedon Nov 2, 2022
If I understand correctly, Option 3 would be basically "all userland", no new API call either private or public? If so, that would be an ideal short term solution :)
Thanks for the additional details.
jlongtine commentedon Nov 2, 2022
@sipsma I've heard worse ideas in my time. :)
I think I'm going to start with this... see if works out, then move onto one of @vito's suggestions if it doesn't for whatever reason.
I appreciate you all digging into this with/for me!
jlongtine commentedon Nov 4, 2022
An update: Using environment variables works! I've got that all up and running, and it unblocked me on a bunch of stuff. Thanks for all the help, everyone!
jlongtine commentedon Dec 7, 2022
I had a good discussion today with @sipsma and @vito about this.
Our proposal as a first pass (with subsequent designs for extensions, etc) is to add a GraphQL API to allow the creation of new Secrets. This will add those secrets to the
secret.Store, and allow for retrieval by Buildkit.Everything feels pretty solid on implementation, but we still have some open questions around the API.
API Design
I had previously suggested one or the other of these:
With the following behavior:
@sipsma Also suggested this as a possibility:
which would allow queries like:
@shykes, @aluzzardi Do you like either of these, or have any other ideas for this API?
7 remaining items
vito commentedon Dec 8, 2022
Also just realized this is actually an argument in favor of
withSecret(#3442 (comment)) since I wouldn't need to carefully ensure secret names don't collide in shared session state with a long-lived client.shykes commentedon Dec 14, 2022
Here's my proposal: #4193
dolanor commentedon Dec 14, 2022
I don't have a lot of knowledge on BuildKit secret management. @jlongtine helped understand better but I feel I'm still not completely sure how it works.
I spent some time today in creating some diagram to share and be able to have feedback on my comprehension.
I had a first diagram that I presented to @jlongtine again.
(somehow, the mermaid interpreter from GitHub can't parse the code, so I put it in the annex)
So I thought the
dagger-sessionwould completely run in the Docker container, with thegraphql serveras well. But @jlongtine told me that thegraphql serverruns in the SDK (from the provisionning logic).So the connection between the SDK and the Dagger Engine is not GraphQL based, but more gRPC for BuildKit Gateway?
Then, the graph would look like that:

So my questions are:
dagger-engine-sessioncontainer back in the old days, like, last week)session attachableclient-side or server-side? GraphQL Client? Or BuildKit Client?Annex: mermaid code
1st Graph: GraphQL Server in the Dagger Engine
Details
2nd Graph: GraphQL server in the SDK/Client
Details
sipsma commentedon Dec 19, 2022
@dolanor
The second diagram is pretty much spot-on 👍
dagger sessionis a (hidden) subcommand of our CLI. So the way it works is the SDK either finds a pre-existing CLI and uses that or it defaults to downloading one to~/.cache/daggerand using that. It then invokesdagger sessionas a child process and communicates w/ it over localhost.Working on documenting all this as part of: #4215
Session attachables are implemented on the client-side. They are basically a way of allowing buildkit to reach back to the client and ask for something (secrets, a local dir sync, unix socket forward, etc.)
They're fetched from the client, so the host that the client is on
Yes, session attachables work vi some grpc magic in the buildkit client code that creates a channel where buildkit can make requests to the client.
[-]Support the creation of new Secrets via the API[/-][+]In-memory secret store[/+]shykes commentedon Jan 20, 2023
Note, I gave this design proposal a nickname ("in-memory secret store") to make it easier to distinguish from other design proposals for handling dynamic secrets. See #4426 (this issue is listed as "option B").
samalba commentedon Jan 24, 2023

My 2c, the original name made more sense to me. This one implies a specific secret provider implementation, which wasn't the intent when @jlongtine opened it.shykes commentedon Jan 24, 2023
The problem is that we have several possible ways of "creating a new secret via the API", and we need a way to distinguish them. Right now we have "in-memory store" (store the value of the secrets in memory) + "helpers" (retrieve the value of secrets from helpers). What names did you have in mind?
[-]In-memory secret store[/-][+]Proposal: in-memory secret store for dynamic secrets[/+]shykes commentedon Feb 27, 2023
We have reached consensus on another design for implementing dynamic secrets (this is "option A"; we are going for "option D"). I am closing this to reflect the decision.