# Keyless GitHub Actions to Google Cloud with Workload Identity Federation

> **TL;DR**
>
> Authenticate GitHub Actions to Google Cloud without service account keys by using Workload Identity Federation, then prove it works by uploading a file to a Cloud Storage bucket.
>
> **Time to complete:** about 30 minutes
>
> **Who it's for:** DevOps and platform engineers, and developers who deploy to Google Cloud from GitHub Actions. You should be comfortable with basic IAM and Git.
>
> **You'll need:** a Google Cloud project where you can create IAM resources, a GitHub repository, and the `gcloud` CLI (or Cloud Shell).
>
> **You'll end up with:** a keyless workflow that uploads a folder to a GCS bucket on every push to `main`.

Workload Identity Federation (WIF) lets a GitHub Actions workflow authenticate to Google Cloud with a short-lived token, so you never create, download, or rotate a service account key.

A JSON key is a long-lived password sitting in a GitHub secret: if it leaks, anyone can use it until you notice and delete it. With WIF there is nothing to leak. GitHub issues each job a signed OIDC token, Google's Security Token Service (STS) checks it against rules you define, and the job then impersonates a service account that holds only the permissions it needs.

In this guide you will build a small pipeline that uploads the contents of a folder to a Google Cloud Storage (GCS) bucket on every push to `main`, with no keys anywhere.

## How it works

1. The workflow runs and GitHub issues it an OIDC token that names the repository, branch, and actor.
2. The `auth` action sends that token to Google STS.
3. STS checks the token against the provider's attribute condition. If it matches, it returns a federated token.
4. The federated token impersonates the service account, which returns an access token valid for about an hour.
5. Later steps use that access token to write to the bucket.

![Figure of short-lived token swaps](https://cdn.hashnode.com/uploads/covers/61fe1129fd8b083e5728bdbe/f504519d-4e17-4fbb-8cf4-bad9137afbdb.png align="center")

Every credential in this chain is short-lived and minted per run, so there is no standing secret to steal.

## Create Workload Identity Pools

The pool is a container for external identities

**Console:** go to IAM & Admin, then Workload Identity Federation, and click **Create pool**.

![Workload identity pool](https://cdn.hashnode.com/uploads/covers/61fe1129fd8b083e5728bdbe/9f8cd5e3-1158-4ec8-8d0c-ece74655f569.png align="center")

![Create identity pool](https://cdn.hashnode.com/uploads/covers/61fe1129fd8b083e5728bdbe/c54d4732-cb36-4471-8d86-7963df0362cb.png align="center")

**Name:** `github-action-pool`\
**Description:** `Workload Identity Federation Pool for GitHub Action`

### Add the provider

The provider tells Google how to trust GitHub's tokens.

![Configure provider](https://cdn.hashnode.com/uploads/covers/61fe1129fd8b083e5728bdbe/195f9075-241e-4e8d-80f2-c3a4d8dceed2.png align="center")

**Select a provider:** `OpenID Connect (OIDC)`\
**Provider name:** `github-action-provider`\
**Issuer (URL):** `https://token.actions.githubusercontent.com`

Leave other things default and click `Continue`

### Configure provider attributes

Add these attributes by clicking `Add mapping`

| Google attribute | GitHub token claim | Why you need it |
| --- | --- | --- |
| `google.subject` | `assertion.sub` | Required. Unique identity of the workflow run. |
| `attribute.actor` | `assertion.actor` | The user who triggered the run, useful in audit logs. |
| `attribute.repository` | `assertion.repository` | Lets you grant access to one repo (`owner/name`). |
| `attribute.repository_owner` | `assertion.repository_owner` | Lets you restrict the whole pool to your account or org. |

![configure provider attribute](https://cdn.hashnode.com/uploads/covers/61fe1129fd8b083e5728bdbe/98509fbc-59a4-4a9b-98d7-b89c037f7e66.png align="center")

Under **Attribute conditions**, add the rule below, then click **Save**. `assertion.repository_owner=='<GitHub User>'`

## Create service account

**Name:** `github-action-sa`\
**Description:** `Service account for GitHub action`

![Create service account](https://cdn.hashnode.com/uploads/covers/61fe1129fd8b083e5728bdbe/6571b296-7f52-46bd-ac25-ba06ca9f16b5.png align="center")

Click `create and continue`\
Select the role `Storage Object User`. It can create, read, overwrite, and delete objects in the bucket

![Assign role to service account](https://cdn.hashnode.com/uploads/covers/61fe1129fd8b083e5728bdbe/ba85993e-28f5-475f-9864-5003d7f572ae.png align="center")

Leave other things default and Click `Done`

---

## Connect service account for Workload Identity federation

Click on `github-action-pool` identity pool

![connect sa to workload identity federation](https://cdn.hashnode.com/uploads/covers/61fe1129fd8b083e5728bdbe/792b4e78-a5a2-4161-9da5-fb2fa13e7c10.png align="center")

Now click on `Grant access`

![Grant access to WIF pool](https://cdn.hashnode.com/uploads/covers/61fe1129fd8b083e5728bdbe/ab50521e-bc69-4916-9d51-027b9f39571e.png align="center")

Select `Grant access using service account impersonation`\
**Select Service account:** `github-action-sa`\
**Select repository**: `<github-user>/<repository>`

Click `Save`

This will pop-up for `Configure your application`\
Click `Dismiss` as we don't need it

---

## Verify the workload identity federation

Now we will create secret and env on GitHub repository and deploy GitHub action to verify the connection between the GitHub and Workload Identity federation in GCP.

### Create bucket in GCS

```shell
gcloud storage buckets create gs://<unique-bucket-name> \
  --location=us-east1 \
  --uniform-bucket-level-access
```

![create GCS bucket](https://cdn.hashnode.com/uploads/covers/61fe1129fd8b083e5728bdbe/6ab6718d-8e68-44a4-b5b1-bc8ed8dec07c.png align="center")

### Create this layout.

Note that the folder is `workflows` (plural); GitHub ignores files in any other folder name.

```text
.
├── .github/
│   └── workflows/
│       └── gcs-upload.yaml
└── file-upload/
    └── names.txt
```

Put any text in `file-upload/names.txt`; it is the file we will upload.

### Create workflow

Here is the workflow for our setup `gcs-upload.yaml`

```yaml
name: File upload workflow
run-name: "Upload to GCS"
on:
  push:
    branches: ["main"]
  workflow_dispatch: 
jobs:
  connect-gcp:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read
    env:
      BUCKET: ${{ vars.GCS_BUCKET_NAME }}Select the role Storage Object User. It can create, read, overwrite, and delete objects in the bucketSelect the role Storage Object User. It can create, read, overwrite, and delete objects in the bucketSelect the role Storage Object User. It can create, read, overwrite, and delete objects in the bucket
    steps:
      - id: 'checkout'
        uses: 'actions/checkout@v4'
      - id: 'auth'
        name: Auth to Google Cloud (WIF)
        uses: 'google-github-actions/auth@v3'
        with:
          workload_identity_provider: ${{ secrets.GCP_WIF_PROVIDER }}
          service_account:  ${{ secrets.GCP_SA_EMAIL }}
      - id: 'upload-files'
        name: 'upload files to gcs BUCKET'
        uses: 'google-github-actions/upload-cloud-storage@v3'
        with:
          path: file-upload/
          destination: ${{ env.BUCKET }}
          parent: false
```

Three details matter here:

- `id-token: write` is the permission that lets the job request an OIDC token. Without it the `auth` step fails before it ever reaches Google.
- `workload_identity_provider` and `service_account` are the only two inputs the `auth` action needs. There is no `credentials_json`, which is the point.
- `parent: false` uploads the folder's contents to the bucket root instead of creating a `file-upload/` prefix.

To get WIF **provider** resource name:

```shell
gcloud iam workload-identity-pools providers describe github-action-provider \
  --location="global" \
  --workload-identity-pool="github-action-pool" \
  --format="value(name)"
```

The output looks like this:

```text
projects/123456789012/locations/global/workloadIdentityPools/github-action-pool/providers/github-action-provider
```

To get Service account email:

```shell
gcloud iam service-accounts list \
  --filter="email:github-action-sa@" \
  --format="value(email)"
```

The service account email follows the pattern

`github-action-sa@<project-id>.iam.gserviceaccount.com`.

### Create secrets and variables on GtiHub

In your repository, go to **Settings**, then **Secrets and variables**, then **Actions**, open the **Secrets** tab, and add:

**Secrets:**

| Name | Secret |
| --- | --- |
| `GCP_WIF_PROVIDER` | The provider resource name from the command above |
| `GCP_SA_EMAIL` | `github-action-sa@<project-id>.iam.gserviceaccount.com` |

**Variables:**

| Name | Value |
| --- | --- |
| `GCS_BUCKET_NAME` | Use the same bucket name |

### Push code

deploy workflow on GitHub

```shell
git add .
git commit -m "Feat: gcs-upload workflow"
git push origin main
```

---

## Verify the deployment

Check the GitHub success message

![check workflow success](https://cdn.hashnode.com/uploads/covers/61fe1129fd8b083e5728bdbe/8efda850-a507-420d-9122-35bb4fbf78bc.png align="center")

Verify that file is uploaded on GCS bucket

![GCS file uploaded](https://cdn.hashnode.com/uploads/covers/61fe1129fd8b083e5728bdbe/a274483e-f0c5-463e-813b-625a7a6bee99.png align="center")

---

## Conclusion

You now have a GitHub Actions workflow that reaches Google Cloud through a short-lived, repository-scoped identity instead of a stored key. The same pattern works for any GCP service the service account is allowed to use, such as Artifact Registry, Cloud Run, or Terraform state buckets.

## Reference:

Official Authenticate to Google Cloud from GitHub Actions: <https://github.com/google-github-actions/auth>

Last tested: Nov 2026
