Skip to main content

Secrets

Dagger supports the use of confidential information, such as passwords, API keys, SSH keys, access tokens and so on, in your pipelines. These "secrets" can be sourced from different secret providers and passed to Dagger Functions as arguments.

Dagger supports multiple secret providers. It can securely read secrets from the host environment, the host filesystem, the result of host command execution, and external secret managers 1Password and Vault.

Dagger has built-in safeguards to ensure that secrets are used without exposing them in plaintext logs, writing them into the filesystem of containers you're building, or inserting them into the cache. This ensures that sensitive data does not leak - for example, in the event of a crash.

Here's an example of a pipeline that receives and uses a GitHub personal access token as a secret:

package main

import (
"context"
"dagger/my-module/internal/dagger"
)

type MyModule struct{}

func (m *MyModule) GithubApi(
ctx context.Context,
token *dagger.Secret,
) (string, error) {
return dag.Container().
From("alpine:3.17").
WithSecretVariable("GITHUB_API_TOKEN", token).
WithExec([]string{"apk", "add", "curl"}).
WithExec([]string{"sh", "-c", `curl "https://api.github.com/repos/dagger/dagger/issues" --header "Accept: application/vnd.github+json" --header "Authorization: Bearer $GITHUB_API_TOKEN"`}).
Stdout(ctx)
}

The secret can be passed from the host environment via the env provider:

Secret from environment

Secrets can also be passed from host files via the file provider (shown below) or from host command output via the cmd provider:

Secret from file

Secrets can also be read from external secret managers, such as Vault (vault):

dagger call github-api --token=vault://credentials.github

...or 1Password (op):

dagger call github-api --token=op://infra/github/credential

Secret from 1Password

Learn more