Security
CI/CD
Best practices

Keyless deploys: let CI prove who it is (OIDC)

Eliminating long-lived service account keys in GitHub Actions using Workload Identity Federation

Use OpenID Connect and Google Cloud Workload Identity Federation to authenticate CI pipelines without long-lived JSON keys.
Published

2026-09-26

Modified

2026-09-26

The problem

Deploying code from CI to cloud providers traditionally begins with a dangerous ritual:

  1. Generate a service account in your cloud console.
  2. Download a long-lived credential file (such as a Google Cloud JSON service account key or an AWS access key pair).
  3. Paste that JSON blob into GitHub repository secrets (GCP_SA_KEY).
  4. Hope nobody ever logs it, forks the repo, or compromises an action that reads it.

This practice carries severe operational and compliance liabilities:

  • No built-in expiration. A service account JSON key never expires. If an action dumps environment variables or a malicious dependency exfiltrates the secret, the key remains valid until someone manually notices and revokes it.
  • Rotation debt. Rotating keys across multiple repositories is tedious, so teams rarely do it. In GxP environments, static shared keys weaken the audit trail because any system holding the key appears identical in access logs.
  • Accidental exposure. A single misplaced echo statement or debugging chunk in an R Markdown or Quarto document can print environment variables into build logs, exposing the entire key (see secret scanning).

The solution is to eliminate static keys entirely. Instead of storing a secret in GitHub, let GitHub cryptographically prove its identity to the cloud on every single run.

The web-repo way: Workload Identity Federation

Modern cloud architectures use OpenID Connect (OIDC) and Workload Identity Federation (WIF).

How OIDC authentication works

  1. When a workflow job starts, GitHub’s OIDC token service generates a signed, short-lived JSON Web Token (JWT) describing the workflow (the repository, the commit, the branch, and the triggering event).
  2. The GitHub Action sends this token to Google Cloud’s Security Token Service (STS).
  3. Google Cloud validates the token’s cryptographic signature using GitHub’s published signing keys (OIDC discovery/JWKS at the issuer: https://token.actions.githubusercontent.com).
  4. If the token claims match the configured trust rules, Google exchanges the GitHub token for a temporary, short-lived (by default about an hour) Google Cloud access token.
  5. The workflow deploys using that short-lived token. When the job finishes, the token expires automatically.

Configuring keyless federation in Google Cloud

In Google Cloud, we configure a Workload Identity Pool and an OIDC Provider pinned strictly to the repository:

PROJECT_ID=my-project
PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format='value(projectNumber)')
SA=gh-deploy@$PROJECT_ID.iam.gserviceaccount.com

# 1. Create the pool and GitHub OIDC provider
gcloud iam workload-identity-pools create github --project=$PROJECT_ID \
  --location=global --display-name="GitHub Actions"

gcloud iam workload-identity-pools providers create-oidc playbook --project=$PROJECT_ID \
  --location=global --workload-identity-pool=github --display-name="my-site" \
  --issuer-uri="https://token.actions.githubusercontent.com" \
  --attribute-mapping="google.subject=assertion.sub,attribute.repository_id=assertion.repository_id,attribute.repository_owner_id=assertion.repository_owner_id" \
  --attribute-condition="assertion.repository_owner_id=='<OWNER_ID>' && assertion.repository_id=='<REPO_ID>'"

# 2. Grant minimal IAM roles to a dedicated deployment service account
gcloud iam service-accounts create gh-deploy --project=$PROJECT_ID \
  --display-name="GitHub deploy: my-site"

gcloud projects add-iam-policy-binding $PROJECT_ID --member="serviceAccount:$SA" \
  --role=roles/firebasehosting.admin
gcloud projects add-iam-policy-binding $PROJECT_ID --member="serviceAccount:$SA" \
  --role=roles/serviceusage.apiKeysViewer

# 3. Allow workflows matching our repository ID to impersonate the service account
gcloud iam service-accounts add-iam-policy-binding $SA --project=$PROJECT_ID \
  --role=roles/iam.workloadIdentityUser \
  --member="principalSet://iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/github/attribute.repository_id/<REPO_ID>"

Notice the attribute condition:

assertion.repository_owner_id == '<OWNER_ID>' && assertion.repository_id == '<REPO_ID>'

We pin to GitHub’s numeric repository and owner IDs rather than the string repository name. If the repository or organization is later renamed, the identity assertion cannot be hijacked or broken.

The GitHub Actions workflow

In .github/workflows/quarto.yml, the job requests an OIDC token by declaring id-token: write permissions, then uses google-github-actions/auth@v3:

permissions:
  contents: read
  id-token: write          # Required for requesting the GitHub OIDC JWT

steps:
  - uses: actions/checkout@v7

  - name: Authenticate to Google Cloud (keyless)
    if: env.DEPLOY_ENABLED == 'true'
    uses: google-github-actions/auth@v3
    with:
      workload_identity_provider: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}
      service_account: ${{ vars.GCP_SERVICE_ACCOUNT }}

  - name: Deploy site
    run: |
      npx --yes "$FIREBASE_TOOLS" deploy --only hosting \
        --project "${{ vars.FIREBASE_PROJECT_ID }}"

Variables, not secrets

Notice the workflow syntax: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}.

Because Workload Identity Federation uses cryptographic attestation rather than shared passwords, the provider URI, service account email, and project ID are public identifiers, not secrets. They are stored in repository variables, visible in plain text in the repo settings. An attacker who copies those values cannot authenticate from their own machine or from another repository because Google STS verifies that the requesting JWT originates from our specific GitHub repository ID.

Why not Firebase’s official GitHub Action?

The official Firebase deployment action (FirebaseExtended/action-hosting-deploy) requires users to paste a service account JSON key into GitHub Secrets (FIREBASE_SERVICE_ACCOUNT_...).

Our secrets standard forbids JSON keys (see secrets management). Instead, we authenticate keylessly via google-github-actions/auth@v3, which writes a short-lived credential configuration file (external account, no private key) and points GOOGLE_APPLICATION_CREDENTIALS at it. We then invoke firebase-tools directly using npx. The Firebase CLI automatically picks up the temporary credentials.

The R way: an analogy for R developers

For developers accustomed to R and Shiny, OIDC authentication is the difference between writing your database password into a .Renviron file versus authenticating through your organisation’s Single Sign-On (SSO) system.

  • The static key approach: Copying a static API token into .Renviron or .Renviron.site. If that laptop or server is compromised, the token remains valid indefinitely.
  • The OIDC approach: When you log into an enterprise RStudio Server or Posit Workbench instance via SAML/OIDC, the identity provider checks your credentials, confirms your group memberships, and issues a temporary session token. No service password is typed into R, and access revokes automatically when the session closes.

Cloud and platform support

GitHub provides native OIDC token generation for the three major cloud providers: - Google Cloud: Workload Identity Federation (used here). - Amazon Web Services (AWS): IAM OpenID Connect identity providers and role assumption (aws-actions/configure-aws-credentials). - Microsoft Azure: Azure AD / Entra ID federated credentials (azure/login).

What about Posit Connect and shinyapps.io?

When deploying Shiny applications or Quarto reports to hosting platforms: - Cloud-native targets: Targets you reach through a cloud’s own IAM (e.g. deploying to Cloud Run) can use the same keyless pattern. - Dedicated hosting platforms: Posit Connect and shinyapps.io commonly authenticate deploys with API keys; check your platform’s docs for federation support. If federation is unavailable, follow strict secret discipline (see secrets management): create a scoped, minimally privileged API key, store it in GitHub Secrets, and implement a regular rotation schedule.

Pitfalls we hit

  • Missing id-token: write permission. If your GitHub Actions workflow omits permissions: id-token: write, GitHub will not provide a token. The auth step fails because no OIDC token is available.
  • Pinning repository names instead of IDs. Trusting assertion.repository == "org/repo" is vulnerable if a repository is renamed or an account is transferred. Always pin assertion.repository_id using the immutable numeric identifier.
  • Over-privileged service accounts. Assigning roles/owner or roles/editor to the CI service account breaks the principle of least privilege. Our service account receives only roles/firebasehosting.admin and roles/serviceusage.apiKeysViewer.
  • Assuming third-party actions support keyless auth. Many legacy GitHub Actions still expect a static token or JSON secret. Check action documentation before adopting it; running the underlying CLI tool directly via npx or shell scripts is often cleaner.
NoteUpdates
  • 2026-09-26: Removed the end-of-post checklist.