> ## Documentation Index
> Fetch the complete documentation index at: https://docs.opal.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Authenticate Google apps with workload identity federation

> Connect Google Cloud Platform, Google Groups, and Google Workspace to Opal without a service account key.

With workload identity federation (in limited beta), you don't upload a service account key to Opal. Your Google Cloud project trusts tokens that Opal signs for one specific app, and Google exchanges each token for short-lived credentials for your service account. There's no long-lived key to leak or rotate, and you can cut off Opal at any time by disabling the provider in Google Cloud.

This page applies to the [Google Cloud Platform](https://docs.opal.dev/integrations/google-cloud-platform.md), [Google Groups](https://docs.opal.dev/integrations/google-groups.md), and [Google Workspace](https://docs.opal.dev/integrations/google-workspace.md) apps.

## How it works

1. Opal signs a short-lived OIDC token with a key that's unique to the app. The token names Opal as its **Issuer** and the app as its **Subject**.
2. Google's Security Token Service checks the token against the workload identity provider you created: the signature must match the provider's **JWKS**, and the subject must match its attribute condition. It then returns a short-lived federated token.
3. The federated token acts as your service account, for about an hour at a time:
   * **Google Cloud Platform** impersonates the service account.
   * **Google Groups** and **Google Workspace** use domain-wide delegation. Without a key, Opal asks Google to sign the delegation token on the service account's behalf, which needs the Service Account Token Creator role.

The service account, its roles, and its domain-wide delegation scopes are the same as with a key. Only how Opal authenticates as it changes.

## Set up a new app

Create the service account and grant it the roles or scopes the app needs, as described on the app's page, then:

> [!NOTE]
>
> Workload identity federation is in limited beta. Contact Opal support to enable it for your organization.

Opal doesn't need a key for your service account. Your Google Cloud project trusts short-lived tokens that Opal signs for this app, and Google exchanges each one for short-lived credentials for the service account. See [how workload identity federation works](https://docs.opal.dev/integrations/google-workload-identity-federation.md#how-it-works).

1. In the service account's project, enable the [Security Token Service API](https://console.cloud.google.com/apis/library/sts.googleapis.com) and the [IAM Service Account Credentials API](https://console.cloud.google.com/apis/library/iamcredentials.googleapis.com).
2. On the Opal app form, turn on **Authenticate with workload identity federation instead of a service account key**. Opal shows an **Issuer**, **Subject**, **Audience**, and **JWKS**. Keep the form open until you select **Create**: reloading it generates a new key, which changes the subject and JWKS.
3. In Google Cloud, create a [workload identity pool](https://cloud.google.com/iam/docs/manage-workload-identity-pools-providers#create), or reuse one, and add an OIDC provider to it:

   * **Issuer**: the **Issuer** from Opal.
   * **JWKS**: paste the **JWKS** from Opal (for example with `--jwk-json-path` in gcloud).
   * **Attribute mapping**: `google.subject=assertion.sub`.
   * **Attribute condition**: `assertion.sub == '<Subject from Opal>'`.
   * Leave the provider's allowed audiences empty. Opal uses the provider's default audience.

   If your organization restricts which identity providers pools may trust (the `constraints/iam.workloadIdentityPoolProviders` organization policy), allow `https://app.opal.dev`, or your own Opal URL for self-hosted Opal.
4. Grant roles on the service account to the principal for the subject, using the project's **number**, not its ID:

   `principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/POOL/subject/<Subject from Opal>`

   * `roles/iam.workloadIdentityUser`, for every Google app.
   * `roles/iam.serviceAccountTokenCreator`, for Google Groups and Google Workspace only. Domain-wide delegation needs it because Google signs the delegation token when there's no key.
5. Back on the Opal form, enter the **Workload identity provider** (its full resource name, for example `projects/123456789/locations/global/workloadIdentityPools/opal/providers/opal`), the **Service account email**, and the **Service account project ID**, then select **Create**.

Opal checks each step before it creates the app and names the step that fails. New IAM grants can take a minute or two to take effect, so if Opal reports that it couldn't impersonate the service account or sign the delegation token, wait and select **Create** again.

Each app has its own key and subject, so add a provider for each app. One pool can hold all of them. To move an existing app off its key, see [Switch an existing app](https://docs.opal.dev/integrations/google-workload-identity-federation.md#switch-an-existing-app).

## Switch an existing app

You can move an app that uses a service account key to federation without creating a new app or re-importing anything.

1. In the app in Opal, go to **Setup** > **Edit** and turn on **Authenticate with a new OIDC federation key instead of a service account key**.
2. Create the provider and grant the roles with the values Opal shows, as in [Set up a new app](#set-up-a-new-app).
3. Enter the workload identity provider, then select **Save**.

Opal checks the federation setup before saving. If a step fails, Opal shows which one and keeps using the existing key, so syncs aren't interrupted.

> [!WARNING]
>
> After the app works with federation, delete the service account's JSON keys in Google Cloud. Otherwise, a long-lived key that can authenticate as the service account still exists.

## Rotate the federation key

You can replace an app's federation key without interrupting syncs:

1. In the app in Opal, go to **Setup** > **Edit** and turn on **Authenticate with a new OIDC federation key instead of a service account key**. Opal generates a new key and shows two JWKS values: **JWKS**, which accepts both the current and new keys, and **JWKS after saving**, which accepts only the new key.
2. In Google Cloud, update the workload identity provider to use the **JWKS** value, then select **Save** in Opal. Opal starts signing with the new key.
3. Update the provider again to use the **JWKS after saving** value. This retires the old key.

The issuer and subject stay the same when you rotate the key, so you only update the JWKS. Each rotation is recorded as an [event](https://docs.opal.dev/docs/event-types.md) on the app, identified by the key's ID.

## Troubleshooting

Opal checks federation one step at a time, so the validation that fails tells you what to fix.

| Validation | What to check |
| - | - |
| The workload identity provider is not valid | Enter the provider's full resource name, with the project number rather than its ID. |
| Google's Security Token Service rejected Opal's token | The Security Token Service API is enabled, and the provider uses the issuer and JWKS Opal showed, has the attribute condition for the app's subject, and leaves its allowed audiences empty. Check the organization policy in [Set up a new app](#set-up-a-new-app). |
| Opal could not impersonate the service account | The IAM Service Account Credentials API is enabled, and the principal has `roles/iam.workloadIdentityUser` on the service account. New grants can take a minute or two. |
| Google would not sign the domain-wide delegation token | Google Groups and Google Workspace only: the principal also has `roles/iam.serviceAccountTokenCreator` on the service account. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.