Repository navigation
Description
Problem
Dagger can safely load static secrets, by accessing a snapshot of the client's environment variables. But there is no safe way do load dynamic secrets. This limits the use of Dagger in production.
In this context, a dynamic secret is a secret that requires executing arbitrary code in order to be retrieved. Examples of dynamic secrets include:
- Secrets stored in an encrypted file, that must be loaded with a tool such as
gpg,ageorsops - Secrets stored in a secret store service, such as Hashicorp Vault, Doppler, Pulumi, etc.
Note that the Dagger API does have a way to load dynamic secrets: File { secret }, but it [carries security risk](, so we don't consider it to be a complete solution unless it can be made 100% safe. See #4403
Solution
Implement a safe way to load dynamic secrets.
Design
A design has been selected. In summary: Change Secret API to ressemble Cache API
The intent is to have the layer of indirection the "secret helpers" would provide while keeping the implementation simplicity of "in-memory secret store".
In other words, it's a simple API call to add a secret, yet we leave the door open to move secrets to extensions in the future.
SecretIDis a human defined secret key (just like aCacheID)- It's not plaintext and it's not a digest
- It is the caller that sets the key
- Provide an API call to map the secret key to plaintext secret
- Very similar to Proposal: in-memory secret store for dynamic secrets #3442
- However, rather than returning a
SecretIDin exchange for a "plaintext", user would provide a mapping of key<->plaintext
- To maintain current cache behavior (e.g. rotating a secret will invalidate cache), engine should keep a 3 way mapping:
- SDKs refer to secrets by key to the engine API (e.g.
aws-access-key) - Engine sends secrets as digests in LLB (for caching purposes)
- SDKs refer to secrets by key to the engine API (e.g.
- Potentially deprecate
Host.Env.SecretandHost.Directory.File.Secret- As they would become unnecessary
- e.g.
Host.Env.Secretcan be written as (pseudo code)c.SetSecret("aws-access-key", os.Getenv("AWS_ACCESS_KEY"))
- Deprecate
Container().File().Secret()because it's insecure (leaves secret in cache)
Alternative design options
4 design options have been considered: A, B, C and D. Option D has been selected.
See the comparison table below:
| Option | Description | Advantages | Disadvantages |
|---|---|---|---|
| No new API | Possibly surprising caching behavior; possible edge cases in implementation; possible friction of having to run everything in containers | ||
| Full control for developers; unblocks CUE SDK compatibility bridge | More work for developers; ecosystem fragmentation; frustrating OX; secrets leak into IDs | ||
| Full control for operators; less work for developers; unified ecosystem; easy implementation | Less control for developers (until we ship containerized helpers); requires shipping new CLI features (config file) | ||
| D | Change Secret API to ressemble Cache API | (1) a simple API, with a simple implementation, that gives the community what it needs now (the ability to create secrets programmatically); (2) a path to adding a very important, but less urgent feature (a standard secrets provider API) later, without painful breaking changes | No compatibility bridge for CUE SDK; improving OX is out of scope |
Activity
shykes commentedon Jan 20, 2023
Update on my preference:
File { secret }rather than hacking our way to a safe implementation.shykes commentedon Jan 20, 2023
FYI @samalba @aluzzardi @jlongtine @rawkode
mircubed commentedon Feb 7, 2023
@samalba @shykes - can you clarify what next step is needed here to decide which solution we go with?
mircubed commentedon Feb 8, 2023
Note that we have a user who asked " Actual we are using the AWS Secrets Manager. Yeah that is the question if is possible to integrate it with Dagger? "
jpadams commentedon Feb 9, 2023
Other user quotes (paraphrases):
"Being able to test and run secrets locally for dev is important."
"Need to support a lot of secrets managers to cover needs for the whole org, including Google Secrets Manager which is main one."
"Would prefer that dagger can connect to AWS directly for secrets rather than relying on CircleCI to provide those variables."
"Using HashiCorp Vault" multiple
"GitHub Actions and OIDC to AWS for short-lived secrets."
"Amazon secrets manager since they are an amazon shop, so it means they need to run one less thing."
multiple "Secrets are embedded in various CI solutions like GitHub Actions, CircleCI, Jenkins, Drone."
"Using SOPS for secrets in files in the repo."
"Need a way to allow users to inject their secrets easily."
shykes commentedon Feb 18, 2023
After a live discussion with @aluzzardi and @samalba, we may have a breakthrough :) Stand by for "option D" in the near future, @aluzzardi is writing it up somewhere.
aluzzardi commentedon Feb 21, 2023
Here's option D:
The intent is to have the layer of indirection the "secret helpers" would provide while keeping the implementation simplicity of "in-memory secret store".
In other words, it's a simple API call to add a secret, yet we leave the door open to move secrets to extensions in the future.
Summary: Change Secret API to ressemble Cache API
SecretIDis a human defined secret key (just like aCacheID)SecretIDin exchange for a "plaintext", user would provide a mapping of key<->plaintextaws-access-key)Host.Env.SecretandHost.Directory.File.SecretHost.Env.Secretcan be written as (pseudo code)c.SetSecret("aws-access-key", os.Getenv("AWS_ACCESS_KEY"))Container().File().Secret()because it's insecure (leaves secret in cache)jlongtine commentedon Feb 21, 2023
I like this option a lot, @aluzzardi. I think we should do it. :)
@dolanor I'd love to help figure this out! Let me know if you're down to chat about it!
dolanor commentedon Feb 22, 2023
@jlongtine I'm down!
dolanor commentedon Feb 22, 2023
For
File.Secret()deprecation, I propose that even the logic is removed and we always return an error if people use it?Should we include a link for some documentation when it will be available on how to use the new Secret API?
aluzzardi commentedon Feb 22, 2023
There's a
@deprecatedannotation we can use on the API for now. We should do that before removing the API altogether, so people have a chance to migrate away without breaking the API.dolanor commentedon Feb 23, 2023
I know about the deprecated (btw, it's soooo nice to just have everything generated for all the SDK with 1 line change in the graphql schema), but you're right about not wanting to break everything so soon. We could adopt this strategy later.
shykes commentedon Feb 27, 2023
Thanks for taking care of the writeup @aluzzardi !
This is why this option is superior IMO. Instead of choosing between "correct" and "fast", we get the benefits of both.
I am excited that we finally found a path forward, and can't wait to play with this feature :)
Thank you everyone for participating in this epic design discussion.
shykes commentedon Feb 27, 2023
I updated the top comment to reflect the selected design.