How to replace service account JSON keys in GitHub secrets with a workload identity pool, an OIDC provider that checks the repository, and a service account the workflow impersonates.

A service account JSON key in a GitHub secret is a password that never expires, and it can be copied out of a log or a compromised action. Workload Identity Federation removes it: GitHub signs a token for every run, Google exchanges it for short-lived credentials, and nothing long-lived is stored.
The setup has four parts: a pool, a provider that trusts GitHub, an IAM binding to a service account, and the workflow.
Google documents federation for deployment pipelines, including GitHub Actions. With gcloud:
The attribute condition is what keeps other GitHub accounts out of the provider, and the ref check keeps branch and pull request workflows from getting deploy credentials. Google recommends the numeric repository_owner_id and repository_id claims over names. Names can be reclaimed by someone else if you delete a repository or organization, while the numeric IDs cannot.
Grant the pool's identity for your repository the right to impersonate the deploy service account, using the project number rather than the project ID in the member string:
The service account then carries the deploy permissions, for example Artifact Registry writer and Cloud Run developer, and nothing more. Review it like any other IAM binding because it defines what a compromised workflow could do.
name: deploy
on:
push:
branches: [main]
permissions:
id-token: write # lets the job request the OIDC token
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- id: auth
uses: google-github-actions/auth@v3
with:
workload_identity_provider: projects/123456789/locations/global/workloadIdentityPools/github/providers/github-oidc
service_account: deploy@my-project.iam.gserviceaccount.com
- uses: google-github-actions/setup-gcloud@v3
- run: gcloud run services list --region europe-west1
The auth action handles the token exchange and writes credentials that gcloud and the client libraries pick up. If the provider or service account value is wrong, the step fails before any other command runs. Pin each action to a full commit SHA rather than a tag, since every step after the auth step runs with the deploy credentials.
The error The given credential is rejected by the attribute condition means the token's claims did not satisfy the provider's condition, so print the claims and compare them with the condition. A failure to impersonate the service account means the binding is missing, uses the project ID instead of the project number, or names a different attribute than the one you mapped. A job that fails to get a token at all is missing id-token: write. Pool and provider changes can also take a few minutes to propagate. The federation overview lists the supported providers and the claims they provide.
Encore brings infrastructure from code, and for GCP the own cloud docs describe the recommended setup: you add an IAM binding in your own organization or project for the Google-managed service account the Encore platform provides for each app, and you choose its roles, down to a single project. You share no long-lived key with Encore, and access ends when you remove the binding. Link the repository through the GitHub integration, and a push to the configured branch deploys to your project.

Run in your terminal to get started locally.
// media/media.go
package media
import (
"encore.dev/storage/objects"
"encore.dev/storage/sqldb"
)
// Declared in code. A deploy provisions the Cloud Storage bucket and the
// Cloud SQL database in the connected project.
var Uploads = objects.NewBucket("uploads", objects.BucketConfig{})
var db = sqldb.NewDatabase("media", sqldb.DatabaseConfig{
Migrations: "./migrations",
})
The workflow has no federation setup because the platform deploys the code, and the Cloud Storage buckets and databases it declares are created in your project as the GCP infrastructure docs describe. A coding agent adding a bucket edits the Go file and runs it locally, with no service account or IAM binding to write separately.
Best fit: Teams that deploy to their own Google Cloud project and want to avoid maintaining a pool, a provider and bindings for CI.
The workflow gets an OIDC token from GitHub, Google's security token service exchanges it for a short-lived federated token according to the pool and provider settings, and the workflow can then impersonate a service account. No service account JSON key is stored in GitHub.
Without one, any GitHub repository could present a token to the provider. A condition on the repository or, better, the repository ID restricts the provider to your repositories, and the principalSet in the IAM binding narrows access further.
The identity from the pool needs roles/iam.workloadIdentityUser on the target service account. The service account itself holds the deploy roles, such as permission to push images and update a Cloud Run service.
With Encore, you add an IAM binding in your own GCP organization or project that grants the roles you choose to the service account the Encore platform provides for your app, and link the GitHub repository. Removing the binding ends access. A push to the configured branch deploys, and the workflow stores no cloud keys.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.