We earn commissions when you shop through affiliate links on this site, at no extra cost to you. Our guides and technical recommendations are written independently of these relationships: a commission never decides what we recommend, how we diagnose a problem or what we publish, and the content does not depend on it. Affiliate disclosure

CI/CD · Azure · GCP · Terraform · Intermediate · 25 min

GitHub Actions OIDC to Azure and GCP with Terraform

Keyless GitHub Actions login to Azure and GCP with Terraform: the immutable subject migration and the fix for "rejected by the attribute condition".

GitHub Actions can sign in to Azure and Google Cloud with no stored secret. This guide builds both trusts as Terraform, wires azure/login@v3 and google-github-actions/auth@v3, and fixes the Google attribute condition error. On a repository created after 15 July 2026 the subject carries numeric IDs, so the classic form fails; the guide shows how to read it and migrate the credential. Tested in a scratch repository; pull request and tag subjects were not.

A GitHub Actions job can sign in to Azure and Google Cloud without a stored secret, and the Google side fails with unauthorized_client: The given credential is rejected by the attribute condition. when the trust does not match the token. This guide builds both trusts as Terraform and fixes that message. On a repository created after 15 July 2026 the classic repo:OWNER/REPO:... subject also no longer matches on Azure, so the guide shows how to read the real subject and migrate the credential.

The Azure error AADSTS700213 and the id-token permission error each have their own runbook: Fix AADSTS700213 in GitHub Actions Azure login owns both. This guide is the setup from zero on both clouds.

Quick answer

  • What you build: on Azure an app registration, a service principal, one federated credential and a Reader role on one resource group (five resources). On Google Cloud a workload identity pool, a provider with an attribute condition, a viewer-only service account, one IAM binding and the Security Token Service API (six resources). No client secret and no key file exist anywhere.
  • The subject is not what most tutorials show. On our repository, created after 15 July 2026, the token sub was repo:OWNER@OWNER-ID/REPO@REPO-ID:ref:refs/heads/obf-lab, and a credential written as repo:OWNER/REPO:ref:refs/heads/obf-lab did not match. Do not type the subject: read it (section 2) and pass it to Terraform as a variable.
  • Google was not affected by that change in our test, because our provider condition and binding use the repository claim, not sub.
  • Tested: both logins, five failure modes plus one false alarm with exact messages (sections 6.1 to 6.6), a decoded token, and a full terraform destroy of both clouds. Not tested: pull request and tag subjects, opting a repository in or out of the new format, and more (section 8).

It was run between 13 and 14 November 2026 from an Ubuntu 26.04 test machine with Terraform 1.17.2, providers google 7.46.2, azurerm 4.81.0 and azuread 3.10.0, Azure CLI 2.92.0, Google Cloud SDK 593.0.0 and gh 2.46.0. The jobs ran on GitHub-hosted ubuntu-latest runners with azure/login v3 (it resolved to v3.1.0) and google-github-actions/auth v3, in a public scratch repository. Neither the Azure subscription nor the Google project had a policy that restricted app registrations or workload identity federation. There are no distribution-specific commands on this page, so there is no RHEL-family twin; everything ran on the one Ubuntu test machine and on GitHub's runners.

Why does google-github-actions/auth@v3 fail in CI with the attribute condition error?

Because the provider's attribute condition did not match the token. The message unauthorized_client: The given credential is rejected by the attribute condition. comes from the Google Security Token Service, in the google-github-actions/auth@v3 step, before gcloud runs. Compare the provider's attribute_condition with the repository claim of the token, exactly as written (section 6.5 reproduces it with its real output).

SymptomMeaningWhere
unauthorized_client ... rejected by the attribute conditionProvider condition names another repositorySection 6.5
Permission 'iam.serviceAccounts.getAccessToken' denied (403)Binding names another repository, or an IAM change has not propagatedSection 6.6
Azure login fails with the subject in the log not matching the credentialSubject format or type differs from the credentialSection 6.1 (immutable subject), 6.3, and the AADSTS700213 runbook
The job cannot get a token (missing id-token: write)Permission missingSection 6.2 and the AADSTS700213 runbook
No credentialed accounts. from gcloud auth listNot an error; the login workedSection 6.4

0. Rules of engagement

  • Terraform creates cloud resources. Apply in a test subscription and project first. Section 9 destroys everything.
  • Use the smallest role. The lab uses Reader on one empty resource group and roles/viewer on one project. A deploy identity needs more, and that is a separate decision.
  • The trust is what keeps other repositories out. Google requires an attribute condition on the provider; Azure matches one exact subject. Our code is a lab minimum: its condition is name-based, which is weaker than the form Google recommends (section 3).
  • Change one thing per run. Each failure below has one cause. Change one value, apply, re-run the job.
  • No secrets in the repository. The client, tenant, subscription, provider and service account values are identifiers, not passwords, and we store them as repository variables. We never printed the token signature.
  • Masked values. OWNER, REPO, OWNER-ID, REPO-ID, PROJECT-ID, PROJECT-NUMBER, TENANT-ID, SUB-ID, CLIENT-ID and <guid> replace real values. The obf-* names and the branch obf-lab are throwaway lab names, shown as they were.

1. How the login works, and what changed on 15 July 2026

The job asks GitHub for an OpenID Connect token. The token carries claims about the run: who owns the repository, which branch or environment, which workflow. The cloud checks the issuer, the audience and the claims you named, then hands back a short-lived cloud credential. Nothing secret is stored; the trust is configuration.

Three claims decide the match in this guide:

ClaimWhere it is matched
sub (subject)Azure: the federated credential's subject, one exact string
repositoryGoogle: the provider's attribute condition and the IAM binding (through attribute.repository)
aud and issAzure: api://AzureADTokenExchange and https://token.actions.githubusercontent.com. Google: the provider's issuer_uri

GitHub announced immutable subject claims on 23 April 2026. The changelog says: "All repositories created after July 15, 2026 will automatically use the new immutable subject claim format." The format adds the numeric owner and repository IDs after the names, joined with @: repo:OWNER@OWNER-ID/REPO@REPO-ID:.... According to the same post, renames and transfers move a repository to the new format too, existing repositories are unaffected unless they opt in, and it applies to github.com only, not GitHub Enterprise Server. Microsoft's page on immutable subjects (ms.date 2026-07-28) describes the migration: create the new credential next to the old one, then delete the old one. We state nothing about defaults beyond what those two pages say.

Our API output for the repository also contained a field use_immutable_subject. We did not find that field name in the documentation pages listed in the references, so treat it as something we observed, not something we can point you to a spec for.

2. Read your real subject before you write any Terraform

Ask GitHub which prefix the repository uses. This is read-only and needs gh signed in with access to the repository.

# Read-only: the subject prefix GitHub uses for this repository
gh api repos/OWNER/REPO/actions/oidc/customization/sub
# Real output (names and ids masked)
{"use_default":true,"use_immutable_subject":true,"sub_claim_prefix":"repo:OWNER@OWNER-ID/REPO@REPO-ID"}

Our repository was created after 15 July 2026 (gh api repos/OWNER/REPO --jq '{created_at,id,owner_id}' shows created_at). The full subject is the prefix plus the job's part: :ref:refs/heads/BRANCH for a branch, :environment:NAME for a job that uses an environment. To see the claims of a real token, decode one inside a run. This workflow requests a token for the Azure audience, masks it, and prints the header and payload with the run-specific values replaced. The signature is never printed.

# .github/workflows/obf-oidc-claims.yml: decode the token of this very run (signature never printed)
name: obf-oidc-claims
on:
  push:
    branches: [obf-lab]
    paths:
      - '.github/workflows/obf-oidc-claims.yml'
      - '.obf-trigger'

permissions:
  id-token: write
  contents: read

jobs:
  claims:
    runs-on: ubuntu-latest
    steps:
      - name: Decode the OIDC token (signature never printed)
        run: |
          TOKEN=$(curl -sS -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
            "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=api://AzureADTokenExchange" | jq -r .value)
          echo "::add-mask::$TOKEN"
          # base64url -> base64, restore the padding
          dec() { p="$1"; pad=$(( (4 - ${#p} % 4) % 4 )); { printf '%s' "$p"; printf '====' | head -c "$pad"; } | tr '_-' '/+' | base64 -d; }
          echo "token has $(echo "$TOKEN" | tr -cd . | wc -c) dots: header.payload.signature (signature is never printed)"
          echo "--- header"
          dec "$(echo "$TOKEN" | cut -d. -f1)" | jq -c '{alg, typ, kid: "<kid>"}'
          echo "--- payload"
          dec "$(echo "$TOKEN" | cut -d. -f2)" | jq '.repository_id="<id>" | .repository_owner_id="<id>" | .actor_id="<id>" | .run_id="<id>" | .check_run_id="<id>" | .run_number="<n>" | .run_attempt="<n>" | .jti="<jti>" | .sha="<sha>" | .job_workflow_sha="<sha>" | .workflow_sha="<sha>"'

The first version of our decoder had a bug: a header whose length is a multiple of 4 got an extra = and base64 printed invalid input. The pad arithmetic above is the fixed version.

# Real output: the header, then the payload (ids, sha and jti masked by the workflow)
token has 2 dots: header.payload.signature (signature is never printed)
--- header
{"alg":"RS256","typ":"JWT","kid":"<kid>"}
--- payload
{
  "actor": "OWNER",
  "actor_id": "<id>",
  "aud": "api://AzureADTokenExchange",
  "base_ref": "",
  "check_run_id": "<id>",
  "event_name": "push",
  "exp": 1794609559,
  "head_ref": "",
  "iat": 1794609259,
  "iss": "https://token.actions.githubusercontent.com",
  "job_workflow_ref": "OWNER/REPO/.github/workflows/obf-oidc-claims.yml@refs/heads/obf-lab",
  "job_workflow_sha": "<sha>",
  "jti": "<jti>",
  "nbf": 1794608959,
  "ref": "refs/heads/obf-lab",
  "ref_protected": "false",
  "ref_type": "branch",
  "repository": "OWNER/REPO",
  "repository_id": "<id>",
  "repository_owner": "OWNER",
  "repository_owner_id": "<id>",
  "repository_visibility": "public",
  "run_attempt": "<n>",
  "run_id": "<id>",
  "run_number": "<n>",
  "runner_environment": "github-hosted",
  "sha": "<sha>",
  "sub": "repo:OWNER@OWNER-ID/REPO@REPO-ID:ref:refs/heads/obf-lab",
  "workflow": "obf-oidc-claims",
  "workflow_ref": "OWNER/REPO/.github/workflows/obf-oidc-claims.yml@refs/heads/obf-lab",
  "workflow_sha": "<sha>"
}

exp - iat is 300 seconds: the token lives five minutes, so a cloud login has to happen in the same job, soon after the token is requested. The audience is the one we asked for in the URL; without &audience= it would be different (not tested). A job that uses an environment adds an environment claim and the sub ends in :environment:NAME instead of :ref:...; the ref claim stays (section 6.3).

3. Google Cloud: workload identity federation with Terraform

The provider maps three claims to attributes, and the condition lets only one repository in. The service account gets a harmless role, and the binding lets tokens from that repository impersonate it. Variables hold every value that differs per project, and allowed_repo exists only so the lab can break the condition on purpose (section 6.5). In your own code you can use one variable for both.

# main.tf (GCP): pool, provider with attribute condition, viewer-only service account, one binding
terraform {
  required_version = ">= 1.9"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 7.0"
    }
  }
}

variable "project" {
  type        = string
  description = "GCP project id"
}

variable "github_repo" {
  type        = string
  description = "OWNER/REPO that may impersonate the service account"
}

# What the provider accepts. Normally the same as github_repo; the lab changes it
# on purpose to reproduce the "unauthorized_client" error.
variable "allowed_repo" {
  type        = string
  description = "Repository named in the provider attribute condition"
}

# Placeholder default: any region works, the lab resources are global.
variable "region" {
  type    = string
  default = "us-central1"
}

provider "google" {
  project = var.project
  region  = var.region
}

# The Security Token Service API is the only one that was not enabled yet.
# iam, iamcredentials and cloudresourcemanager already were, so they are not managed here.
resource "google_project_service" "sts" {
  service            = "sts.googleapis.com"
  disable_on_destroy = true
}

resource "google_iam_workload_identity_pool" "gh" {
  workload_identity_pool_id = "obf-gh-pool"
  display_name              = "obf GitHub Actions"
  description               = "Lab: keyless login from GitHub Actions"
  depends_on                = [google_project_service.sts]
}

resource "google_iam_workload_identity_pool_provider" "gh" {
  workload_identity_pool_id          = google_iam_workload_identity_pool.gh.workload_identity_pool_id
  workload_identity_pool_provider_id = "obf-gh-provider"
  display_name                       = "obf GitHub OIDC"

  # Map claims of the GitHub token to attributes the IAM binding can use.
  attribute_mapping = {
    "google.subject"       = "assertion.sub"
    "attribute.repository" = "assertion.repository"
    "attribute.ref"        = "assertion.ref"
  }

  # Without a condition any repository on GitHub that knows the provider path could try to log in.
  attribute_condition = "assertion.repository == \"${var.allowed_repo}\""

  oidc {
    issuer_uri = "https://token.actions.githubusercontent.com"
  }
}

resource "google_service_account" "gh" {
  account_id   = "obf-oidc-sa"
  display_name = "obf GitHub Actions OIDC"
}

# Harmless role: read-only on the project.
resource "google_project_iam_member" "viewer" {
  project = var.project
  role    = "roles/viewer"
  member  = "serviceAccount:${google_service_account.gh.email}"
}

# Only tokens from this repository may impersonate the service account.
resource "google_service_account_iam_member" "wif" {
  service_account_id = google_service_account.gh.name
  role               = "roles/iam.workloadIdentityUser"
  member             = "principalSet://iam.googleapis.com/${google_iam_workload_identity_pool.gh.name}/attribute.repository/${var.github_repo}"
}

output "workload_identity_provider" {
  value = google_iam_workload_identity_pool_provider.gh.name
}

output "service_account_email" {
  value = google_service_account.gh.email
}
# terraform.tfvars (GCP): the values that differ per project, masked
project      = "PROJECT-ID"
github_repo  = "OWNER/REPO"
allowed_repo = "OWNER/REPO"

Google's documentation for deployment pipelines says an attribute condition is required on a provider that trusts an external issuer such as GitHub, and tells you to use the numeric *_id fields, which are "unique and can't be reused". Our condition uses the repository name claim, which is name-based: a name can be released and taken by someone else. That is the recyclable form and a lab minimum. For real use, test a condition on repository_id (or repository_owner_id); we did not test one. The region value is a placeholder default, and the resources here are global.

# Real output, condensed [...]: init, validate, apply (state-changing; creates six resources)
$ terraform init
- Installed hashicorp/google v7.46.2 (signed by HashiCorp)
Terraform has been successfully initialized!

$ terraform validate
Success! The configuration is valid.

$ terraform apply -auto-approve
Plan: 6 to add, 0 to change, 0 to destroy.
google_service_account.gh: Creation complete after 13s [id=projects/PROJECT-ID/serviceAccounts/obf-oidc-sa@PROJECT-ID.iam.gserviceaccount.com]
google_project_iam_member.viewer: Creation complete after 10s [id=PROJECT-ID/roles/viewer/serviceAccount:obf-oidc-sa@PROJECT-ID.iam.gserviceaccount.com]
google_project_service.sts: Creation complete after 23s [id=PROJECT-ID/sts.googleapis.com]
google_iam_workload_identity_pool.gh: Creation complete after 11s [id=projects/PROJECT-ID/locations/global/workloadIdentityPools/obf-gh-pool]
google_service_account_iam_member.wif: Creation complete after 6s [id=projects/PROJECT-ID/serviceAccounts/obf-oidc-sa@PROJECT-ID.iam.gserviceaccount.com/roles/iam.workloadIdentityUser/principalSet://iam.googleapis.com/projects/PROJECT-NUMBER/locations/global/workloadIdentityPools/obf-gh-pool/attribute.repository/OWNER/REPO]
google_iam_workload_identity_pool_provider.gh: Creation complete after 11s [id=projects/PROJECT-ID/locations/global/workloadIdentityPools/obf-gh-pool/providers/obf-gh-provider]
Apply complete! Resources: 6 added, 0 changed, 0 destroyed.

Outputs:
service_account_email = "obf-oidc-sa@PROJECT-ID.iam.gserviceaccount.com"
workload_identity_provider = "projects/PROJECT-NUMBER/locations/global/workloadIdentityPools/obf-gh-pool/providers/obf-gh-provider"

Read back what exists with gcloud (read-only):

# Real output: the provider, the binding and the project role of the service account
$ gcloud iam workload-identity-pools providers describe obf-gh-provider --workload-identity-pool=obf-gh-pool --location=global
attributeCondition: assertion.repository == "OWNER/REPO"
attributeMapping:
  attribute.ref: assertion.ref
  attribute.repository: assertion.repository
  google.subject: assertion.sub
name: projects/PROJECT-NUMBER/locations/global/workloadIdentityPools/obf-gh-pool/providers/obf-gh-provider
oidc:
  issuerUri: https://token.actions.githubusercontent.com
state: ACTIVE
$ gcloud iam service-accounts get-iam-policy obf-oidc-sa@PROJECT-ID.iam.gserviceaccount.com
bindings:
- members:
  - principalSet://iam.googleapis.com/projects/PROJECT-NUMBER/locations/global/workloadIdentityPools/obf-gh-pool/attribute.repository/OWNER/REPO
  role: roles/iam.workloadIdentityUser
$ gcloud projects get-iam-policy (roles of the service account only)
ROLE          MEMBERS
roles/viewer  serviceAccount:obf-oidc-sa@PROJECT-ID.iam.gserviceaccount.com

4. Azure: app registration, federated credential and Reader with Terraform

The trust is the federated credential on the app registration. The Reader role on one resource group is what makes az account show work after the login. The subject is a variable: you give Terraform the complete sub value, taken from section 2, instead of building it from the repository name.

# main.tf (Azure): app registration, service principal, federated credential, Reader on one resource group
terraform {
  required_version = ">= 1.9"
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 4.0"
    }
    azuread = {
      source  = "hashicorp/azuread"
      version = "~> 3.0"
    }
  }
}

variable "subscription_id" {
  type = string
}

# Placeholder default: any Azure region works for the empty resource group.
variable "location" {
  type    = string
  default = "westeurope"
}

# The complete `sub` claim the token must carry. Take it from a decoded token, do not guess it.
variable "subject" {
  type = string
}

provider "azurerm" {
  features {}
  subscription_id = var.subscription_id
}

provider "azuread" {}

data "azurerm_client_config" "current" {}

resource "azurerm_resource_group" "oidc" {
  name     = "obf-oidc"
  location = var.location
}

resource "azuread_application" "gh" {
  display_name = "obf-gh-oidc"
}

resource "azuread_service_principal" "gh" {
  client_id = azuread_application.gh.client_id
}

# No client secret anywhere: the trust is this federated credential.
resource "azuread_application_federated_identity_credential" "branch" {
  application_id = azuread_application.gh.id
  display_name   = "obf-gh-branch"
  description    = "GitHub Actions, one branch of the scratch repository"
  audiences      = ["api://AzureADTokenExchange"]
  issuer         = "https://token.actions.githubusercontent.com"
  subject        = var.subject
}

# Reader on one empty resource group: the smallest scope that still shows up in `az account show`.
resource "azurerm_role_assignment" "reader" {
  scope                = azurerm_resource_group.oidc.id
  role_definition_name = "Reader"
  principal_id         = azuread_service_principal.gh.object_id
}

output "client_id" {
  value = azuread_application.gh.client_id
}

output "tenant_id" {
  value = data.azurerm_client_config.current.tenant_id
}

output "subscription_id" {
  value = var.subscription_id
}

We applied a first version that built the subject as "repo:${var.github_repo}:${var.subject_suffix}" from two variables, which is how most tutorials do it. The file above is that file after the fix in section 6.1: the two variables became one subject variable and nothing else changed.

# terraform.tfvars (Azure): the subject comes from `gh api ... --jq .sub_claim_prefix`, plus the job's part
subscription_id = "SUB-ID"
subject         = "repo:OWNER@OWNER-ID/REPO@REPO-ID:ref:refs/heads/obf-lab"
# Real output, condensed [...]: first apply of the Azure code (state-changing; creates five resources)
$ terraform apply -auto-approve
Plan: 5 to add, 0 to change, 0 to destroy.
azuread_application.gh: Creation complete after 2s [id=/applications/<guid>]
azuread_service_principal.gh: Creation complete after 2s [id=/servicePrincipals/<guid>]
azuread_application_federated_identity_credential.branch: Creation complete after 6s [id=<guid>/federatedIdentityCredential/<guid>]
azurerm_resource_group.oidc: Creation complete after 28s [id=/subscriptions/SUB-ID/resourceGroups/obf-oidc]
azurerm_role_assignment.reader: Creation complete after 33s [id=/subscriptions/SUB-ID/resourceGroups/obf-oidc/providers/Microsoft.Authorization/roleAssignments/<guid>]
Apply complete! Resources: 5 added, 0 changed, 0 destroyed.

Outputs:
client_id = "CLIENT-ID"
subscription_id = "SUB-ID"
tenant_id = "TENANT-ID"

That output is from the first version (classic subject). The credential is one exact string, with no wildcard: a job that uses an environment and a job that does not need two credentials, or two different values. We did not try Microsoft's flexible federated credentials (section 8). Read back what the app trusts and holds (read-only):

# Real output: federated credential, client secrets and role assignment (the credential shown was set to the environment subject, see section 6.3)
$ az ad app federated-credential list --id <app object id> -o json
[
  {
    "audiences": [ "api://AzureADTokenExchange" ],
    "issuer": "https://token.actions.githubusercontent.com",
    "name": "obf-gh-branch",
    "subject": "repo:OWNER@OWNER-ID/REPO@REPO-ID:environment:obf-env"
  }
]
$ az ad app credential list --id <app object id>   (client secrets)
[]
$ az role assignment list --all --assignee <client id> --query "[].{role:roleDefinitionName,scope:scope}" -o json
[
  {
    "role": "Reader",
    "scope": "/subscriptions/SUB-ID/resourceGroups/obf-oidc"
  }
]

The empty list is the point: the app has no client secret. We did not open the Terraform state file.

5. The GitHub side: variables and two workflows

The workflow needs the identifiers from the Terraform outputs. They are not secrets, so we set them as repository variables with gh variable set: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_SUBSCRIPTION_ID, GCP_WIF_PROVIDER, GCP_SERVICE_ACCOUNT and GCP_PROJECT. No repository secret existed before, during or after the test.

# State-changing (GitHub): set one repository variable from a Terraform output (shape only; we set all six this way)
gh variable set AZURE_CLIENT_ID --repo OWNER/REPO --body "$(terraform output -raw client_id)"

Each job needs permissions: id-token: write; without it no token is issued (section 6.2). The two files below were triggered by a push to the obf-lab branch.

# .github/workflows/obf-oidc-gcp.yml: sign in to Google Cloud and prove the identity
name: obf-oidc-gcp
on:
  push:
    branches: [obf-lab]
    paths:
      - '.github/workflows/obf-oidc-gcp.yml'
      - '.obf-trigger'

permissions:
  id-token: write
  contents: read

jobs:
  gcp:
    runs-on: ubuntu-latest
    steps:
      - id: auth
        uses: google-github-actions/auth@v3
        with:
          workload_identity_provider: ${{ vars.GCP_WIF_PROVIDER }}
          service_account: ${{ vars.GCP_SERVICE_ACCOUNT }}
          access_token_scopes: https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/userinfo.email
      - name: Who am I
        run: |
          gcloud auth list
          gcloud projects describe "${{ vars.GCP_PROJECT }}" --format='value(projectId,lifecycleState)'
          curl -sS "https://oauth2.googleapis.com/tokeninfo?access_token=$(gcloud auth print-access-token)" | jq '{email, email_verified}'
# .github/workflows/obf-oidc-azure.yml: sign in to Azure and prove the identity
name: obf-oidc-azure
on:
  push:
    branches: [obf-lab]
    paths:
      - '.github/workflows/obf-oidc-azure.yml'
      - '.obf-trigger'

permissions:
  id-token: write
  contents: read

jobs:
  azure:
    runs-on: ubuntu-latest
    steps:
      - uses: azure/login@v3
        with:
          client-id: ${{ vars.AZURE_CLIENT_ID }}
          tenant-id: ${{ vars.AZURE_TENANT_ID }}
          subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
      - name: Who am I
        run: |
          az account show --query '{state:state, tenantId:tenantId, id:id, userType:user.type}' -o json
          az group list --query '[].name' -o tsv

We used the moving tag @v3 in the lab. For a real pipeline pin both actions to a commit, as the AADSTS700213 runbook does. The very first version of the GCP workflow had no access_token_scopes and no curl line; we added them for the reason in section 6.6.

6. The failures we hit, with exact messages

Each subsection is one failure we caused or met, the message as it appeared, and the fix. Fixes were applied with Terraform and the same workflow run was re-run (same commit).

6.1 Azure: the classic subject does not match on a repository with immutable subjects

The first Azure run used a credential with the classic subject repo:OWNER/REPO:ref:refs/heads/obf-lab, the form most guides show. The branch and the audience were right, and the login failed (the error is the Azure one the AADSTS700213 runbook owns; read the generic fix there):

# Real output: azure/login, repository created after 15 July 2026, classic subject in the credential
[Run azure/login@v3] Federated token details:
[Run azure/login@v3]  issuer - https://token.actions.githubusercontent.com
[Run azure/login@v3]  subject claim - repo:OWNER@OWNER-ID/REPO@REPO-ID:ref:refs/heads/obf-lab
[Run azure/login@v3]  audience - api://AzureADTokenExchange
[Run azure/login@v3]  job_workflow_ref - OWNER/REPO/.github/workflows/obf-oidc-azure.yml@refs/heads/obf-lab
[Run azure/login@v3] Attempting Azure CLI login by using OIDC...
[Run azure/login@v3] ##[error]AADSTS700213: No matching federated identity record found for presented assertion subject 'repo:OWNER@OWNER-ID/REPO@REPO-ID:ref:refs/heads/obf-lab'. Check your federated identity credential Subject, Audience and Issuer against the presented assertion. https://learn.microsoft.com/entra/workload-id/workload-identity-federation Trace ID: <guid> Correlation ID: <guid>
[Run azure/login@v3] ##[error]Login failed with Error: The process '/usr/bin/az' failed with exit code 1. Double check if the 'auth-type' is correct. Refer to https://github.com/Azure/login#readme for more information.

The cause is the subject: the token carries the numeric IDs, the credential did not. The migration is one in-place change in Terraform: take the prefix from gh api (section 2), add :ref:refs/heads/BRANCH, put the result in the subject variable of section 4, and apply. Terraform changed nothing else:

# Real output, condensed [...]: terraform apply with the subject from sub_claim_prefix (state-changing; one in-place update)
  # azuread_application_federated_identity_credential.branch will be updated in-place
      ~ subject        = "repo:OWNER/REPO:ref:refs/heads/obf-lab" -> "repo:OWNER@OWNER-ID/REPO@REPO-ID:ref:refs/heads/obf-lab"
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
# Real output: the same workflow run re-run after the apply (login lines only)
[Run azure/login@v3]  subject claim - repo:OWNER@OWNER-ID/REPO@REPO-ID:ref:refs/heads/obf-lab
[Run azure/login@v3] Attempting Azure CLI login by using OIDC...
[Run azure/login@v3] Subscription is set successfully.
[Run azure/login@v3] Azure CLI login succeeds by using OIDC.
[Who am I] az account show --query '{state:state, tenantId:tenantId, id:id, userType:user.type}' -o json
[Who am I] {
[Who am I]   "id": "SUB-ID",
[Who am I]   "state": "Enabled",
[Who am I]   "tenantId": "TENANT-ID",
[Who am I]   "userType": "servicePrincipal"
[Who am I] }
[Who am I] obf-oidc

It worked on the first attempt after the apply, with no propagation wait. Reader on one resource group was enough for azure/login with a subscription-id and for az account show; az group list returned only obf-oidc. For an existing repository whose subject is moving to the new format, Microsoft's migration order is to add the new credential next to the old one and delete the old one after the new one works. We changed the subject in place, in a lab with no other users, and did not test the side-by-side order.

6.2 Both clouds: id-token: write is missing

If the job lacks permissions: id-token: write, no token is issued and the login fails before the cloud is asked anything. The AADSTS700213 runbook owns this error for azure/login. We reproduced it on both clouds by removing the line from the permissions: block (keeping contents: read). The Azure line that names the cause:

# Real output: azure/login@v3 without id-token: write (one line of the log)
[Run azure/login@v3] ##[error]Failed to fetch federated token from GitHub. Please make sure to give write permissions to id-token in the workflow.

google-github-actions/auth@v3 fails with its own text, which says GitHub did not inject the token variables and names the workflow permissions (or a fork) as the likely cause. Adding the line id-token: write back fixed both runs.

6.3 Azure: the job uses an environment, the credential trusts a branch

We created the environment obf-env and added environment: obf-env to the Azure job. The credential still had the branch subject.

# Real output, condensed [...]: the job's subject now ends in :environment:obf-env, the credential still trusts the branch
[Run azure/login@v3]  subject claim - repo:OWNER@OWNER-ID/REPO@REPO-ID:environment:obf-env
[Run azure/login@v3] ##[error]AADSTS700213: No matching federated identity record found for presented assertion subject 'repo:OWNER@OWNER-ID/REPO@REPO-ID:environment:obf-env'. Check your federated identity credential Subject, Audience and Issuer against the presented assertion. https://learn.microsoft.com/entra/workload-id/workload-identity-federation Trace ID: <guid> Correlation ID: <guid> Timestamp: <time>

The claims run in the same commit confirmed it: the token had "environment": "obf-env" and sub ended in :environment:obf-env, while ref was still refs/heads/obf-lab. An environment replaces the ref: part of the subject. The fix is a new subject value in Terraform, <sub_claim_prefix>:environment:obf-env:

# Real output, condensed [...]: apply and re-run (state-changing; one in-place update)
      ~ subject        = "repo:OWNER@OWNER-ID/REPO@REPO-ID:ref:refs/heads/obf-lab" -> "repo:OWNER@OWNER-ID/REPO@REPO-ID:environment:obf-env"
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
[Run azure/login@v3]  subject claim - repo:OWNER@OWNER-ID/REPO@REPO-ID:environment:obf-env
[Run azure/login@v3] Azure CLI login succeeds by using OIDC.
[Who am I]   "userType": "servicePrincipal"

6.4 Google Cloud: the login works but gcloud auth list shows no account

This is not an error, but it looks like one. The login succeeded, and gcloud auth list printed this:

# Real output: google-github-actions/auth succeeded; gcloud auth list shows nothing
[Run google-github-actions/auth@v3] ⚠️ The "create_credentials_file" option is true, but the current GitHub workspace is empty. Did you forget to use "actions/checkout" before this step? If you do not intend to share authentication with future steps in this job, set "create_credentials_file" to false.
[Run google-github-actions/auth@v3] Created credentials file at "/home/runner/work/REPO/REPO/gha-creds-<hex>.json"
[Who am I] gcloud auth list
[Who am I]
[Who am I] No credentialed accounts.
[Who am I]
[Who am I] To login, run:
[Who am I]   $ gcloud auth login `ACCOUNT`
[Who am I]
[Who am I] PROJECT-ID	ACTIVE
[Post Run google-github-actions/auth@v3] Removed exported credentials at "/home/runner/work/REPO/REPO/gha-creds-<hex>.json"

The action hands gcloud an external-account credentials file through CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE, and gcloud auth list only lists accounts stored by gcloud auth login. The proof of the login is the project line PROJECT-ID ACTIVE from gcloud projects describe, which the roles/viewer role allows. The warning about the empty workspace is harmless here because the job has no checkout. To see which identity gcloud uses, ask Google about the access token; that needs the userinfo.email scope, which is why the workflow above sets access_token_scopes:

# Real output: tokeninfo for the access token of the job
[Who am I] PROJECT-ID	ACTIVE
[Who am I] {
[Who am I]   "email": "obf-oidc-sa@PROJECT-ID.iam.gserviceaccount.com",
[Who am I]   "email_verified": "true"
[Who am I] }

6.5 Google Cloud: The given credential is rejected by the attribute condition

We changed only the provider condition with Terraform (allowed_repo = "OWNER/other-repo") and re-ran the successful run.

# Real output, condensed [...]: terraform apply with a different repository in the condition (state-changing; one in-place update)
      ~ attribute_condition                = "assertion.repository == \"OWNER/REPO\"" -> "assertion.repository == \"OWNER/other-repo\""
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
# Real output: the auth step fails in the token exchange, before gcloud runs
[Run google-github-actions/auth@v3] ##[error]google-github-actions/auth failed with: failed to generate Google Cloud federated token for //iam.googleapis.com/projects/PROJECT-NUMBER/locations/global/workloadIdentityPools/obf-gh-pool/providers/obf-gh-provider: {"error":"unauthorized_client","error_description":"The given credential is rejected by the attribute condition."}

The message means the token reached the Security Token Service and the provider's condition said no. Compare the attributeCondition that gcloud iam workload-identity-pools providers describe prints (section 3) with the repository claim of the token (section 2): the condition must name OWNER/REPO. Our change took effect on the first re-run after the apply, with no wait. The fix is to apply allowed_repo = "OWNER/REPO" again and re-run; the run then printed PROJECT-ID ACTIVE and the service account e-mail.

6.6 Google Cloud: the binding names the wrong repository (403 after a delay)

Here the condition is right, so the token exchange works, and the failure moves to the impersonation step. We changed only the binding (github_repo = "OWNER/other-repo"); the principal set changed to .../attribute.repository/OWNER/other-repo, Terraform replaced the binding (1 added, 0 changed, 1 destroyed).

The first re-run, a few seconds after the apply, still showed the old state and succeeded. A re-run at about three minutes had the new state and failed in the first step that used gcloud, with the auth step green:

# Real output: the auth step is green, the next gcloud call fails (details trimmed to the relevant fields)
[Who am I] ERROR: (gcloud.projects.describe) There was a problem refreshing your current auth tokens: ('Unable to acquire impersonated credentials', '{
  "error": {
    "code": 403,
    "message": "Permission 'iam.serviceAccounts.getAccessToken' denied on resource (or it may not exist). Remediate access with this Troubleshooter URL or share it with your administrator - https://console.cloud.google.com/iam-admin/troubleshooter/summary;errorId=<id> .",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "IAM_PERMISSION_DENIED",
        "domain": "iam.googleapis.com",
        "metadata": {
          "permission": "iam.serviceAccounts.getAccessToken",
          "error_info_id": "<id>",
          "troubleshooter_url": "..."
        }
      }
    ]
  }
}
')
[Who am I] ##[error]Process completed with exit code 1.

The fix is to apply the right repository again. The first re-run right after the fix still failed with the same 403, and a re-run at about 90 seconds passed. These are single observations, not a measured delay: after an IAM binding change, re-run once after a few minutes before you conclude anything. The attribute condition change in section 6.5 took effect on the first re-run.

7. Verify

  • Azure: the azure/login step ends with Azure CLI login succeeds by using OIDC., az account show prints "userType": "servicePrincipal" with your subscription ID, and az group list lists only the resource group you gave Reader on.
  • Google Cloud: gcloud projects describe prints PROJECT-ID ACTIVE, and the tokeninfo call prints the service account e-mail, not a person.
  • No stored secret: az ad app credential list --id <app object id> returns [], and gh secret list prints nothing. Both were true in our run.

Common mistakes

  • Writing the subject by hand from a tutorial. On a repository created after 15 July 2026 the classic form does not match (section 6.1). Read it with gh api and pass it as a variable.
  • Moving a job into an environment without changing the credential. The subject ends in :environment:NAME and the branch credential no longer matches (section 6.3).
  • Forgetting id-token: write. GitHub documents how a permissions: block affects the other permissions under permissions for the GITHUB_TOKEN (we did not test it here); if the job checks out code, list contents: read too (section 6.2).
  • Trusting gcloud auth list. It shows no account even when the login worked (section 6.4). Use gcloud projects describe or the tokeninfo call.
  • Judging an IAM change too early. After a binding change wait a few minutes and re-run once before you debug (section 6.6).
  • Leaving out the attribute condition on Google. Google requires one for this issuer. Without a repository in it, the trust is wider than you want.
  • Keeping the name-based condition. Ours uses assertion.repository, a lab minimum; Google recommends the numeric *_id fields (section 3).
  • Reusing a pool id right after a destroy. The deleted pool still existed in state DELETED and its id could not be reused, so use another pool id (section 9).

8. What was not tested

  • Pull request and tag subjects. No pull request or tag was created; the scratch rules allowed only the obf-lab branch.
  • Opting a repository in or out of the immutable format, and a custom sub template. The API was never called to change the setting, and we had no older repository, so we did not see the classic subject on an existing repository.
  • Audience and issuer mismatches on Azure.
  • Flexible federated credentials with claimsMatchingExpression, wildcards, and a second credential on the same app.
  • Google principal:// bindings, a condition on assertion.sub (these would break with the immutable subject, not run), a condition on repository_id, and direct resource access without a service account.
  • Organization or tenant policies that restrict app registrations or workload identity federation, and GitHub Enterprise Server or self-hosted runners.
  • The token without &audience=, and AWS.
  • The final code as shown. After the lab we replaced the hard-coded region and location with variables with placeholder defaults and removed an unused google_project data source; the files were not applied again after that edit. Both edited configurations pass terraform init and terraform validate on Terraform 1.17.2 ("Success! The configuration is valid.").
  • A RHEL-family twin. There are no distribution-specific commands on this page; the Terraform, az, gcloud and gh commands ran only on one Ubuntu 26.04 test machine.

9. Rollback and cleanup

terraform destroy removes everything on each side. Run it in each folder; it lists the plan and waits for you to type yes (our run used -auto-approve). On Azure the role assignment goes before the resource group.

# State-changing: destroy the Azure resources, then the Google Cloud resources (run in each Terraform folder)
terraform destroy
terraform state list
# Real output, Azure, condensed (terraform state list printed nothing afterwards)
azuread_application_federated_identity_credential.branch: Destruction complete after 23s
azurerm_role_assignment.reader: Destruction complete after 2s
azurerm_resource_group.oidc: Destruction complete after 22s
azuread_service_principal.gh: Destruction complete after 23s
azuread_application.gh: Destruction complete after 22s
Destroy complete! Resources: 5 destroyed.
# Real output, Google Cloud, condensed
google_service_account_iam_member.wif: Destruction complete after 6s
google_project_iam_member.viewer: Destruction complete after 9s
google_service_account.gh: Destruction complete after 1s
google_iam_workload_identity_pool_provider.gh: Destruction complete after 12s
google_iam_workload_identity_pool.gh: Destruction complete after 11s
google_project_service.sts: Destruction complete after 12s
Destroy complete! Resources: 6 destroyed.

sts.googleapis.com was enabled by Terraform and disabled again by destroy. iam and iamcredentials were already enabled before the lab and stayed enabled, which is why the code does not manage them.

On GitHub we deleted the workflow runs, the six repository variables, the environment and the branch. Read-only checks afterwards: gh variable list and gh secret list printed nothing, gh api repos/OWNER/REPO/environments --jq ".environments[].name" printed nothing, and the remote had only the branches that existed before.

After the destroy, a read-only look showed the workload identity pool in state DELETED and the app registration in the Entra recycle bin: deletion in both clouds is soft. We left both alone. The pool id could not be reused, so a repeat of the lab needs another pool id.

# Real output: read-only look at the soft-deleted objects after destroy
$ gcloud iam workload-identity-pools list --location=global --show-deleted --format="table(name.basename(),state)"
NAME         STATE
obf-gh-pool  DELETED
$ az rest --method get --url "https://graph.microsoft.com/v1.0/directory/deletedItems/microsoft.graph.application?$filter=displayName eq 'obf-gh-oidc'" --query "value[].{name:displayName}" -o json
[
  {
    "name": "obf-gh-oidc"
  }
]

References

Official reference

docs.github.com ↗

Technical steps are original explanations; consult the upstream documentation for version-specific details.

Behavior differs by distribution and tool version. Commands are examples for authorized systems; review output for secrets before sharing.

Found this useful?

Follow us on YouTube for video explainers, and find us on Facebook to keep up with what is new.