Skip to content

Dagger prints my secrets when it crashes #4339

Closed

Description

@rawkode

What are you trying to do?

At the moment, we can mark things as sensitive ONLY from environment variables that exist before the Dagger client is created.

We do this with: client.host().envVariable("X").secret()

In a mono-repository environment, or any environment where more than a single secrets backend is used - this can be rather difficult to orchestrate. Do we blanket make every secret available before we run, or can we do this smarter?

I've tried two approaches.

  1. Container Based Fetch
  2. Host Based Fetch

Container Based Fetch

This was my first approach. Dagger can run containers really well, so let's run a Doppler container that can fetch secrets dynamically. We provide a single ENV on the host, the DOPPLER_TOKEN, and we provide a helper function that can getSecrets("project", "environment");

This works very well, but unfortunately there's no API with Dagger to mark a value as sensitive. We can mark a file from a container as sensitive, but in this particularly use-case that file is actually a collection of secrets that are used independently (I run JSON.parse on the value) meaning we lose the sensitivity of each unique secret when used in isolation.

Desire an API to dynamically mark individual values as sensitive would be ideal for this use-case.

Host Based Fetch

After discussions with the Dagger team, it was actually determined that we shouldn't fetch these secrets within a container - as it leaves stuff around in the build cache. We should leverage Dagger's native-code abilities to run commands on the host and then push secrets into Dagger.

I agree this is the preferred approach and is what I do now. It works great .. until it doesn't.

Challenge

When Dagger crashes, it currently dumps the world into STDOUT/STDERR. This has printed by GCP's credentials to GitHub Actions MANY times now.

With either approach, it's become very apparent that we need the ability to client.makeSecret like we could with the CUE API.

Reference Dagger code: https://github.com/RawkodeAcademy/RawkodeAcademy. See:

Why is this important to you?

I don't want to rotate my credentials every time Dagger pipeline crashes when run on GitHub Actions

How are you currently working around this?

Only running Dagger locally on my machine

Activity

  1. shykes commented on Jan 9, 2023

    @shykes
    Contributor

    After discussions with the Dagger team, it was actually determined that we shouldn't fetch these secrets within a container - as it leaves stuff around in the build cache

    Shouldn't we discuss how to fix that? So far I'm seeing much discussion of rushing to a new API because of a security defect in the current one. It seems to me that we should first explore the possibility of making it safe to create a secret from a container - thus fixing your problem AND removing a defect in our current API.

    cc @jlongtine @aluzzardi @sipsma

  2. rawkode commented on Jan 9, 2023

    @rawkode
    ContributorAuthor

    I'm not sure, actually. Especially as remote caching becomes more of a thing later - there's a lot of security posture-benefits that come from controlling the execution of the Dagger pipeline and pushing more sensitive stuff there, while leaning on the container workloads for the grunt-work.

    const client = createClient();
    
    const secretThings = localExecutingSecretThing();
    
    client.markSensitive(secretThings);
    
    client.run(remoteBuildStuff({
      secrets: secretThings
    });

    I think this pattern leverages the benefits of Dagger's new native code possibilities. Sure, I can run a container that speaks to Vault or Doppler, but I think this is cleaner. If I control the local execution I can restrict API access to secrets with a static IP of the runner, but still offload all the boring work to build farms.

    I agree that you shouldn't rush into a new API, but I do think it should be possible (in any situation) to mark a value as sensitive and make it available to container based workloads.

  3. rawkode commented on Jan 9, 2023

    @rawkode
    ContributorAuthor

    If it helps, my pipelines with earthly.dev work in a pretty nice fashion. Perhaps some inspiration could come from there?

    build:
      FROM terraform:latest
      RUN --secret "studio:FIREBASE_TOKEN" terraform apply

    This --secret "studio__FIREBASE_TOKEN" gets sent to a local credential helper that I write myself which splits the string on "studio__FIREBASE_TOKEN" and runs, locally, doppler secrets get --project studio --plain FIREBASE_TOKENand then mounts it into the container with--mount=type=secret` etc

    The API I'm suggesting would be to allow:

    client.makeSecret("ID", "VALUE");

    Dagger ALREADY provides these APIS:

    client.container().from().withSecretVariable("ID", "ENVIRON_NAME_IN_CONTAINER");
    client.container().from().withMountedSecret("ID", "/tmp/secret.json");

    But we don't have the ability to mark things as sensitive, and I think that's important.

  4. changed the title [-]✨ Dynamic Secrets API[/-] [+]Dagger prints my secrets when it crashes[/+] on Jan 19, 2023
  5. shykes commented on Jan 19, 2023

    @shykes
    Contributor

    @rawkode I took the liberty of editing your issue's title, to reflect the gist of your feedback / complaint. I hope you don't mind. This is to help organize and navigate our growing collection of issue-related issues.

  6. mircubed commented on Feb 6, 2023

    @mircubed
    Contributor

    @samalba will review this issue to ensure that it is solved with the solutions from #4413

  7. mircubed commented on Feb 25, 2023

    @mircubed
    Contributor

    @samalba @dolanor can you review this one to see if #4413 solves it? If so, can you close this one?

  8. samalba commented on Feb 27, 2023

    @samalba
    Contributor

    Given that part of the original issue is related to dynamic secret support, let's keep this open until #4426 is closed.

  9. mircubed commented on Mar 28, 2023

    @mircubed
    Contributor

    @dolanor since #4426 is closed, can we close this one as well?

  10. dolanor commented on Mar 30, 2023

    @dolanor
    Contributor

    Yes, I think this has been fixed.
    If it's still doesn't meet your requirement, @rawkode , don't hesitate to reopen and tell us why :)

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