Skip to content

docs: Added guide for secrets - #4822

Merged
vikram-dagger merged 32 commits into
dagger:mainfrom
vikram-dagger:1971-secrets-guide
Mar 30, 2023
Merged

vikram-dagger merged 32 commits into
dagger:mainfrom
vikram-dagger:1971-secrets-guide

Conversation

@vikram-dagger

Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels quite clunky. Is there a better way? @dolanor

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What feels clunky?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the code example feels clunky?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because we are reading the file into a string, then writing the string back to a file.

@dolanor dolanor Mar 28, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree.
I hope I can fix file.secret, then, it would feel more natural: file -> file.
But for now, it is best used with setSecret.
A good example could be to get some secret SSH key from a Vault for example to be able to push a commit via git.
So you would access vault, get the SSH key out of it, create a secret out of it with setSecret and mount it as a file on the container that would do a git push to some ulterior git repository that handles deploy, for example.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should ask @jpadams if he has some users that have some workflow using git in later pipeline stage?

@vikram-dagger
vikram-dagger requested a review from dolanor March 23, 2023 16:35

@dolanor dolanor left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the setSecret API so we could avoid leaking plaintext info with the file.Secret() API.
I believe there is a way we could actually make it safe and make it a 1st level API again.
This guide would be impacted, but it can come in an ulterior update as this one is already good and could be published as is as I haven't fixed the file.Secret() implementation yet.

The other BIG advantage of using setSecret is that we don't have to pass by the hostenv or file. It allows us to fetch secrets from external system (like Vault, GCP secret manager, etc).
I think an example using that would be more interesting.
I created a demo with that here: https://github.com/dolanor/demos/blob/main/secret/gcp/main.go
I asked @kpenfound if he could help creating some extra demos (Vault being the priority IMHO)

I think having some sort of table showing what API happens on the host vs what API happens on the pipeline could also help.

medium host pipeline
file file.secret() WithMountedSecret
env host.EnvVariable() WithSecretVariable
any setSecret()

Also, indicating that once something is a secret, it can be a file (mounted secret) or a secret env (secret variable), wherever it came from. Maybe a diagram could help? (feel free to modify this one or create a new one altogether 😄 )

flowchart LR
    subgraph pipeline
        p([container])
        p --> ms[mounted secret]
        p --> es[env secret]
    end
    subgraph Host
        he[host.envVariable.secret] -->|secret| p
        fs[file.secret] -->|secret| p
        ss(setSecret) -->|secret| p
    end
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the code example feels clunky?

@vikram-dagger

Copy link
Copy Markdown
Contributor Author

@dolanor dolanor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work. The last part is the table that would need fixing because I think it might confuse people that only 1 "host" API can only inject in 1 "pipeline" API: file -> file, env -> env. But as long as it is a secret, it can be an env or a mounted secret.

@vikram-dagger

Copy link
Copy Markdown
Contributor Author

@dolanor does the change suggested in #4822 (comment) block merge?

Vikram Vaswani and others added 16 commits March 29, 2023 18:52
Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: vikram-dagger <[email protected]>
Co-authored-by: Tanguy ⧓ Herrmann <[email protected]>
Signed-off-by: vikram-dagger <[email protected]>
Signed-off-by: vikram-dagger <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
Co-authored-by: Helder Correia <[email protected]>
Signed-off-by: vikram-dagger <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: Tanguy ⧓ Herrmann <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
dolanor and others added 4 commits March 29, 2023 16:42
Signed-off-by: Tanguy ⧓ Herrmann <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
@helderco

Copy link
Copy Markdown
Contributor

@vikram-dagger There were more instances of the indented print nit. I usually only comment on one.

dolanor and others added 2 commits March 29, 2023 23:04
Co-authored-by: Helder Correia <[email protected]>
Signed-off-by: Tanguy ⧓ Herrmann <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
@vikram-dagger

Copy link
Copy Markdown
Contributor Author

@vikram-dagger There were more instances of the indented print nit. I usually only comment on one.

@helderco corrected, please re-check and approve if OK

Signed-off-by: vikram-dagger <[email protected]>

@helderco helderco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this 🙌

Just a few quick fixes.

@dolanor

dolanor commented Mar 30, 2023

Copy link
Copy Markdown
Contributor

I'm gonna fix the snippets.
cc @vikram-dagger

dolanor and others added 4 commits March 30, 2023 14:03
Co-authored-by: Helder Correia <[email protected]>
Signed-off-by: Tanguy ⧓ Herrmann <[email protected]>
Signed-off-by: Tanguy ⧓ Herrmann <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: Tanguy ⧓ Herrmann <[email protected]>
@dolanor

dolanor commented Mar 30, 2023

Copy link
Copy Markdown
Contributor

I rephrased the explanations but mostly removed the reference to Secret() is it was that part that was leaking and that we replaced with setSecret.

@dolanor
dolanor requested a review from helderco March 30, 2023 13:35
Modified secret URI (all).

Signed-off-by: Vikram Vaswani <[email protected]>
@vikram-dagger
vikram-dagger merged commit 8a6c8e2 into dagger:main Mar 30, 2023
@gerhard

gerhard commented Apr 3, 2023

Copy link
Copy Markdown
Contributor

This was such a big & important group effort - well done for shipping it! 🚀

https://docs.dagger.io/723462/use-secrets/ reads really well. I especially liked the multi-language aspect of it. This must have been the hardest part to get right. It's great to see so much valuable information in a single place, for all SDKs!

A couple of thoughts:

  1. We should emphasise that WithSecretVariable doesn't end in the container image history, or the final layer. WithEnvVariable does, and sometimes a regular env variable that should not stick around (maybe because that container will be published) should be declared via WithSecretVariable instead. I hit this problem a few weeks ago: thechangelog/changelog.com@0aa5e6d

  2. We should caution users against using WithEnvVariable for secrets. I mention this because it is the common way of using secrets in GitHub Actions. We do too, e.g.

    - name: "Publish Engine & CLI"
    env:
    GITHUB_TOKEN: ${{ secrets.RELEASE_DAGGER_CI_TOKEN }}
    DAGGER_ENGINE_IMAGE: ${{ secrets.RELEASE_DAGGER_ENGINE_IMAGE }}
    AWS_ACCESS_KEY_ID: ${{ secrets.RELEASE_AWS_ACCESS_KEY_ID }}
    AWS_SECRET_ACCESS_KEY: ${{ secrets.RELEASE_AWS_SECRET_ACCESS_KEY }}
    AWS_REGION: ${{ secrets.RELEASE_AWS_REGION }}
    AWS_BUCKET: ${{ secrets.RELEASE_AWS_BUCKET }}
    ARTEFACTS_FQDN: ${{ secrets.RELEASE_FQDN }}
    HOMEBREW_TAP_OWNER: ${{ secrets.RELEASE_HOMEBREW_TAP_OWNER }}
    GORELEASER_KEY: ${{ secrets.GORELEASER_PRO_LICENSE_KEY }}

Leaving this with you @dolanor @vikram-dagger @d3rp3tt3 @mircubed

@dolanor

dolanor commented Apr 3, 2023

Copy link
Copy Markdown
Contributor

We talked about it in our 1on1, and you clearly have a point as people come with this new tool with assumption that might be wrong based on their experience with Docker or Kubernetes. Build Secrets from Buildkit don't leave any trace, either as secret variables or as secret env. Not in the build history, nor in the image itself, nor in the cache.
We should update the guide to reflect that, I agree.

And the idea to also put some env variable as secrets because we don't want them to stick around in the image is a good idea.
I wonder, though, if a simple withoutEnvVariable would work enough for the final image. Maybe it would leave a trace in the build history, and it's already too much information. I'll explore that as well.

cc: @vikram-dagger

@vikram-dagger
vikram-dagger deleted the 1971-secrets-guide branch April 6, 2023 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants