Skip to content

new provider option: useDefaultAzureCredential#4174

Merged
EronWright merged 15 commits into
masterfrom
issue-4172
Aug 26, 2025
Merged

new provider option: useDefaultAzureCredential#4174
EronWright merged 15 commits into
masterfrom
issue-4172

Conversation

@EronWright

@EronWright EronWright commented May 31, 2025

Copy link
Copy Markdown
Contributor

This PR enables the "Default Credential Chain" feature of the Azure SDK for Go:

DefaultAzureCredential is an opinionated, preconfigured chain of credentials. It's designed to support many environments, along with the most common authentication flows and developer tools.

This feature is enabled with a new provider option, useDefaultAzureCredential and the environment variable ARM_USE_DEFAULT_AZURE_CREDENTIAL. When enabled, the provider looks for AZURE_* environment variables, then a Azure workload or managed identity, then an active CLI account.

Customization

Set the Azure environment

To configure the active Azure environment, set the provider option environment or the environment variable ARM_ENVIRONMENT or AZURE_ENVIRONMENT to public, usgov, or china.

Exclude a credential type category

To exclude all "Developer tool" or "Deployed service" credentials, set environment variable AZURE_TOKEN_CREDENTIALS to prod or dev, respectively.

Use a specific credential

To exclude all credentials except for one, set environment variable AZURE_TOKEN_CREDENTIALS to one of:

  • AzureCLICredential
  • AzureDeveloperCLICredential
  • EnvironmentCredential
  • ManagedIdentityCredential
  • WorkloadIdentityCredential

Testing

Manual Setup

curl -fsSL https://get.pulumi.com | sh
pulumi plugin install resource azure-native 3.8.0-alpha.1756942349
pulumi config set azure-native:useDefaultAzureCredential true
pulumi config set azure-native:subscriptionId <subscription-id>

Closes #4172

@github-actions

Copy link
Copy Markdown
Contributor

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

@EronWright

This comment was marked as resolved.

@EronWright

This comment was marked as resolved.

@EronWright EronWright changed the base branch from master to issue-4223 August 20, 2025 23:57
@EronWright EronWright marked this pull request as ready for review August 21, 2025 00:56
@EronWright EronWright requested a review from Copilot August 21, 2025 00:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for using Azure's DefaultAzureCredential authentication strategy in the Azure Native provider. This simplifies authentication by combining credentials used in Azure hosting environments with those used in local development through a standardized credential chain.

Key changes:

  • Added a new useDefaultAzureCredential configuration option that enables the default Azure credential chain
  • Integrated the default credential as the first authentication method in the credential chain (before existing methods)
  • Added comprehensive test coverage for the new authentication method

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
provider/pkg/provider/auth_azidentity.go Core implementation of the default Azure credential authentication method and configuration
provider/pkg/gen/schema.go Schema definition for the new useDefaultAzureCredential provider option
provider/pkg/provider/auth_azidentity_test.go Unit test for the default Azure credential functionality
provider/pkg/provider/provider_e2e_test.go End-to-end test validating the default credential behavior in CI environment

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread provider/pkg/provider/auth_azidentity.go
@EronWright EronWright requested review from a team and danielrbradley August 21, 2025 19:06
@EronWright EronWright force-pushed the issue-4223 branch 2 times, most recently from 2f05533 to 779ec3c Compare August 25, 2025 19:09
Base automatically changed from issue-4223 to master August 25, 2025 19:58
@codecov

codecov Bot commented Aug 26, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.66%. Comparing base (faec5c4) to head (8f58473).
⚠️ Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
provider/pkg/provider/auth_azidentity.go 88.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4174      +/-   ##
==========================================
+ Coverage   58.79%   59.66%   +0.86%     
==========================================
  Files          84       86       +2     
  Lines       13582    13939     +357     
==========================================
+ Hits         7986     8317     +331     
+ Misses       4989     4974      -15     
- Partials      607      648      +41     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mjeffryes mjeffryes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fairly safe to add and correct AFAICT. Might be nice to try to test more of the different auth configurations supported by identity default credential


"useDefaultAzureCredential": {
TypeSpec: pschema.TypeSpec{Type: "boolean"},
Description: "Use the default credential chain of the Azure SDK (see https://learn.microsoft.com/en-us/azure/developer/go/sdk/authentication/credential-chains#defaultazurecredential-overview).",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we shouldn't have a doc of our own to point at that explains how this strategy layers in with our other auth strategies. (IIUC, the existing strategies try to mimic the TF provider env variables, while this new strategy will respect the AZURE_* env variables used by the azure cli. But I imagine there's a lot more nuance involved.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the PR description, I captured how the provider specifically uses the DefaultAzureCredential, and the upstream documentation is very good and detailed.

You are correct that the provider configures itself with ARM_ variables, as does azure-classic provider. The relevant options here are ARM_SUBSCRIPTION_ID, ARM_ENVIRONMENT, and ARM_USE_DEFAULT_AZURE_CREDENTIAL.

To minimize interplay with the other strategies, we check for ARM_USE_DEFAULT_AZURE_CREDENTIAL before using any heuristics like checking for ARM_CLIENT_ID to activate Service Principal authentication.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// the next method.
// - Auxiliary or additional tenants are supported for SP with client secret and CLI authentication, not for others.
func newSingleMethodAuthCredential(authConf *authConfiguration, baseClientOpts azcore.ClientOptions) (azcore.TokenCredential, error) {
if authConf.useDefault {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we ever want to enable this by default (say in a future major version)? It seems like it's designed to support a set of auth strategies that overlap with existing strategies for this provider.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I do think it would be an ideal default for the true default provider instance. The DefaultAzureCredential is 100% about getting your identity from the ambient environment, so it wouldn't make much sense to use with an explicit provider.

@EronWright EronWright merged commit 7ed14fc into master Aug 26, 2025
23 checks passed
@EronWright EronWright deleted the issue-4172 branch August 26, 2025 21:05
@pulumi-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped in release v3.8.0.

3 similar comments
@pulumi-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped in release v3.8.0.

@pulumi-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped in release v3.8.0.

@pulumi-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped in release v3.8.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support AZURE_* environment variables in addition to ARM_*

4 participants