GitHub Actions Cloud Run Deployment Setup (Workload Identity Federation)
Purpose
Set up automated Cloud Run deployments via GitHub Actions using Workload Identity Federation (WIF) instead of long-lived JSON keys.When to run this
- Initial CI/CD setup for GitHub Actions → Cloud Run
- Migration from JSON keys to WIF
- Troubleshooting auth/permission/deploy failures in workflow runs
Prerequisites
- GCP project
payroll-bi-gauntletexists gcloudCLI installed and authenticated- GitHub repository:
payroll-pipeline-cbs - GitHub Actions enabled for the repository
Inputs
- Service:
payroll-pipeline-cbs-api - Project:
payroll-bi-gauntlet - Region:
us-central1 - Runtime Service Account:
sa-worker@payroll-bi-gauntlet.iam.gserviceaccount.com - Authentication: Workload Identity Federation (no JSON keys)
Procedure
1) Create deployment service account
2) Create workload identity pool and provider
3) Configure IAM binding (restrict to repository)
4) Configure GitHub secrets
Go to your GitHub repository → Settings → Secrets and variables → Actions → New repository secret Add the following secrets:| Secret Name | Value | How to Get |
|---|---|---|
WIF_PROVIDER | Full provider resource name | Run: gcloud iam workload-identity-pools providers describe github-provider --project=payroll-bi-gauntlet --location=global --workload-identity-pool=github-actions-pool --format="value(name)" |
WIF_SERVICE_ACCOUNT | Service account email | sa-github-deployer@payroll-bi-gauntlet.iam.gserviceaccount.com |
5) Verify setup
Verification
.github/workflows/deploy_cloudrun.yml is already configured with:
- Trigger: Push to
mainbranch (when API files change) - Authentication: WIF via
google-github-actions/auth@v2 - Deployment:
gcloud run deploy --source . - SHA Verification: Automatically verifies
/api/healthreturns correctgit_commit_sha
Failure modes & fixes
Workflow fails with “Permission denied”
- Verify
WIF_PROVIDERsecret matches the full resource name - Verify
WIF_SERVICE_ACCOUNTsecret matches the service account email - Check IAM bindings:
gcloud iam service-accounts get-iam-policy sa-github-deployer@payroll-bi-gauntlet.iam.gserviceaccount.com
Workflow fails with “Service account not found”
- Verify service account exists:
gcloud iam service-accounts describe sa-github-deployer@payroll-bi-gauntlet.iam.gserviceaccount.com - Check project ID matches:
gcloud config get-value project
SHA verification fails
- Check
/api/healthendpoint returnsgit_commit_shafield - Verify
GIT_COMMIT_SHAenvironment variable is set correctly in deployment - Check Cloud Run logs for errors:
gcloud logging read "resource.type=cloud_run_revision" --limit=50
Deployment times out
- Increase
timeout-minutesin workflow if needed - Check Cloud Build quotas:
gcloud compute project-info describe --project=payroll-bi-gauntlet
Artifacts produced
- Deployer service account and IAM bindings
- Workload identity pool/provider configuration
- GitHub Actions repository secrets (
WIF_PROVIDER,WIF_SERVICE_ACCOUNT) - Successful workflow run and Cloud Run revision with SHA verification
Related docs
Supporting reference
Required IAM roles explained
| Role | Purpose |
|---|---|
roles/run.admin | Create/update Cloud Run services and revisions |
roles/iam.serviceAccountUser | Act as runtime service account (sa-worker) |
roles/cloudbuild.builds.editor | Submit Cloud Build jobs (needed for --source deployments) |
roles/storage.admin | Upload source code to Cloud Storage (needed for --source deployments) |
Security best practices
- Repository Restriction: WIF binding restricts access to
abundy1/payroll-pipeline-cbsonly - Branch Restriction (optional): Can further restrict to
mainbranch only - Least Privilege: Service account has only the minimum required roles
- No JSON Keys: WIF eliminates the need for long-lived credentials
- Audit Trail: All deployments are logged in Cloud Run and GitHub Actions
Migration from JSON keys
If you’re currently usingGCP_SA_KEY secret:
- Complete the WIF setup above
- Update
.github/workflows/deploy_cloudrun.yml(already done) - Add
WIF_PROVIDERandWIF_SERVICE_ACCOUNTsecrets - Test deployment via
workflow_dispatch - Remove
GCP_SA_KEYsecret after verification