Configuring OpenID Connect for Google Cloud
This document outlines the steps required to configure Pulumi to use OpenID Connect to authenticate with Google Cloud. OIDC in Google Cloud uses workload identity federation to allow access to resources. Access to the resources is authorized using attribute conditions that validate the contents of the OIDC token issued by the Pulumi Cloud.
Prerequisites
- You must create a Google Cloud project with the required APIs enabled
Create a Workload Identity Pool and Provider
- Navigate to the Workload Identity Pools page in the Google Cloud console.
- Select your Google Cloud project.
- Click the Create Pool button.
- Provide a name and an optional description. then click Continue
- In the Add a provider to pool dropdown, select OpenID Connect (OIDC).
- Provide a name for the provider.
- In the Issuer field, enter
https://api.pulumi.com/oidc
. - In the Audiences section, select the Allowed audiences radio button. The value for this field is different between pulumi deployments and ESC. For Deployments enter just the name of your Pulumi organization. For ESC enter the name of your Pulumi organization prefixed with
gcp:
(e.g.gcp:{org}
). Then click Continue.For environments in thedefault
project the audience will use just the Pulumi organization name. This is to prevent regressions for legacy environments. - In the Configure provider attributes section, provide the value of
assertion.sub
in the OIDC 1 field. Then click Save.
Configure a Service Account
Once you have created your workload identity pool and provider, you will be directed to the pool details page. If you already have an appropriate service account created, skip ahead to the steps found in the Grant access to the service account section. Otherwise, continue through the steps below to create a new one.
Create a new service account
- Navigate to the Service Accounts page.
- Select your Google Cloud project.
- Click “Create Service Account”.
- Enter a value for the Service account name field. Then click Create And Continue
- The Service account ID field will auto-populate based on this value.
- In the Grant this service account access to project section, select the role(s) that provides the relevant access to your Pulumi service. Then click Continue.
- Leave the values in the next section blank and click Done.
Grant access to the service account
- In your workload identity pool’s details page, click the Grant Access button.
- In the Select service account dropdown, select the desired service account to associate with the pool.
- Under the Select principals section, click the Only identities matching the filter radio button.
- In the Attribute name dropdown, select Subject.
- In the Attribute value field, provide a valid subject claim (see examples at the end of this section). Then click Save.
Make a note of the project ID, workload identity pool ID, provider ID, and service account email address from the previous steps. These will be necessary to enable OIDC for your service.
Configure ESC for OIDC
To configure OIDC for Pulumi ESC, create a new environment in the Pulumi Console. Make sure that you have the correct organization selected in the left-hand navigation menu. Then:
Click the Environments link.
Click the Create environment button.
Provide a project to create your new environment in and a name for your environment.
- This should be the same as the identifier provided in the subject claim of your federated credentials.
Click the Create environment button.
You will be presented with a split-pane document and table view. Delete the default placeholder content in the editor and replace it with the following code:
values: gcp: login: fn::open::gcp-login: project: <your-project-id> oidc: workloadPoolId: <your-pool-id> providerId: <your-provider-id> serviceAccount: <your-service-account> environmentVariables: GOOGLE_PROJECT: ${gcp.login.project} CLOUDSDK_AUTH_ACCESS_TOKEN: ${gcp.login.accessToken} pulumiConfig: gcp:accessToken: ${gcp.login.accessToken}
Replace
<your-project-id>
,<your-pool-id>
,<your-provider-id>
, and<your-service-account>
with the values from the previous steps.Scroll to the bottom of the page and click Save.
You can validate that your configuration is working by running either of the following:
esc open <your-org>/<your-project>/<your-environment>
command of the ESC CLIpulumi env open <your-org>/<your-project>/<your-environment>
command of the Pulumi CLI
Make sure to replace <your-org>
, <your-project>
, and <your-environment>
with the values of your Pulumi organization, project, and environment file respectively. You should see output similar to the following:
{
"environmentVariables": {
"GOOGLE_PROJECT": 111111111111
"CLOUDSDK_AUTH_ACCESS_TOKEN": "ya29...."
},
"gcp": {
"login": {
"accessToken": "ya29.....",
"expiry": "2023-11-09T11:12:41Z",
"project": 111111111111,
"tokenType": "Bearer"
}
},
"pulumiConfig": {
"gcp:accessToken": "ya29...."
}
}
Subject claim customization
You can customize the subject claim in the OIDC token to control which Pulumi environments or users are allowed to assume a given IAM role. This allows for more granular access control than the default organization-level permissions.
You can do so by configuring the subjectAttributes
setting. It expects an array of keys to include in it:
rootEnvironment.name
: the name of the environment that is opened first. This root environment in turn opens other imported environmentscurrentEnvironment.name
: the full name (including the project) of the environment where the ESC login provider andsubjectAttributes
are definedpulumi.user.login
: the login identifier of the user opening the environmentpulumi.organization.login
: the login identifier of the organization
The subject always contains the following prefix pulumi:environments:pulumi.organization.login:{ORGANIZATION_NAME}
and every key configured will be appended to this prefix. For example, consider the following environment:
values:
gcp:
login:
fn::open::gcp-login:
oidc:
...
subjectAttributes:
- currentEnvironment.name
- pulumi.user.login
The subject will be pulumi:environments:pulumi.organization.login:contoso:currentEnvironment.name:project/development:pulumi.user.login:userLogin
. Note how the keys and values are appended along with the prefix.
default
project, the project will not be present in the subject to preserve backwards compatibility. The format of the subject claim when subjectAttributes
are not set is pulumi:environments:org:<organization name>:env:<environment name>
. If currentEnvironment.name
is used as a custom subject attribute it will resolve to only the environment name (e.g. pulumi:environments:pulumi.organization.login:contoso:currentEnvironment.name:development:pulumi.user.login:personA
). Due to this it is recommended to move your environments out of the default
project for best security practices.Subject claim examples
Below is an example of a valid subject claim for the project/development
environment of the contoso
organization:
pulumi:environments:org:contoso:env:project/development
The default format of the subject claim when subjectAttributes
are not used is pulumi:environments:org:<organization name>:env:<project name>/<environment name>
If you are integrating Pulumi ESC with Pulumi IaC, the default subject identifier of the ESC environment will not work at this time. There is a known issue with the subject identifier’s value sent to Azure from Pulumi.
Use ‘subjectAttributes’ to customize the subject identifier to work with Pulumi IaC. Alternatively, you can use this syntax: pulumi:environments:org:contoso:env:<yaml>
when configuring the subject claim in your cloud provider account. Make sure to replace contoso
with the name of your Pulumi organization and use the literal value of <yaml>
as shown.
Thank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.