Originally published on DevToolHub.

Workload identity federation GitHub Actions and GitLab CI flow: each job sends an OIDC token to a GCP pool, a repo condition accepts or rejects it, and the job impersonates a service account

With workload identity federation GitHub Actions and GitLab CI jobs call GCP using a short-lived token instead of a service account key. You create a workload identity pool, add one OIDC provider per CI system, and let the pool impersonate a service account. I ran this end to end on 3 December 2026 for both CI systems, and the first GitHub run failed for a reason the docs only half explain.

I tested with the Google Cloud SDK 594.0.1 in a Docker container, google-github-actions/auth@v3 on a GitHub-hosted runner, and a GitLab.com pipeline using google/cloud-sdk:slim. Both jobs authenticated as the same service account. A second GitHub repo that I left out of the condition was rejected.

In this guide:

  • Create one pool with a GitHub provider and a GitLab provider
  • Lock each provider to a single repo or project
  • Authenticate a workflow and a pipeline without a key file
  • Avoid the delay, permission and cleanup traps I hit

How does workload identity federation GitHub Actions authentication work?

The job asks its CI platform for an OIDC token, sends it to Google's Security Token Service, and gets back a short-lived federated token. That token then impersonates a service account. No secret is stored in the repo, so there is no key to leak or rotate. Google's deployment pipeline guide describes the same flow.

Three objects on the GCP side make it work:

Object What it does My test name
Pool Groups external identities dth-wif-pool
Provider Trusts one issuer and applies a condition dth-github, dth-gitlab
Service account binding Lets the pool impersonate the account roles/iam.workloadIdentityUser

If you still create keys today, the service account key guide shows what this replaces.

How do you set up workload identity federation GitHub Actions on GCP?

Create the pool, a provider restricted to one repo, a service account, and a binding. These commands ran against a real project. Set PROJECT and NUMBER (the project number) first.

PROJECT=my-project NUMBER=123456789012 REPO=my-org/my-repo gcloud iam workload-identity-pools create my-pool \ --location=global --project=$PROJECT gcloud iam workload-identity-pools providers create-oidc my-github \ --location=global --workload-identity-pool=my-pool \ --project=$PROJECT \ --issuer-uri=https://token.actions.githubusercontent.com \ --attribute-mapping='google.subject=assertion.sub,attribute.repository=assertion.repository' \ --attribute-condition="assertion.repository=='$REPO'" gcloud iam service-accounts create my-ci-sa --project=$PROJECT 

Warning: The condition is not optional in practice. GitHub, GitLab and HCP Terraform use one issuer URL for every customer, so Google tells you to restrict tokens to your own organization. Without a condition, another organization's token could reach your pool.

Now let tokens from that repo impersonate the service account. The service account needs its own roles for whatever the job does. I gave mine roles/browser on the project and called gcloud projects describe.

gcloud iam service-accounts add-iam-policy-binding \ my-ci-sa@$PROJECT.iam.gserviceaccount.com \ --project=$PROJECT --role=roles/iam.workloadIdentityUser \ --member="principalSet://iam.googleapis.com/projects/$NUMBER/locations/global/workloadIdentityPools/my-pool/attribute.repository/$REPO" 

The workflow needs id-token: write. This is the file that passed on the runner:

name: WIF test on: workflow_dispatch permissions: contents: read id-token: write jobs: gcp: runs-on: ubuntu-latest steps: - uses: google-github-actions/auth@v3 with: workload_identity_provider: projects/123456789012/locations/global/workloadIdentityPools/my-pool/providers/my-github service_account: my-ci-sa@my-project.iam.gserviceaccount.com - uses: google-github-actions/setup-gcloud@v3 - run: gcloud projects describe my-project --format='value(projectId)' 

The job printed the project ID, so it ran as the service account. For more on what each permissions line grants, see the GitHub Actions security guide.

How do you use the same pool from GitLab CI?

Add a second provider for https://gitlab.com, map the project path, and declare an ID token in the job. GitLab's ID token docs cover the id_tokens keyword. The audience must match what the provider expects.

gcloud iam workload-identity-pools providers create-oidc my-gitlab \ --location=global --workload-identity-pool=my-pool \ --project=$PROJECT --issuer-uri=https://gitlab.com \ --allowed-audiences=https://iam.googleapis.com/projects/$NUMBER/locations/global/workloadIdentityPools/my-pool/providers/my-gitlab \ --attribute-mapping='google.subject=assertion.sub,attribute.project_path=assertion.project_path' \ --attribute-condition="assertion.project_path=='my-group/my-project'" gcloud iam service-accounts add-iam-policy-binding \ my-ci-sa@$PROJECT.iam.gserviceaccount.com \ --project=$PROJECT --role=roles/iam.workloadIdentityUser \ --member="principalSet://iam.googleapis.com/projects/$NUMBER/locations/global/workloadIdentityPools/my-pool/attribute.project_path/my-group/my-project" 

The pipeline writes the token to a file, builds a credential config from it, and logs in:

wif: image: google/cloud-sdk:slim id_tokens: GCP_TOKEN: aud: https://iam.googleapis.com/projects/123456789012/locations/global/workloadIdentityPools/my-pool/providers/my-gitlab script: - echo "$GCP_TOKEN" > "$CI_PROJECT_DIR/.token" - gcloud iam workload-identity-pools create-cred-config projects/123456789012/locations/global/workloadIdentityPools/my-pool/providers/my-gitlab --service-account=my-ci-sa@my-project.iam.gserviceaccount.com --credential-source-file="$CI_PROJECT_DIR/.token" --output-file="$CI_PROJECT_DIR/cred.json" - gcloud auth login --cred-file="$CI_PROJECT_DIR/cred.json" - gcloud projects describe my-project --format='value(projectId)' 

The job log showed Authenticated with external account credentials for the service account, then the project ID, then Job succeeded. The token is in the job's workspace while it runs, so keep the pipeline private and do not print the file.

Why did my first workload identity federation GitHub Actions run fail?

The first GitHub run failed a few minutes after I created the binding with Permission 'iam.serviceAccounts.getAccessToken' denied on resource (or it may not exist). The token exchange had already worked. Only the impersonation step was denied. I re-ran the same workflow about two minutes later and it passed with no change.

That is IAM propagation. The auth action's README says pools, providers and IAM permissions can take up to 5 minutes to propagate. I hit it twice. Right after I granted myself the pool admin roles, creating the pool returned IAM_PERMISSION_DENIED, and a retry 45 seconds later worked.

So if a brand-new setup fails with a denied error, check the binding with get-iam-policy, then wait a few minutes before changing anything. Rewriting a correct binding just resets your wait.

Three other traps cost me time:

  • Missing permissions. Creating a pool needs permissions that editor and projectIamAdmin do not include. I needed roles/iam.workloadIdentityPoolAdmin and roles/iam.serviceAccountAdmin temporarily.
  • The STS API was off. sts.googleapis.com was disabled in my project, so I enabled it.
  • A dangling binding after deleting the service account. Deleting my-ci-sa left a deleted:serviceAccount:... entry for its roles/browser grant on the project. Remove it by hand.

Does the attribute condition really block other repos?

Yes. I created a second private GitHub repo with the same workflow and pointed it at the same provider. It failed at the token exchange with unauthorized_client: The given credential is rejected by the attribute condition. It never reached impersonation.

This is the check that matters. Everything before it in the flow is identical for every repo on GitHub, so the condition is the only thing keeping your pool private.

Should the condition use names or numeric IDs?

Use the numeric IDs. Google warns that repository and repository_owner are names, and that someone may claim a name after you delete a repo or organization. It recommends the *_id claims, which are unique and cannot be reused. For GitLab it lists project_id and namespace_id as the stable equivalents.

Note: My first test used the repo name, because it is the easiest to read. I then tested repository_id on GitHub. I renamed the repo, and the same workflow still passed because the ID did not change. Then I created a new repo that took the old name. It passed a name-based condition and was rejected by the ID-based one. Map repository_id and bind attribute.repository_id/<ID>. I did not test GitLab's project_id, so run the same positive and negative checks there.

How do you clean up a workload identity pool?

Delete the providers, then the pool, then the service account, then remove any grants you added to yourself. Google keeps deleted pools and providers for 30 days. You can undelete them in that window, and you cannot reuse the name until the deletion is permanent. Pick pool names you are happy to keep.

gcloud iam workload-identity-pools providers delete my-github \ --location=global --workload-identity-pool=my-pool --project=$PROJECT gcloud iam workload-identity-pools providers delete my-gitlab \ --location=global --workload-identity-pool=my-pool --project=$PROJECT gcloud iam workload-identity-pools delete my-pool \ --location=global --project=$PROJECT 

Then list the project's IAM policy and look for deleted: members. Checking this once saves a confusing audit finding later. If you work across several clouds, the cloud account switching guide helps keep the right project selected, and the Azure managed identity comparison covers the same idea on Azure.

What I did not test

I used a service account for impersonation. The auth README calls direct federation, where the pool gets IAM roles on resources with no service account, the preferred setup. I did not try it. I also did not test GitLab's project_id, branch or environment conditions, GitHub's newer subject format, self-managed GitLab, or access tokens for other Google APIs. Each is a small change to the mapping or condition, and each deserves its own positive and negative run. For the wider workflow layout, see the GitHub Actions workflow guide.

Frequently Asked Questions

Q: Do I still need a service account key with workload identity federation?
A: No. The job gets a short-lived token from its CI platform and exchanges it for a federated token. Nothing is stored in the repo or in CI secrets. You still need a service account if you use impersonation, but only its email address appears in the workflow.

Q: Why does my workload identity federation setup say permission denied right after I created it?
A: IAM changes take time to propagate. My first run failed with getAccessToken denied and passed about two minutes later with no change. The auth action README says up to 5 minutes. Check the binding is correct, then wait before editing anything.

Q: How do I stop other repositories from using my pool?
A: Set an attribute condition on each provider, such as assertion.repository=='my-org/my-repo' for GitHub. A repo outside the condition fails with The given credential is rejected by the attribute condition. Prefer the numeric repository_id or project_id claims, because names can be reclaimed. In my test a squatter repo with the old name passed the name condition and failed the ID one.

Q: Can GitHub Actions and GitLab CI share one pool?
A: Yes. One pool can hold several providers. I used one pool with a GitHub provider and a GitLab provider, each with its own condition, and bound the same service account to both principal sets.

Quick Summary:

  • One pool holds a provider per CI system, and each provider needs an attribute condition to stay private
  • GitHub needs id-token: write and google-github-actions/auth@v3. GitLab needs an id_tokens entry whose aud matches the provider
  • Both jobs authenticated as the same service account with no key file
  • A repo outside the condition was rejected at the token exchange, as expected
  • A new binding failed with getAccessToken denied and worked about two minutes later, so wait before debugging
  • Creating pools needs extra roles, and deleting a service account leaves a dangling deleted: binding
  • Google recommends numeric *_id claims over names, and my test agrees. A new repo that took over the old name passed a name condition and failed the repository_id one

Create the pool and one provider this week, restrict it to a single repo, and run one workload identity federation GitHub Actions workflow before you delete the old key. Then run the same workflow from a second repo and confirm it fails.