Skip to content
Application identity

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.

  • 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

Create one Provider per Zone for GitHub’s OIDC issuer. Every repository and organization shares it.

Terminal window
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.

  1. 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
    subject The job’s sub claim. 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_audience Omitted, so it defaults to your Zone issuer URL. The action requests the token with that audience.
    authentication_condition CEL 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/main unless 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.

  2. Copy the credential’s Client ID

    The response’s identifier is the credential’s Client ID. The action sends it as client_id. It is not a secret.

  1. Add repository variables

    In the repository, go to Settings → Secrets and variables → Actions → Variables and add:

    Variable Value
    KEYCARD_ISSUER Your Zone issuer URL
    KEYCARD_CLIENT_ID The credential’s Client ID

    These values are not secrets, so they’re stored as variables.

  2. 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: write
    contents: read
    jobs:
    deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: keycardai/gha-keycard-auth@v0
    with:
    zone-url: ${{ vars.KEYCARD_ISSUER }}
    client-id: ${{ vars.KEYCARD_CLIENT_ID }}
    credentials: |
    - resource: <resource-url>
    type: env
    env-name: RESOURCE_TOKEN
    - name: Call the Resource
    run: |
    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.

    credentials field Value
    resource The Resource’s identifier
    type env to set an environment variable, or file to write the token to a file under $RUNNER_TEMP
    env-name The variable to set, for type: env
    file-path The file to write, for type: file
    scope Optional. 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.

Run the workflow. The action’s step succeeds, and a credentials:issue event shows on the Application’s Activity tab in Keycard Console.

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}'
  • aud differs from the Zone issuer URL: set zone-url to your Zone issuer URL exactly. If you set allowed_audience on the credential, pass the same value as the action’s audience input. Use a value only Keycard accepts, not GitHub’s default https://github.com/<org>.
  • sub doesn’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. Update subject, or use a trailing *.
  • Wrong Client ID: KEYCARD_CLIENT_ID isn’t the Client ID of a Workload Identity credential in this Zone, or KEYCARD_ISSUER names another Zone.