Overview

GitHub Actions can issue each job a signed OIDC token describing the repository, branch and triggering event. Prism trusts GitHub's issuer per project, and a service account declares which repositories and events may assume it. The job then exchanges its GitHub token at POST /api/v1/auth/service-accounts/assume/openid and receives a 24-hour Prism token for the service account.

From there the job can do anything the service account is granted: read store values, mint federation tokens for AWS or GCP, or get SSH certificates for deployment.

Prerequisites

  1. Trust GitHub Actions in the project

    The issuer and JWKS URL are preconfigured; a project can have one GitHub Actions trust.

    prism projects openid-trusts create --project payments --kind github-actions
    # name: github-actions
    # issuer: https://token.actions.githubusercontent.com
    # audience: https://acme.id.prism.example.com

    Note the audience: the workflow must ask GitHub for a token with exactly this audience. Tokens with GitHub's default audience are rejected, so a token minted for another relying party cannot be replayed against Prism.

  2. Create the service account and allow the repository to assume it

    --organization is the GitHub owner, --repo the repository name without the owner, and --event the triggering events allowed. Both --repo and --event can be repeated; all values match exactly.

    prism service-accounts create -p payments -n deployer
    
    prism service-accounts assumptions add-github-actions -p payments \
      --service-account deployer \
      --organization acme-corp \
      --repo payments \
      --event push --event workflow_dispatch
    
    prism service-accounts assumptions list -p payments --service-account deployer

    Pull requests from forks run with the pull_request event; leave it out unless untrusted code should get this identity.

  3. Grant the service account what CI needs

    # e.g. read deployment configuration
    prism stores add-grant -p payments --store app-config \
      --principal deployer --effect allow --role prism:store-reader --key-prefix prod/
  4. Exchange the token in the workflow

    The job needs id-token: write to request a GitHub OIDC token:

    name: deploy
    on:
      push:
        branches: [main]
    
    permissions:
      id-token: write
      contents: read
    
    env:
      PRISM_SERVER_URL: https://prism.example.com
      PRISM_AUDIENCE: https://acme.id.prism.example.com   # audience of the trust
    
    jobs:
      deploy:
        runs-on: ubuntu-latest
        steps:
          - name: Get a Prism token
            run: |
              GH_TOKEN=$(curl -fsS -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
                "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=$PRISM_AUDIENCE" | jq -r .value)
    
              PRISM_TOKEN=$(curl -fsS -X POST "$PRISM_SERVER_URL/api/v1/auth/service-accounts/assume/openid" \
                -H 'Content-Type: application/json' \
                -d "$(jq -n --arg t "$GH_TOKEN" \
                      '{project: "payments", service_account: "deployer", token: $t}')" \
                | jq -r .token)
              echo "::add-mask::$PRISM_TOKEN"
              echo "PRISM_TOKEN=$PRISM_TOKEN" >> "$GITHUB_ENV"
    
          - name: Read deployment config
            run: |
              curl -fsS -H "Authorization: Bearer $PRISM_TOKEN" \
                "$PRISM_SERVER_URL/api/v1/payments/stores/app-config/values/prod%2Fdatabase-url" \
                -o db-url.txt

    With the prism CLI installed on the runner, the exchange is one command, and the token is saved to the CLI profile:

    echo "$GH_TOKEN" > gh-token.jwt
    prism auth sa-assume-openid --project payments --service-account deployer --token-file gh-token.jwt
    prism stores values get prod/database-url -p payments --store app-config

Troubleshooting

"the project must trust github_actions first"

Create the trust (step 1) before adding the assumption method.

"unauthorized" when exchanging the token

Usually the audience. Decode the GitHub token's payload and compare aud with the trust's audience (prism projects openid-trusts list --project payments).

"forbidden" when exchanging the token

The token is valid but no assumption method matches. Compare the token's repository_owner, repository and event_name claims with the method's organization, repositories and events.

Security considerations