Configuring OpenID Connect for Azure with Pulumi Deployments
This document outlines the steps required to configure Pulumi Deployments to use OpenID Connect to authenticate with Azure. OIDC in Azure uses workload identity federation to access Azure resources via a Microsoft Entra App. Access to the temporary credentials is authorized using federated credentials that validate the contents of the OIDC token issued by Pulumi Cloud.
Prerequisites
- You must have access in the Azure Portal to create and configure Microsoft Entra App registrations.
Create a Microsoft Entra application
In the navigation pane of the Microsoft Entra console:
- Select App registrations and then click New registration.
- Provide a name for your application (ex:
pulumi-deployments-oidc-app
). - In the Supported account types section, select Accounts in this organizational directory only.
- Click Register.
After the Microsoft Entra application has been created, take note of the following details:
- Subscription ID
- Application (client) ID
- Directory (tenant) ID
These values will be necessary when enabling OIDC for your service.
Add federated credentials
Once you have created your new application registration, you will be redirected to the application’s Overview page. In the left navigation menu:
- Navigate to the Certificates & secrets pane.
- Select the Federated credentials tab.
- Click on the Add credential button. This will start the “Add a credential” wizard.
- In the wizard, select Other Issuer as the Federated credential scenario.
- Fill in the remaining form fields as follows:
- Issuer:
https://api.pulumi.com/oidc
- Subject Identifier: must be a valid subject claim (see examples at the end of this section).
- Name: An arbitrary name for the credential, e.g. “pulumi-oidc-credentials”.
- Audience: Enter the name of your Pulumi organization.
- Issuer:
Subject claim examples
Because Azure’s federated credentials require that the subject identifier exactly matches an OIDC token’s subject claim, this process must be repeated for each permutation of the subject claim that is possible for a stack. For example, in order to enable all of the valid operations on a stack named dev
of the core
project in the contoso
organization, you would need to create credentials for each of the following subject identifiers:
pulumi:deploy:org:contoso:project:core:stack:dev:operation:preview:scope:write
pulumi:deploy:org:contoso:project:core:stack:dev:operation:update:scope:write
pulumi:deploy:org:contoso:project:core:stack:dev:operation:refresh:scope:write
pulumi:deploy:org:contoso:project:core:stack:dev:operation:destroy:scope:write
Create a service principal
To provide Pulumi services the ability to deploy, manage, and interact with Azure resources, you need to associate your Microsoft Entra application with your Subscription or Resource Group.
- Navigate to the Subscriptions page of the Azure portal.
- Select the subscription to create the service principal in.
- If you want to limit access to a specific resource group, go to the Resource Groups page instead and select the desired resource group.
- In the left navigation menu, select Access control (IAM).
- Click Add > Add role assignment to be taken to the Add role assignment wizard.
- Under the Job function roles tab, select the desired role from the list, then click Next.
- Select User, group, or service principal, then click Select members
- Enter the name of the application you created in a previous step, select it from the list, then click Select.
- Click Next and then Review + assign.
Configure OIDC in the Pulumi console
- Navigate to your stack in the Pulumi Console.
- Open the stack’s Settings tab.
- Choose the Deploy panel.
- Under the OpenID Connect header, toggle Enable Azure Integration.
- Enter the client and tenant IDs for the app registration created above in the Client ID and Tenant ID fields, respectively.
- Enter the ID of the subscription you want to use in the Subscription ID field.
- Click the Save deployment configuration button.
With this configuration, each deployment of this stack will attempt to exchange the deployment’s OIDC token for Azure credentials using the specified AAD App prior to running any pre-commands or Pulumi operations. The fetched credentials are published in the ARM_CLIENT_ID
, ARM_TENANT_ID
, and ARM_SUBSCRIPTION_ID
environment variables. The raw OIDC token is also available for advanced scenarios in the PULUMI_OIDC_TOKEN
environment variable and the /mnt/pulumi/pulumi.oidc
file.
If you want an example of how to automate the configuration of OIDC for Pulumi Deployments with Azure, you can refer to this TypeScript example.
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.