Sub topic 13
Using the same pattern with other providers
This chapter assumes you have read the earlier chapters on the token exchange, the sub and aud claims, and trust conditions. It shows that the AWS setup is one instance of a general pattern. Azure, Google Cloud, and HashiCorp Vault all work the same way. Only the names and the matching rules differ.
The shared pattern
Every provider does the same four things:
- The workflow gets a JWT from GitHub's issuer,
https://token.actions.githubusercontent.com. - The workflow sends the JWT to the provider's token-exchange endpoint.
- The provider fetches GitHub's public signing keys and checks the signature, issuer, audience, and expiry.
- The provider compares claims such as
suborrepositorywith a trust rule you configured. If they match, it returns short-lived credentials.
What changes between providers is where you write the trust rule, what the audience must be, and how strict subject matching is.
| Provider | Trust object | Expected audience | Subject and claim matching |
|---|---|---|---|
| AWS | IAM role trust policy | `sts.amazonaws.com` | `Condition` block, wildcards allowed with `StringLike` |
| Azure | Federated credential on an app registration or managed identity | `api://AzureADTokenExchange` | Exact `sub` string per credential |
| Google Cloud | Workload identity pool and provider | Provider resource URL by default, configurable | Attribute mapping plus CEL condition |
| Vault | JWT auth role | Any value you set in `bound_audiences` | `bound_claims` on any claim |
Azure: federated credentials
In Microsoft Entra ID you add a federated identity credential to an app registration or a user-assigned managed identity. The credential stores three values: issuer, subject, and audience. Entra matches the sub claim exactly. A standard federated credential has no wildcards, so you create one credential per branch, environment, or tag you want to allow.
{
"name": "github-main",
"issuer": "https://token.actions.githubusercontent.com",
"subject": "repo:octo-org/octo-repo:ref:refs/heads/main",
"description": "Deploy from main",
"audiences": ["api://AzureADTokenExchange"]
}Save this as credential.json. Then run az ad app federated-credential create --id <app-object-id> --parameters credential.json. The service principal also needs an Azure role assignment, such as Contributor on the target resource group. The federated credential only proves who the caller is. The role assignment decides what the caller can do.
The workflow uses azure/login. The client ID, tenant ID, and subscription ID are identifiers, not secrets, so repository variables are fine.
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: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- run: az account showGoogle Cloud: workload identity federation
Google Cloud splits the trust into two steps. First you create a workload identity pool with an OIDC provider. The provider's attribute mapping turns token claims into Google attributes. Then you grant a service account to principals that carry those attributes.
gcloud iam workload-identity-pools create github-pool \
--project=my-project --location=global \
--display-name="GitHub Actions"
gcloud iam workload-identity-pools providers create-oidc github-provider \
--project=my-project --location=global \
--workload-identity-pool=github-pool \
--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'"
gcloud iam service-accounts add-iam-policy-binding \
[email protected] \
--project=my-project \
--role=roles/iam.workloadIdentityUser \
--member="principalSet://iam.googleapis.com/projects/123456789/locations/global/workloadIdentityPools/github-pool/attribute.repository/octo-org/octo-repo"The --attribute-condition is a Common Expression Language (CEL) expression. Google rejects tokens that fail it before any IAM binding is checked. Always set one that names your repository or organization. The pool is shared by everything that presents a token from GitHub's issuer, so without a condition the provider's trust is broad.
name: gcp-deploy
on:
push:
branches: [main]
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/auth@v2
with:
workload_identity_provider: projects/123456789/locations/global/workloadIdentityPools/github-pool/providers/github-provider
service_account: [email protected]
- uses: google-github-actions/setup-gcloud@v2
- run: gcloud auth listThe auth action requests the token for you. By default it uses the provider's resource name as the audience, so you do not set one by hand.
HashiCorp Vault: JWT auth
Vault does not issue cloud credentials itself. It returns a Vault token, which you then use to read secrets or mint dynamic credentials. You enable the jwt auth method and point it at GitHub's discovery document. The role holds the rules.
vault auth enable jwt
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/ci-deploy - <<'EOF'
{
"role_type": "jwt",
"user_claim": "repository",
"bound_audiences": "https://github.com/octo-org",
"bound_claims": {
"repository": "octo-org/octo-repo",
"ref": "refs/heads/main"
},
"token_policies": "ci-deploy",
"token_ttl": "10m"
}
EOFVault has the most flexible matching of the four. bound_claims can test any claim in the token, such as repository, ref, environment, or job_workflow_ref, and not only sub. The audience is whatever you choose. The hashicorp/vault-action action defaults to sigstore, so set jwtGithubAudience to match bound_audiences.
name: vault-read
on:
push:
branches: [main]
permissions:
id-token: write
contents: read
jobs:
read-secret:
runs-on: ubuntu-latest
steps:
- uses: hashicorp/vault-action@v3
with:
url: https://vault.example.com:8200
method: jwt
role: ci-deploy
jwtGithubAudience: https://github.com/octo-org
secrets: |
secret/data/ci/app api_key | API_KEY
- run: test -n "$API_KEY" && echo "secret loaded"The action masks the value in logs and exports it as the environment variable API_KEY.
Common mistakes when moving between providers
- Reusing an AWS audience. An audience of
sts.amazonaws.comfails on Azure and Google. Each provider checks its own value, and a mismatch is rejected during validation. - Expecting wildcards in Azure. A subject like
repo:octo-org/octo-repo:*is treated literally in a standard credential. Create one credential per subject. - Skipping the Google attribute condition. Mapping
google.subjecttoassertion.subis not a restriction. The condition and the IAM binding together are what limit access. - Trusting only the issuer. All GitHub repositories use the same issuer. Every provider needs a rule on
sub,repository, or another claim, or any repository on GitHub could pass. - Forgetting
id-token: write. Every workflow above needs it. Without it the job has no token to request, whatever the provider.
Choosing between them
You rarely get to choose the provider, because it is wherever your resources live. If you do have a choice, use these differences as a guide.
- Use Vault when you need rules on claims other than
sub, or when you want one place to issue credentials for several clouds. - Use Azure when you want a simple, auditable list of allowed subjects, and accept that the list grows with every branch or environment.
- Use Google Cloud when you want attribute-based grants, such as one binding that covers every repository in a team.
Exercise
A workflow that works against AWS is copied to deploy to Azure. The job has id-token: write and the azure/login step, but login fails with an audience error. What is the most likely cause, and where do you fix it?
Show answer
The federated credential on the Azure side, or the token request, uses an audience other than api://AzureADTokenExchange, for example the AWS value sts.amazonaws.com. Fix it in the federated credential's audiences list so it contains api://AzureADTokenExchange, and make sure the workflow does not override the audience with the AWS value.
Exercise
Your Google Cloud provider maps google.subject=assertion.sub and has no attribute condition. Why is this unsafe, and what is the smallest change that fixes it?
Show answer
GitHub's issuer is shared by all repositories, so any repository's workflow can present a valid token to the provider. The mapping does not reject any of them. Add an attribute condition such as assertion.repository == 'octo-org/octo-repo', and bind the service account to a principalSet based on attribute.repository for that repository.