Configure GitHub Actions Workload Identity
Authenticate GitHub Actions workflows to Keycard with the workflow's OIDC token.
A GitHub Actions job gets a short-lived OIDC token from GitHub, with your Zone as its audience. It sends the token to Keycard along with the Client ID of the Application credential it authenticates as. Keycard checks the token’s signature with GitHub’s public keys, then checks its audience, subject, and claims. The Keycard Auth action does this in one workflow step.
Prerequisites
Section titled “Prerequisites”- Familiarity with the concepts in Workload Identity, and with GitHub’s OpenID Connect docs
- A Keycard Zone and an Application for the workflow
- Your Zone issuer URL, from Settings → Connection in Keycard Console
- The Keycard CLI, signed in with
keycard auth signin --org <org-id> - Your GitHub organization and repository IDs:
gh api repos/<org>/<repo> --jq '{github_org_id: .owner.id, repo_id: .id}' - Your repository’s subject prefix:
gh api repos/<org>/<repo>/actions/oidc/customization/sub --jq .sub_claim_prefix - Permission to edit workflows in the repository
Register GitHub Actions as a Provider
Section titled “Register GitHub Actions as a Provider”Create one Provider per Zone for GitHub’s OIDC issuer. Every repository and organization shares it.
keycard agent api /zones/<zone-id>/providers --org <org-id> -X POST -d '{ "name": "GitHub Actions", "identifier": "https://token.actions.githubusercontent.com", "protocols": { "oauth2": { "issuer": "https://token.actions.githubusercontent.com" } }}'Keycard discovers GitHub’s signing keys from the issuer.
Create a token credential
Section titled “Create a token credential”-
Add the credential to the Application
Terminal window keycard agent api /zones/<zone-id>/application-credentials --org <org-id> -X POST -d '{"type": "token","version": 2,"application_id": "<application-id>","provider_id": "<github-provider-id>","subject": "repo:<org>@<github-org-id>/<repo>@<repo-id>:ref:refs/heads/main","authentication_condition": "claims.repository_owner_id == \"<github-org-id>\""}'Field Value subjectThe job’s subclaim. Match exactly, or end with*for a prefix match:repo:<org>@<github-org-id>/<repo>@<repo-id>:*trusts every branch, tag, environment, and pull request job in the repository.allowed_audienceOmitted, so it defaults to your Zone issuer URL. The action requests the token with that audience. authentication_conditionCEL over the token’s claims. Pins the token to your organization.Repositories created after July 15, 2026 use the immutable subject format shown here. Older repositories use
repo:<org>/<repo>:ref:refs/heads/mainunless they opt in, and move to the immutable format on rename or transfer. GitHub Enterprise Server uses the older format.For every claim in a GitHub Actions token, see GitHub’s OIDC token claims.
-
Copy the credential’s Client ID
The response’s
identifieris the credential’s Client ID. The action sends it asclient_id. It is not a secret.
Configure the workflow
Section titled “Configure the workflow”-
Add repository variables
In the repository, go to Settings → Secrets and variables → Actions → Variables and add:
Variable Value KEYCARD_ISSUERYour Zone issuer URL KEYCARD_CLIENT_IDThe credential’s Client ID These values are not secrets, so they’re stored as variables.
-
Add the Keycard Auth action
Grant the workflow
id-token: write, then add the Keycard Auth action before the steps that call the Resource:permissions:id-token: writecontents: readjobs:deploy:runs-on: ubuntu-lateststeps:- uses: keycardai/gha-keycard-auth@v0with:zone-url: ${{ vars.KEYCARD_ISSUER }}client-id: ${{ vars.KEYCARD_CLIENT_ID }}credentials: |- resource: <resource-url>type: envenv-name: RESOURCE_TOKEN- name: Call the Resourcerun: |curl -sS -H "Authorization: Bearer $RESOURCE_TOKEN" <resource-url>The action requests the job’s OIDC token with your Zone issuer URL as its audience, exchanges it for an access token to each listed Resource, and masks the token in logs. It clears the variable when the job ends.
credentialsfieldValue resourceThe Resource’s identifier typeenvto set an environment variable, orfileto write the token to a file under$RUNNER_TEMPenv-nameThe variable to set, for type: envfile-pathThe file to write, for type: filescopeOptional. Scopes to request on the Resource List several entries to get tokens for several Resources in one step. For every input and the providers the action can hand a token to, such as Pulumi, see the action’s README.
Verify
Section titled “Verify”Run the workflow. The action’s step succeeds, and a credentials:issue event shows on the Application’s Activity tab in Keycard Console.
Troubleshooting
Section titled “Troubleshooting”When the audience, subject, or condition doesn’t match, the action’s step fails with STS exchange failed for <resource>: invalid_client. The Audit Log records details on the failure. To compare the token’s claims against the credential, add a step that requests and decodes a token:
- name: Decode the OIDC token run: | curl -sSfG -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ --data-urlencode "audience=${{ vars.KEYCARD_ISSUER }}" "$ACTIONS_ID_TOKEN_REQUEST_URL" \ | jq -r .value \ | jq -R 'split(".")[1] | gsub("-";"+") | gsub("_";"/") | @base64d | fromjson | {aud, sub, repository_owner_id}'auddiffers from the Zone issuer URL: setzone-urlto your Zone issuer URL exactly. If you setallowed_audienceon the credential, pass the same value as the action’saudienceinput. Use a value only Keycard accepts, not GitHub’s defaulthttps://github.com/<org>.subdoesn’t match: check whether the repository uses the immutable format (<org>@<github-org-id>/<repo>@<repo-id>) or the older one, and note that jobs that reference an environment get:environment:<name>instead of a:ref:suffix. Updatesubject, or use a trailing*.- Wrong Client ID:
KEYCARD_CLIENT_IDisn’t the Client ID of a Workload Identity credential in this Zone, orKEYCARD_ISSUERnames another Zone.