Kanji
・Cloud engineer / freelance ・Born in 1993 ・From Ehime / Living in Shibuya, Tokyo ・5 years AWS experience Profile details
Table of Contents
google-github-actions/auth@v3
attribute.condition
Replacing long-lived Service Account JSON keys in GitHub Secrets with Workload Identity Federation (WIF) has become standard practice for deploying to Cloud Run and Artifact Registry. Yet the moment you open the google-github-actions/auth@v3 README, you hit an architectural fork: should you use Direct Workload Identity Federation (which Google now marks as Preferred ) or traditional Service Account Impersonation ?
When I inspected an existing Workload Identity Pool in my personal Google Cloud project using gcloud ( 594.0.1 ), I noticed my older setup still relied on a string-based attribute.repository condition. Looking closer at the auth@v3 documentation and live Google Cloud Discovery schemas also surfaced hard boundaries—such as the 10-minute token limit and Signed URL incompatibility—that can break a CI/CD pipeline if you pick Direct WIF blindly.
gcloud
594.0.1
attribute.repository
auth@v3
In this guide, I compare Direct WIF, Service Account Impersonation, and Service Account JSON keys side by side, examine the security traps in attribute.condition and auth@v3 , and walk through both Artifact Registry (Direct WIF) and Cloud Run (Service Account Impersonation) configurations. Note that I have not run a live destructive CI test to trigger the 10-minute single-token expiration boundary in production (not verified in production); the analysis below combines live local gcloud 594.0.1 checks, Google Cloud Discovery API schemas ( sts.googleapis.com , iam.googleapis.com , iamcredentials.googleapis.com ), read-only inspection of an active pool, and official documentation.
gcloud 594.0.1
sts.googleapis.com
iam.googleapis.com
iamcredentials.googleapis.com
principalSet://
principal://
roles/iam.workloadIdentityUser
service_account
credentials_json
auth
signBlob
roles/iam.serviceAccountTokenCreator
In both federation modes, the GitHub Actions runner first requests a signed OIDC JWT from GitHub ( id-token: write ) and exchanges it at Google Cloud Security Token Service ( sts.googleapis.com ) for a federated token. The divergence happens immediately after that exchange.
id-token: write
With Direct WIF, you assign IAM roles directly to the Workload Identity Pool’s principalSet:// (or per-subject principal:// ) URI on a Google Cloud project or resource. For services listed on Google Cloud’s Identity Federation: products and limitations matrix—such as pushing container images to Artifact Registry or uploading build artifacts to Cloud Storage—removing the intermediate service account simplifies IAM audits.
However, you must use Service Account Impersonation if your pipeline hits any of these five boundaries:
roles/iam.serviceAccountUser
iam.serviceAccounts.signBlob
token_format: "access_token"
token_format: "id_token"
constraints/iam.allowServiceAccountCredentialLifetimeExtension
To confirm current CLI flags and API contracts, I checked gcloud ( Google Cloud SDK 594.0.1 ) locally alongside the live Discovery documents for STS ( revision: 20261106 ) and IAM ( revision: 20261126 ).
Google Cloud SDK 594.0.1
revision: 20261106
revision: 20261126
gcloud --version | head -n 5 gcloud iam workload-identity-pools providers create-oidc --help | grep -E "attribute|issuer|allowed|discovery"
Google Cloud SDK 594.0.1 alpha 2026.11.21 beta 2026.11.21 bq 2.1.42 bundled-python3-unix 3.14.9 --attribute-mapping=[KEY=VALUE,...] --issuer-uri=ISSUER_URI [--allowed-audiences=[ALLOWED_AUDIENCES,...]] [--attribute-condition=ATTRIBUTE_CONDITION] [--description=DESCRIPTION] [--disabled] [--discovery-uri=DISCOVERY_URI]
In sts.googleapis.com v1, GoogleIdentityStsV1ExchangeTokenRequest defines audience , grantType , requestedTokenType , scope , subjectToken , and subjectTokenType , while WorkloadIdentityPoolProvider in iam.googleapis.com v1 exposes attributeMapping and attributeCondition alongside oidc , aws , saml , and x509 .
GoogleIdentityStsV1ExchangeTokenRequest
audience
grantType
requestedTokenType
scope
subjectToken
subjectTokenType
WorkloadIdentityPoolProvider
attributeMapping
attributeCondition
oidc
aws
saml
x509
Reading back a provider I had previously set up in a personal GCP project showed the following configuration (project number and repository identifiers masked with placeholders):
attributeCondition: attribute.repository == "my-org/my-repo" attributeMapping: attribute.actor: assertion.actor attribute.repository: assertion.repository google.subject: assertion.sub oidc: issuerUri: https://token.actions.githubusercontent.com state: ACTIVE
At first glance, pinning attribute.repository looks locked down—but relying on mutable repository names introduces a subtle security gap, along with three other common pitfalls in auth@v3 .
repository
repository_owner
All GitHub Actions workflows share the single global OIDC issuer https://token.actions.githubusercontent.com . Without an attributeCondition , any public GitHub repository in the world can enter your Workload Identity Pool.
https://token.actions.githubusercontent.com
Even when you add a condition, matching solely on strings such as assertion.repository == "my-org/my-repo" or assertion.repository_owner == "my-org" leaves a window open if an organization or repository is ever renamed or deleted and later claimed by an external actor (cybersquatting/typosquatting). Use GitHub’s immutable numeric IDs instead:
assertion.repository == "my-org/my-repo"
assertion.repository_owner == "my-org"
# Fetch immutable numeric IDs via GitHub REST API curl -sfL -H "Accept: application/json" "https://api.github.com/orgs/my-org" | jq .id curl -sfL -H "Accept: application/json" "https://api.github.com/repos/my-org/my-repo" | jq .id
assertion.repository_owner_id == '12345678' && assertion.repository_id == '987654321'
For production deployment pools, combine those IDs with assertion.ref == 'refs/heads/main' so feature branches cannot mint deployment tokens. Note that checking assertion.environment == 'production' alone does not restrict the source branch unless you also pair it with assertion.ref in CEL or configure GitHub Environment deployment branch protection rules. Also remember that GitHub repository names are case-insensitive, whereas Google Cloud CEL and IAM string comparisons are strictly case-sensitive.
assertion.ref == 'refs/heads/main'
assertion.environment == 'production'
assertion.ref
While --attribute-condition can evaluate assertion.* claims directly from the incoming JWT, any attribute you reference in an IAM binding ( principalSet://.../attribute.<KEY>/<VALUE> ) must be explicitly mapped in --attribute-mapping . Missing that mapping results in Failed to generate OAuth 2.0 Access Token .
--attribute-condition
assertion.*
principalSet://.../attribute.<KEY>/<VALUE>
--attribute-mapping
Failed to generate OAuth 2.0 Access Token
checkout
gsutil
google-github-actions/auth@v3 upgraded its runtime to Node 24 . GitHub-hosted runners handle this automatically, but older self-hosted runners must be upgraded before bumping from v2 to v3 .
v2
v3
Two workflow ordering details also trip teams up: - Because the generated credentials file ( gha-creds-*.json ) lives inside $GITHUB_WORKSPACE by default ( create_credentials_file: true ), actions/checkout must run before google-github-actions/auth@v3 , and gha-creds-*.json should be listed in .gitignore and .dockerignore . - As documented in auth@v3 , the legacy gsutil command does not read credentials exported by this action; migrate scripts to gcloud storage .
gha-creds-*.json
$GITHUB_WORKSPACE
create_credentials_file: true
actions/checkout
.gitignore
.dockerignore
gcloud storage
google.subject
Google Cloud IAM enforces a strict 127-byte limit on the mapped google.subject principal identifier. When google.subject=assertion.sub is used on repositories with long organization, repository, or branch names ( repo:my-org/long-repo-name:ref:refs/heads/feature/long-branch ), authentication fails immediately with:
google.subject=assertion.sub
repo:my-org/long-repo-name:ref:refs/heads/feature/long-branch
The size of mapped attribute exceeds the 127 bytes limit.
Keeping repository and branch names concise avoids this, or you can construct a compact google.subject mapping built around fixed-length numeric IDs ( assertion.repository_id + ":" + assertion.run_id ) when long branch names are unavoidable.
assertion.repository_id + ":" + assertion.run_id
In production CI/CD pipelines, a clean pattern is using Direct WIF for Artifact Registry image pushes and Service Account Impersonation for Cloud Run deployments. Below is the end-to-end setup using gcloud and google-github-actions/auth@v3 .
PROJECT_ID="my-gcp-project" PROJECT_NUMBER="123456789012" POOL_ID="github-actions-pool" PROVIDER_ID="github-actions-provider" REPO_OWNER_ID="12345678" REPO_ID="987654321" DEPLOY_SA="github-deploy@${PROJECT_ID}.iam.gserviceaccount.com" # 1. Create the pool gcloud iam workload-identity-pools create "${POOL_ID}" \ --project="${PROJECT_ID}" \ --location="global" \ --display-name="GitHub Actions Pool" # 2. Create the OIDC provider guarded by immutable IDs and main branch gcloud iam workload-identity-pools providers create-oidc "${PROVIDER_ID}" \ --project="${PROJECT_ID}" \ --location="global" \ --workload-identity-pool="${POOL_ID}" \ --display-name="GitHub Actions Provider" \ --issuer-uri="https://token.actions.githubusercontent.com" \ --attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.repository=assertion.repository,attribute.repository_id=assertion.repository_id,attribute.ref=assertion.ref" \ --attribute-condition="assertion.repository_owner_id == '${REPO_OWNER_ID}' && assertion.repository_id == '${REPO_ID}' && assertion.ref == 'refs/heads/main'"
For Artifact Registry, bind roles/artifactregistry.writer directly to principalSet:// without an intermediate service account. For Cloud Run deployment, grant roles/iam.workloadIdentityUser on the deploy service account ( DEPLOY_SA ) and bind roles/run.developer to that service account.
roles/artifactregistry.writer
DEPLOY_SA
roles/run.developer
MEMBER="principalSet://iam.googleapis.com/projects/${PROJECT_NUMBER}/locations/global/workloadIdentityPools/${POOL_ID}/attribute.repository_id/${REPO_ID}" # Pattern A: Direct WIF for Artifact Registry gcloud projects add-iam-policy-binding "${PROJECT_ID}" \ --member="${MEMBER}" \ --role="roles/artifactregistry.writer" # Pattern B: Service Account Impersonation for Cloud Run deployment gcloud iam service-accounts add-iam-policy-binding "${DEPLOY_SA}" \ --project="${PROJECT_ID}" \ --role="roles/iam.workloadIdentityUser" \ --member="${MEMBER}" gcloud projects add-iam-policy-binding "${PROJECT_ID}" \ --member="serviceAccount:${DEPLOY_SA}" \ --role="roles/run.developer"
name: Build and Deploy (WIF) on: push: branches: - main permissions: contents: read id-token: write jobs: push-image-direct-wif: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v7 - name: Authenticate via Direct WIF (Artifact Registry) uses: google-github-actions/auth@v3 with: project_id: ${{ vars.GCP_PROJECT_ID }} workload_identity_provider: ${{ vars.GCP_WIF_PROVIDER }} # Omit service_account for Direct WIF # Format: projects/123456789012/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider - name: Verify Artifact Registry access with federated token run: gcloud artifacts repositories list --project="${{ vars.GCP_PROJECT_ID }}" --location=asia-northeast1 deploy-cloud-run-impersonation: needs: push-image-direct-wif runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v7 - name: Authenticate via Service Account Impersonation (Cloud Run) uses: google-github-actions/auth@v3 with: workload_identity_provider: ${{ vars.GCP_WIF_PROVIDER }} service_account: ${{ vars.GCP_DEPLOY_SA }}
Always double-check that workload_identity_provider uses the numeric Project Number , not the string Project ID, and includes the full /providers/<provider> suffix. Also note that gcloud auth list only prints locally configured accounts and does not test remote authorization—verify access against the actual target API (such as gcloud artifacts repositories list ).
workload_identity_provider
/providers/<provider>
gcloud auth list
gcloud artifacts repositories list
When google-github-actions/auth@v3 fails, the wording of the error pinpoints which layer rejected the request:
Failed to generate Google Cloud federated token
permissions.id-token: write
/providers/...
The size of mapped attribute exceeds the 127 bytes limit
assertion.sub
repository_id
When setting up new GitHub Actions deployments to Google Cloud, start by using Direct WIF for supported services such as Artifact Registry or Cloud Storage, and pair it with Service Account Impersonation when deploying to Cloud Run, signing Cloud Storage URLs, or minting ID tokens. Either way, locking attribute.condition to immutable numeric repository_owner_id and repository_id values is worth doing on day one.
repository_owner_id
For my own older pools still using mutable attribute.repository strings, I still need to decide the cleanest timing to migrate them to immutable IDs alongside Terraform state management.
Real-time AI quant analysis of earnings reports, corporate filings, and momentum indicators for global equities and Japanese stocks.
Master conversation skills with realistic AI phone training and 5-axis feedback. Includes 16-lesson interactive academy and studio AI portraits.
Effortlessly snap receipts for instant AI itemization. Integrated with LINE for seamless group expense tracking and pain-free settlement.
Interactive AI personas (Fortune Teller, Butler, Bartender) host real-time games, challenges, and conversation starters for unforgettable gatherings.
Unbiased healthcare database featuring zero-additive filters and active ingredient cost performance metrics.