Secrets, Variables and OIDC
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
A pipeline needs two kinds of configuration: values that are fine to read (a region, a site URL) and values that
must stay secret (a deploy key, a registry password). GitHub Actions has a store for each, a built-in short-lived
token for talking to GitHub itself, and OpenID Connect (OIDC) for talking to clouds without storing any long-lived
credential at all. This page covers all four, with the exact YAML for AWS, Google Cloud and Azure. The running
example is this documentation site, whose publish workflow already relies on the built-in token to push to the
gh-pages branch. Versions (aws-actions/configure-aws-credentials@v6, google-github-actions/auth@v3,
azure/login@v3, actions/create-github-app-token@v3) were verified on 2026-11-10; the official docs win on any
discrepancy. Protection rules on deployment targets are in
Environments and Deployments.
Secrets
A secret is an encrypted value readable only by workflows, through the secrets context. Create them in the
repository settings (Settings, then Secrets and variables, then Actions) or with the CLI:
gh secret set NPM_TOKEN --repos albertoirurueta/docs # prompts for the value
gh secret set DEPLOY_KEY < ~/.ssh/deploy_key --env production # environment secret
gh secret set SONAR_TOKEN --org my-org --visibility selected --repos docs,hermes
gh secret list
| Level | Behaviour |
|---|---|
Repository |
Available to every workflow in that repository. |
Environment |
Available only to jobs that reference that environment, after its protection rules (required reviewers, wait timers, branch restrictions) pass. The strongest scoping for production credentials. |
Organisation |
Shared across repositories, with access set to all, private or selected repositories. |
When the same name exists at several levels, the most specific wins: environment over repository over organisation. Use a secret in a step by passing it explicitly, never by echoing it:
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
How secrets are protected
-
Masking: the runner replaces the value of a secret with
***in logs. Masking is exact-match, so a transformed value (base64, URL-encoded, a substring) is not masked. Register derived values yourself withecho "::add-mask::$VALUE". -
Forks: workflows triggered by
pull_requestfrom a fork receive no secrets and a read-onlyGITHUB_TOKEN.pull_request_targetdoes run with secrets, so never check out and execute the fork’s code inside it. See Security Hardening. -
Reusable workflows: secrets must be passed by name or with
secrets: inherit, see Reusable Workflows and Composite Actions. -
Structured secrets: avoid JSON or multi-line blobs where possible, since a masked line-by-line value may leak parts of it; if needed, mask each sensitive field separately.
-
Secret scanning and push protection: GitHub scans pushes for known token formats and, with push protection enabled, blocks the push until you remove the secret or bypass with a reason. A leaked secret is compromised even if you delete the commit: rotate it.
Rotating
Rotate on a schedule and after any suspected exposure: create the new credential, update the secret
(gh secret set overwrites), run the pipeline once to prove it works, then revoke the old credential. The best
rotation policy is having nothing to rotate, which is the point of the OIDC section below.
Variables
Variables hold non-sensitive configuration, available through the vars context, at the same three levels as
secrets (repository, environment, organisation). Their values are shown in clear text in logs and the UI.
gh variable set SITE_URL --body "https://albertoirurueta.github.io/docs"
gh variable list
env:
SITE_URL: ${{ vars.SITE_URL }}
steps:
- run: echo "Publishing to $SITE_URL"
Besides vars, the env context (defined in the workflow) and the default environment variables (GITHUB_REPOSITORY,
GITHUB_REF, RUNNER_OS, …) are the other configuration sources; the contexts are listed on
Workflow Syntax and Triggers.
The built-in GITHUB_TOKEN
For every job GitHub creates a temporary installation token for the repository, available as
${{ secrets.GITHUB_TOKEN }} (or ${{ github.token }}), valid until the job ends. It needs no setup and
requires no rotation.
-
Permissions are controlled per workflow or job with the
permissions:key. Once you set any permission, all unlisted ones becomenone, so the least-privilege pattern is to declare exactly what each job needs:
permissions:
contents: read
jobs:
release:
permissions:
contents: write # create releases, push tags
pull-requests: write # comment on PRs
id-token: write # request an OIDC token
runs-on: ubuntu-latest
-
The repository (or organisation) default for the token is set in Settings, then Actions, then General; choose the restricted default (
contents: read) and grant more per job. -
The token is scoped to the repository that runs the workflow. It cannot read other private repositories.
-
Events caused by the token do not start new workflow runs, with the exception of
workflow_dispatchandrepository_dispatch. This prevents recursive loops but means a pull request opened withGITHUB_TOKENdoes not trigger your CI; use a GitHub App token or a PAT if it must. -
It is the right credential for the Antora site’s push to
gh-pages:permissions: contents: writeon the publish job.
OpenID Connect (OIDC)
Why
A cloud secret stored in GitHub (an AWS access key, a service account JSON) is long-lived, copyable, and must be rotated by hand. With OIDC the workflow proves who it is to the cloud with a signed token, and the cloud returns credentials that last minutes. Nothing durable is stored in GitHub.
How it works
-
The job needs
permissions: id-token: write; without it no token can be requested. -
The cloud action asks the runner’s OIDC endpoint for a JWT with the chosen audience.
-
The JWT, signed by
https://token.actions.githubusercontent.com, is sent to the cloud’s token service. -
The cloud checks the signature against GitHub’s published keys and evaluates a trust policy: conditions on the token’s claims.
-
If they match, it issues temporary credentials.
| Claim | Meaning |
|---|---|
|
|
|
Audience; defaults to the repository owner URL, and cloud actions set it to the value the provider expects
(for example |
|
Subject, the main trust condition. Default formats include |
|
The repository and owner. |
|
Context of the run; |
Write trust policies as tightly as the cloud allows: pin the repository and the branch or environment. A policy that
only checks the audience, or uses a wildcard such as repo:OWNER/*, lets unrelated repositories assume the role.
AWS
Create an IAM OIDC identity provider for token.actions.githubusercontent.com, then a role with this trust policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
"token.actions.githubusercontent.com:sub": "repo:albertoirurueta/docs:environment:production"
}
}
}
]
}
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v7
- uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: arn:aws:iam::123456789012:role/github-actions-docs-deploy
aws-region: eu-west-1
role-session-name: docs-${{ github.run_id }}
- run: aws s3 sync build/site s3://example-docs-bucket --delete
Google Cloud
Create a Workload Identity Pool and an OIDC provider, map attribute.repository, and grant a service account to the
principal:
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v7
- id: auth
uses: google-github-actions/auth@v3
with:
workload_identity_provider: projects/123456789012/locations/global/workloadIdentityPools/github/providers/github-oidc
service_account: docs-deployer@example-project.iam.gserviceaccount.com
- uses: google-github-actions/setup-gcloud@v3
- run: gcloud storage rsync build/site gs://example-docs-bucket --recursive
The provider should carry an attribute condition such as assertion.repository == 'albertoirurueta/docs' so that
only your repository can use the pool.
Azure
Register an application (or user-assigned managed identity) and add a federated credential whose subject is the
sub value (for example repo:albertoirurueta/docs:environment:production). No client secret is created:
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v7
- uses: azure/login@v3
with:
client-id: 00000000-0000-0000-0000-000000000001
tenant-id: 00000000-0000-0000-0000-000000000002
subscription-id: 00000000-0000-0000-0000-000000000003
- run: az storage blob upload-batch -d '$web' -s build/site --account-name exampledocs --overwrite
The three IDs are identifiers, not secrets, though many teams keep them in vars or secrets for tidiness.
HashiCorp Vault and others
Vault’s JWT/OIDC auth method can trust the GitHub issuer and map claims to policies; use the
hashicorp/vault-action with method: jwt. Registries such as PyPI and RubyGems offer trusted publishing, and
NuGet has the NuGet/login action, all built on the same token; see
Release Pipelines.
Customising the sub claim
Organisation and repository owners can change which claims go into sub through the OIDC customization API, for
example to include repository_id (immune to renames) or job_workflow_ref:
gh api -X PUT repos/albertoirurueta/docs/actions/oidc/customization/sub \
-F use_default=false \
-f 'include_claim_keys[]=repo' \
-f 'include_claim_keys[]=context' \
-f 'include_claim_keys[]=job_workflow_ref'
Update the cloud trust policies to the new subject format at the same time, or authentication will fail.
Short-lived credentials versus long-lived secrets
| Aspect | Long-lived secret (access key, JSON key) | OIDC short-lived credential |
|---|---|---|
Lifetime |
Until someone rotates it. |
Minutes to an hour. |
Storage in GitHub |
Yes, as a secret. |
None; only non-secret identifiers. |
Blast radius if leaked |
Usable from anywhere until revoked. |
Useless outside the token’s audience, claims and short window. |
Scoping |
Whatever the key allows. |
Per repository, branch, environment or workflow through claims. |
Setup effort |
Low. |
Identity provider and trust policy once per cloud account. |
Audit |
Shows the key owner. |
Shows the repository, run and workflow in cloud logs. |
Which token: GITHUB_TOKEN, GitHub App or PAT?
| GITHUB_TOKEN | GitHub App installation token | Personal access token | |
|---|---|---|---|
Owner |
The workflow run. |
The app (a bot identity). |
A person. |
Lifetime |
The job. |
Up to one hour. |
Until expiry or revocation (fine-grained PATs expire). |
Scope |
The current repository only. |
Any repositories the app is installed on. |
Whatever the user can access. |
Triggers other workflows |
No (except |
Yes. |
Yes. |
Rotation |
Automatic. |
Automatic (private key rotated rarely). |
Manual. |
Best for |
Everyday repository operations. |
Cross-repository automation, opening PRs that must run CI. |
Last resort when an App cannot be used. |
Creating an App token in a workflow:
steps:
- id: app-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
owner: albertoirurueta
repositories: docs,hermes
- uses: actions/checkout@v7
with:
repository: albertoirurueta/hermes
token: ${{ steps.app-token.outputs.token }}
The docs site aggregates other repositories at build time through Antora; if those repositories become private, a read-only App token (or deploy keys) is the way to let the build fetch them without a personal PAT.
Common mistakes
-
Printing secrets with
echoorset -x, or building the value into a URL that ends up in logs. -
Granting
permissions: write-allor leaving the repository default at read and write. -
Using
pull_request_targetand then running code from the pull request. -
Forgetting
id-token: write, then seeing "Unable to get ACTIONS_ID_TOKEN_REQUEST_URL". -
A trust policy without a
subcondition, or with a wildcard that matches other repositories. -
Storing cloud keys as secrets when OIDC is available.
-
Expecting a pull request opened by
GITHUB_TOKENto run CI.