Skip to main content
This guide is to help you connect to GCP with OIDC, instead of using static credentials.

Overview

This guide will show you how to create a GCP Workload Identity Federation Provider, and attach it to a Service Account to generate temporary credentials by accepting env zero’s OIDC token. Refer to env zero’s OIDC configuration.
This guide configures a v2 OIDC credential (the recommended format), where the token audience is api://env0-gcp. See Token versions for background. If you already authenticate to GCP with a v1 credential (allowed audience set to https://prod.env0.com), see Migrating an existing v1 credential below.

Workload Identity Federation Pool and Provider

  1. Login to your GCP account and select the relevant project.
  2. In the left-hand side menu select IAM & Admin
  3. Go to Workload Identity Federation page
  4. Click on the Create Pool button
  5. Enter a name and description, make sure the Enabled Pool is selected and click on the Continue button.
Google Cloud Identity Pool configuration interface showing OIDC provider setup
  1. In Select a provider selection choose OIDC, add a Provider name, enter a Proivder ID
  2. In the Issuer (URL) section enter https://login.app.env0.com/
  3. In the Audiences Select Allowed audiences and enter api://env0-gcp and click on the continue button.
Google Cloud Identity Provider configuration showing OIDC settings and audience configuration
  1. In the Configure provider attributes under the OIDC 1 enter assertion.sub
  2. Click on the Save button
Google Cloud attribute mapping configuration showing OIDC assertion mapping settings
Adding Custom ClaimsIf you like to add more Custom Claims, for example, I would like to add the organization id claim I would click on the Add Mapping button and add attribute.org_id in the Google text box, and in the OIDC I would add assertion.organizationId, and repeat step 14 with the organization id.Read more about Custom Claims here
  1. Follow this guide to get your sub value
  2. In the Identity pool you’ve just created click on the Grant Access button
  3. In the Service account select the relevant service account you would like to associate the identity pool with. Make sure this service account has the relevant access to what your code needs to create those resources
  4. Select the Only identities matching the filter radio button and in the Attribute name select subject and in the Attribute value enter the value of your sub you got from the previous steps, and click on the Save button
Grant Access to Service Account
  1. In the Configure your application modal select the env zero provider you have created, insert env0-oidc-token.txt as a filename in OIDC ID token path text box , and in the Format type select text and click on the Download Config button
  2. This will download a JSON configuration file that we will need during your deployment in env zero, and doesn’t contain any sensitive data on it:

Configure env0 OIDC Credential

Go to the organization’s credentials page and create a new deployment credential. Select GCP OIDC type and enter the following fields:
  • JSON configuration file content - The content of the JSON configuration file from the previous step
  • Use v2 OIDC token - check this box so env zero mints a token with the api://env0-gcp audience added to the provider’s allowed audiences above. The form shows the resulting Audience (aud) value. Leaving it unchecked produces a v1 token (aud: https://prod.env0.com), which the provider will reject unless that audience is also allowed.
env zero GCP OIDC credential form with the Use v2 OIDC token checkbox enabled and Audience set to api://env0-gcp
We will create a new file named env0_credential_configuration.json in the deployment pod that will contain the configuration file content. To be able to use OIDC with GCP you will need to read that configuration file in your code. For example, using terraform, it will look like this:
Credential File PlacementThe file will be placed in the environment’s template path. The value is exposed by the ENV0_TEMPLATE_PATH variable.If no specific template path is set, the file will be placed in the directory defined by the variable: ENV0_ROOT_DIR.

Migrating an existing v1 credential

If you already authenticate to GCP with a v1 env zero OIDC credential, your Workload Identity provider’s allowed audiences contain https://prod.env0.com. Because allowed audiences is a list, you can add the v2 audience alongside the old one and migrate without downtime:
  1. Add the v2 audience to the provider. In IAM & Admin > Workload Identity Federation, open your env zero provider, edit it, and add api://env0-gcp to Allowed audiences, keeping https://prod.env0.com for now.
  2. Enable v2 on the credential. Edit the GCP OIDC credential in env zero and check Use v2 OIDC token. The next deployment mints a token with aud: api://env0-gcp.
  3. Keep the old audience until everything else migrates. Leave https://prod.env0.com in the allowed audiences until every other consumer of the shared audience has moved to v2. Remove it only once nothing depends on it.

Next steps