Sub topic 13
Using the same pattern with other providers
This chapter assumes you have read the AWS walkthrough. You should know what the id-token: write permission does, how the aud and sub claims work, and how a trust policy checks them. Here you will see that Azure, Google Cloud, and HashiCorp Vault accept the same GitHub token. Only the names of the settings change.
The shared pattern
Every provider asks you to do the same three things:
- Trust GitHub's issuer,
https://token.actions.githubusercontent.com. The provider fetches GitHub's public signing keys from that issuer to check signatures. - Choose an audience that the provider expects.
- Write a rule that matches claims such as
suborrepository, and tie that rule to a role or identity.
Azure
Azure calls the trust rule a federated credential. You add it to a Microsoft Entra app registration or a user-assigned managed identity. The issuer is GitHub's URL, the audience is api://AzureADTokenExchange, and the subject is the exact string you want to allow.
name: azure-deploy
on:
push:
branches: [main]
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- run: az account showThe three IDs identify resources and are not secrets. Storing them as repository secrets is a convention. A federated credential matches the subject exactly, so you need a separate credential for each branch or environment.
Google Cloud
Google Cloud uses Workload Identity Federation. You create a workload identity pool and an OIDC provider inside it. The provider maps token claims to Google attributes, and an attribute condition rejects tokens you do not want.
gcloud iam workload-identity-pools providers create-oidc octo-repo \
--project=my-project \
--location=global \
--workload-identity-pool=github \
--issuer-uri="https://token.actions.githubusercontent.com" \
--attribute-mapping="google.subject=assertion.sub,attribute.repository=assertion.repository" \
--attribute-condition="assertion.repository == 'octo-org/octo-repo'"You then let identities from the pool impersonate a service account. In the workflow, google-github-actions/auth does the exchange:
- uses: google-github-actions/auth@v2
with:
workload_identity_provider: projects/123456789/locations/global/workloadIdentityPools/github/providers/octo-repo
service_account: [email protected]HashiCorp Vault
Vault's JWT auth method trusts GitHub's issuer and checks claims through a role.
vault write auth/jwt/config \
oidc_discovery_url="https://token.actions.githubusercontent.com" \
bound_issuer="https://token.actions.githubusercontent.com"
vault write auth/jwt/role/deploy \
role_type="jwt" \
user_claim="sub" \
bound_audiences="https://github.com/octo-org" \
bound_claims='{"repository":"octo-org/octo-repo","ref":"refs/heads/main"}' \
token_policies="deploy" \
token_ttl="10m"Here bound_audiences and bound_claims do the work that Condition blocks do in AWS. The audience is up to you. It must match what the workflow requests, as in the token request chapter.
Comparing the settings
| Concept | AWS | Azure | Google Cloud | Vault |
|---|---|---|---|---|
| Trust container | OIDC provider and role trust policy | Federated credential | Pool and provider | JWT auth mount and role |
| Audience | `sts.amazonaws.com` | `api://AzureADTokenExchange` | Provider resource URL by default | Your choice, set in `bound_audiences` |
| Claim matching | `Condition` keys | Exact subject | Attribute mapping and condition | `bound_claims` |
| Result | Role session | Access token | Service account token | Vault token |
Common mistakes
- Matching the audience in one place and requesting a different one in the workflow. Each provider has its own default audience, so check it.
- Trusting the issuer without matching
suborrepository. - Assuming wildcards work everywhere. Azure compares the subject exactly, while AWS, Google, and Vault each have their own operators.
Exercise
A Vault role has bound_audiences set to "https://github.com/octo-org". The workflow gets a token with the default audience and Vault rejects it. What do you change, and where?
Show answer
Request a token whose audience is "https://github.com/octo-org" by passing that value as the audience when the workflow requests the ID token, or set the matching audience option in the login action. Alternatively, change bound_audiences on the role to the audience the workflow actually uses. The two values must be identical.