Skip to content

Implement ability for run-task to fetch secrets - #1110

Open
ahal wants to merge 3 commits into
taskcluster:mainfrom
ahal:ahal/krpvwwsmzzts
Open

ahal wants to merge 3 commits into
taskcluster:mainfrom
ahal:ahal/krpvwwsmzzts

Conversation

@ahal

@ahal ahal commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@ahal ahal self-assigned this Nov 13, 2026
@ahal
ahal requested a review from a team as a code owner November 13, 2026 15:06
@ahal
ahal requested a review from jcristau November 13, 2026 15:06
@ahal
ahal force-pushed the ahal/krpvwwsmzzts branch from 276e1ca to 1f70b10 Compare November 13, 2026 15:06
ahal added 3 commits November 13, 2026 10:15
A RUN_TASK_SECRETS entry of type 'secret' fetches a secret from Taskcluster's
secrets service. It exports the secret, or one of its keys, to an environment
variable, or writes it to a file only the task's user can read. Unlike
github-repo-token, a failure to fetch the secret fails the task, since a task
that asks for a secret can't do without it.
Tasks using the run transforms can list secrets for run-task to fetch in a
'secrets' key, rather than writing RUN_TASK_SECRETS by hand. The new
use_secrets transform serializes the list into RUN_TASK_SECRETS, adds the
scopes each secret needs, and enables the taskcluster proxy. A
github-repo-token's repo defaults to the base_repository parameter.
The codecov and push-image tasks fetched their secrets themselves. List
them in 'secrets' instead, so run-task fetches them and the transforms add
the scopes. The codecov uploader now reads its token from CODECOV_TOKEN.
push-image gets its auth file written by run-task, which also fixes a
fetch failure going unnoticed until skopeo tried to use the bad file.
@ahal
ahal force-pushed the ahal/krpvwwsmzzts branch from 1f70b10 to f84bc03 Compare November 13, 2026 15:16
The environment variable to export the secret in.
``file``
The file to write the secret to. Relative paths are relative to the
task's working directory. Missing parent directories are created, and on

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.

Is there a potential conflict here?
If the secret is fetched into the same path as the checkout, and happens before checkout, would the checkout fail? Should we add a check for this? (Seems corner case AND self-inflicted, but still)

``name`` (required)
The name of the secret.
``env``
The environment variable to export the secret in.

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.

Does this override anything set in worker.env? Should we mention it here?

print_line(b"secrets", f"fetched secret {name}\n".encode())
value = value if isinstance(value, str) else json.dumps(value)
if path is not None:
_write_secret_file(path, value)

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.

if for some reason the write fails half way thru, this will be a problem.

We should attempt to delete the file on any write failures.

Use Secrets
===========

Tasks often need secrets such as an API tokens or private keys. Taskgraph can

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.

nit: either "..such as API tokens.." or "..such as an API token or private key."

This branch has not been deployed

No deployments
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.

2 participants