feat: Add action to get short-lived access token using OIDC#255
Conversation
| }, | ||
| body: JSON.stringify({ | ||
| oidcToken: OIDC_TOKEN, | ||
| targetRepo: GITHUB_REPOSITORY, |
There was a problem hiding this comment.
Should we add the repository as an input to this action in case a workflow needs access to a different one? For example, the extension has a workflow that pushes commits to the metamask-extension-ts-migration-dashboard repo (https://github.com/MetaMask/metamask-extension/blob/b393e3f210b55756508c507cbd0920e7951dc281/.github/workflows/build-ts-migration-dashboard.yml#L42). I believe it uses a metamaskbot token but we might eventually want to use this action.
There was a problem hiding this comment.
Sure, makes sense. I've added an option target-repository which defaults to github.repository (i.e., the current repository).
| script: | | ||
| const token = await core.getIDToken('api://token-exchange-service'); | ||
| core.setSecret(token); | ||
| core.setOutput('token', token); |
There was a problem hiding this comment.
Why save the token to outputs in this step?
There was a problem hiding this comment.
This is the OIDC token used to request the access token in the second step. It's referenced below:
OIDC_TOKEN: ${{ steps.oidc-token.outputs.token }}In case you're confused about the core.setSecret above, that's actually just the add-mask workflow command and doesn't actually set a secret.
There was a problem hiding this comment.
Ah I see, thanks for the clarification.
This adds a workflow to get a short-lived GitHub access token using
token-exchange-service. Example workflow below:Note
Medium Risk
Introduces a CI path that mints GitHub tokens with caller-chosen permissions; misuse or overly broad scopes in consuming workflows could expand blast radius, though tokens are short-lived and the action itself is additive.
Overview
Adds a new reusable composite GitHub Action Get Token (
.github/actions/get-token) so workflows can obtain short-lived GitHub API access tokens via OIDC and an external token exchange service instead of long-lived PATs.The action requests an OIDC token (
api://token-exchange-service), POSTs it to{token-exchange-url}/api/exchange/tokenwith newline-parsedscope: permissionpairs and an optional target repo, then exposes the returned token as a step output (masked withcore.setSecret). Callers must grantid-token: writeon the job.Reviewed by Cursor Bugbot for commit 8bfb594. Bugbot is set up for automated code reviews on this repo. Configure here.