Use secrets in workflows
This guide shows how to pass a secret's value to a task without writing it in the workflow file, check that the value is masked in the task's log, and override an account secret for one project.
Pass a secret to a task
-
Create the secret, as a project secret in the project that runs the workflow or as an account secret that allows that project. See Manage project secrets or Manage account secrets.
-
In the workflow, name the secret as
${{secrets.<name>}}in the argument of the task that needs it:blocks:main:tasks:upload:name: Uploadargs:api_key: ${{secrets.UPLOAD_API_KEY}}bucket: ${{inputs.bucket_name}} -
Upload the workflow and start a run, as in Create and manage workflows and Start and manage workflow runs.
The secret's value is read when the upload task starts, so a run uses the value the secret holds at that moment. A secret that does not exist, or an account secret that does not allow the project, gives the argument an empty value; the run is not refused. Secrets in the expression language reference gives the exact rules.
Check that the value is masked
Open the task's log, as in View and stream task logs. Its first entry lists the arguments the task was given, with the secret's value shown as ***, and the task's own output shows *** wherever it prints the value exactly as stored.
Only exact occurrences of the value are masked, so a secret your task transforms (base64-encodes, splits, re-encodes) can appear in the log. See How secrets are masked in logs for what is and isn't caught.
Override an account secret for one project
Create a project secret with the same name as the account secret, in the project that needs a different value. Runs in that project use the project secret; runs in the other projects the account secret allows keep using the account secret. Delete the project secret to go back to the account secret.
Next steps
- Secrets also hold the credentials a task's image is pulled with: Use a task image from a private registry
- Secrets
- Secrets in the expression language