Skip to content

Dynamic secrets #4426

Closed
Closed

Description

@shykes

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, age or sops
  • 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.

  • SecretID is a human defined secret key (just like a CacheID)
    • 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
  • 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)
  • Potentially deprecate Host.Env.Secret and Host.Directory.File.Secret
    • As they would become unnecessary
    • e.g. Host.Env.Secret can 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
A Make current API safe No new API Possibly surprising caching behavior; possible edge cases in implementation; possible friction of having to run everything in containers
B New API: in-memory secret store Full control for developers; unblocks CUE SDK compatibility bridge More work for developers; ecosystem fragmentation; frustrating OX; secrets leak into IDs
C New API: secret helpers 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

See also

A list of requested improvements to secret support

Activity

  1. shykes commented on Jan 20, 2023

    @shykes
    ContributorAuthor

    Update on my preference:

    • Initially my preference was to focus on option A (making the current API safe) in the short term, and buy ourselves some time to choose between B and C later.
    • After more study and discussion with @sipsma, I now think we should go straight to option C (secret helpers), and deprecate File { secret } rather than hacking our way to a safe implementation.
  2. shykes commented on Jan 20, 2023

    @shykes
    ContributorAuthor
  3. mircubed commented on Feb 7, 2023

    @mircubed
    Contributor

    @samalba @shykes - can you clarify what next step is needed here to decide which solution we go with?

  4. mircubed commented on Feb 8, 2023

    @mircubed
    Contributor

    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? "

  5. jpadams commented on Feb 9, 2023

    @jpadams
    Contributor

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

  6. shykes commented on Feb 18, 2023

    @shykes
    ContributorAuthor

    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.

  7. aluzzardi commented on Feb 21, 2023

    @aluzzardi
    Contributor

    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

    • SecretID is a human defined secret key (just like a CacheID)
      • 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
    • 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)
    • Potentially deprecate Host.Env.Secret and Host.Directory.File.Secret
      • As they would become unnecessary
      • e.g. Host.Env.Secret can 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)
  8. jlongtine commented on Feb 21, 2023

    @jlongtine
    Contributor

    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!

  9. dolanor commented on Feb 22, 2023

    @dolanor
    Contributor

    @jlongtine I'm down!

  10. dolanor commented on Feb 22, 2023

    @dolanor
    Contributor

    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?

  11. aluzzardi commented on Feb 22, 2023

    @aluzzardi
    Contributor

    For File.Secret() deprecation, I propose that even the logic is removed and we always return an error if people use it?

    There's a @deprecated annotation 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.

  12. dolanor commented on Feb 23, 2023

    @dolanor
    Contributor

    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.

  13. shykes commented on Feb 27, 2023

    @shykes
    ContributorAuthor

    Here's option D:

    Thanks for taking care of the writeup @aluzzardi !

    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.

    This is why this option is superior IMO. Instead of choosing between "correct" and "fast", we get the benefits of both.

    • A simple API, with a simple implementation, that gives the community what it needs now (the ability to create secrets programmatically)
    • A path to adding a very important, but less urgent feature (a standard secrets provider API) later, without painful breaking changes

    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.

  14. shykes commented on Feb 27, 2023

    @shykes
    ContributorAuthor

    I updated the top comment to reflect the selected design.

  15. linked a pull request that will close this issuefeat: add dynamic secret API #4667on Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions