This Terraform project provisions Google Cloud Workload Identity Federation (WIF) infrastructure to enable keyless authentication for GitHub Actions workflows interacting with GCP services (e.g., CodeMender backend APIs on Vertex AI).
Keyless authentication via Workload Identity Federation eliminates the need to store long-lived service account key JSON files in GitHub Secrets. Instead, GitHub Actions requests a short-lived OIDC token from GitHub, which Google Cloud exchanges for a short-lived GCP access token based on trust rules configured in this repository.
- Google Cloud Service Account (
google_service_account):- Service account impersonated by GitHub Actions runners.
- Project IAM Role Assignment (
google_project_iam_member):- Grants
roles/aiplatform.userto the service account so it can call Vertex AI / CodeMender backend APIs.
- Grants
- Workload Identity Pool (
google_iam_workload_identity_pool):- Manages identity mappings between GitHub Actions OIDC tokens and GCP identities.
- Workload Identity Provider (
google_iam_workload_identity_pool_provider):- Configured with GitHub OIDC issuer (
https://token.actions.githubusercontent.com). - Attribute Mappings:
google.subject=assertion.subattribute.repository=assertion.repository
- Configured with GitHub OIDC issuer (
- WIF Service Account Trust Binding (
google_service_account_iam_member):- Grants
roles/iam.workloadIdentityUserto the GitHub repository restricted byattribute.repository(default:nathanielhall/juice-shop).
- Grants
- Terraform >= 1.0.0
- Google Cloud SDK (
gcloud) installed and authenticated - A GCP project with the necessary APIs enabled:
- IAM Service Account API (
iam.googleapis.com) - Security Token Service API (
sts.googleapis.com) - IAM Credentials API (
iamcredentials.googleapis.com) - Vertex AI API (
aiplatform.googleapis.com)
- IAM Service Account API (
terraform initProvide your GCP Project ID when prompted or via a terraform.tfvars file:
terraform plan -var="project_id=YOUR_GCP_PROJECT_ID"terraform apply -var="project_id=YOUR_GCP_PROJECT_ID"| Name | Description | Type | Default | Required |
|---|---|---|---|---|
project_id |
The GCP project ID where WIF resources will be provisioned. | string |
N/A | Yes |
region |
The default GCP region. | string |
"us-central1" |
No |
workload_identity_pool_id |
The ID of the Workload Identity Pool. | string |
"github-actions-pool" |
No |
workload_identity_provider_id |
The ID of the Workload Identity Pool Provider. | string |
"github-actions-provider" |
No |
service_account_id |
The account ID for the Google Cloud Service Account. | string |
"codemender-github-sa" |
No |
github_repository |
The GitHub repository allowed to impersonate the service account (owner/repo). |
string |
"nathanielhall/juice-shop" |
No |
| Name | Description |
|---|---|
WIF_SERVICE_ACCOUNT |
The email address of the created Service Account. |
WIF_PROVIDER |
The full resource name of the Workload Identity Provider. |
After running terraform apply, copy the values from WIF_SERVICE_ACCOUNT and WIF_PROVIDER into your GitHub repository secrets or environment variables.
Example workflow step using google-github-actions/auth:
name: CodeMender Pipeline
on:
push:
branches: [ main ]
jobs:
codemender:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # Required for requesting the JWT OIDC token
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: '${{ secrets.WIF_PROVIDER }}'
service_account: '${{ secrets.WIF_SERVICE_ACCOUNT }}'
# Subsequent steps now run with authenticated GCP credentials