OIDC tokens for cloud access
A run can ask Forge for OIDC tokens: short-lived JSON Web Tokens that Forge signs for that run. A cloud that trusts your organization's issuer exchanges such a token for its own short-lived credentials. Your runs need no long-lived cloud keys stored as secrets.
The tokens work with AWS, Google Cloud, Azure, HashiCorp Vault and anything else that accepts OIDC federation with RS256.
In the run spec
Name each token and its audience under id_tokens, at most 5 per run:
image: amazon/aws-cli
id_tokens:
AWS_TOKEN:
audience: sts.amazonaws.com
command: [sh, -c, 'aws sts assume-role-with-web-identity --role-arn "$ROLE" --role-session-name forge --web-identity-token "file://$AWS_TOKEN"']
$AWS_TOKENis the path of a file holding the token,/run/forge-id-tokens/AWS_TOKEN, not the token itself. So the token doesn't end up in a process listing or a child's environment by accident.- A token lasts 10 minutes. While the run goes on, the runner replaces the file every 5 minutes
with a new token. Read the file each time you need a token; don't copy it once at the start.
Most cloud SDKs re-read a web identity token file by themselves (
AWS_WEB_IDENTITY_TOKEN_FILE, Google's external account credentials with afilesource). - The file is readable by the run's user, in a small in-memory directory. It never reaches a disk.
- In the run form, the OIDC tokens field takes one
NAME=audienceper line.
Containers, VMs and compose runs all get the directory. In a compose run, mount it into the services that need it:
services:
deploy:
image: amazon/aws-cli
volumes: ["/run/forge-id-tokens:/run/forge-id-tokens:ro"]
environment: [AWS_WEB_IDENTITY_TOKEN_FILE=/run/forge-id-tokens/AWS_TOKEN]
Who gets tokens
- A run gets tokens only when it would get secrets. A run of a pull request from a fork waits for approval and gets neither. Its page names the tokens as withheld.
- A run file from a repository (a trigger's
.forge/file, a generated flow) may only ask for the audiences its trigger allows: Allowed OIDC token audiences on the trigger, orallowed_id_token_audienceson a flow step. Templates and runs started through the API or the CLI aren't limited. See Git. - Runs with tokens are placed like runs with secrets: on the organization's own runners, or on shared runners that sandbox each run.
- Local runs (
forge run --local) refuseid_tokens: only Forge's server signs tokens, and only for runs on its runners. - Each token issued is in the audit log as Issued an OIDC token, with its name, audience and subject, never the token.
The issuer
Each organization has its own issuer:
https://<your Forge server>/oidc/<organization id>
with the discovery document at …/.well-known/openid-configuration and the keys at …/jwks. A
cloud trust that names this issuer admits only your organization's runs. The organization's
General page shows its ID and its OIDC issuer. The issuer uses the id, not the URL
name, so a trust doesn't break or widen when something is renamed.
Forge signs with an RSA key per organization, which gets a new version every 90 days. A new key is
published a day before it signs, and an old one stays a day after, so a cloud that caches the keys
never sees a token it can't verify. Point your trust at the issuer, not at a copied key or kid.
Claims
| Claim | Value |
|---|---|
iss |
the organization's issuer |
sub |
project:<project id>:environment:<name> for a run that deploys to an environment, else project:<project id>:ref:<git ref>, else project:<project id>:run |
aud |
the audience the spec asked for |
exp, iat, nbf |
the token's 10 minutes |
jti |
unique per token |
org_id, org |
the organization's id and URL name |
project_id, project |
the project's id and URL name |
run_id, run_number, attempt |
the run |
template, trigger, flow |
what started it, when any did |
environment |
the environment it deploys to |
ref, ref_type, sha, repository, event, actor |
its Git context; ref_type is branch, tag or pull_request |
runner_kind |
own (the organization's runner) or shared |
Claims without a value are left out, so a condition on a claim never matches an empty string.
Write trust conditions on sub first: it holds ids, which don't change when something is renamed.
Trust Forge in your cloud
The cloud must reach the issuer over HTTPS: it fetches the discovery document and the keys there.
The organization's Cloud identity page builds the setup for you. Pick a Project and the Runs to trust (Deploys to an environment, A Git ref or Any run of the project), then the Cloud. It shows the Subject (sub), the Trust setup to copy and what goes In the run spec. Replace the upper-case names in angle brackets with your cloud account's values.
In short, per cloud:
- AWS: add an IAM OIDC identity provider with the issuer URL and the audience
sts.amazonaws.com. Then make a role whose trust policy allowssts:AssumeRoleWithWebIdentitywith a condition on<issuer without https://>:sub, such asproject:<project id>:environment:production. - Google Cloud: a workload identity pool provider with the issuer URL, mapping
google.subjecttoassertion.sub, and an attribute condition on the project or environment. - Azure: a federated credential on an app registration or managed identity, with the issuer,
the subject and the audience
api://AzureADTokenExchange. - Vault: a JWT auth method with
oidc_discovery_urlset to the issuer, and a role withbound_audiencesandbound_subject(orbound_claims).
Good to know
- A token is a credential in your cloud while it lasts: whoever holds it gets what your trust
maps that run to. Bind the trust to
audand tosub(an environment for deploys), not only to the issuer, and give the role no more than the run needs. - Forge masks everything shaped like a JWT in the output, summary and test reports of a run with tokens, and leaves out outputs that hold one.