Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Azure CLI auth regression #20526

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.1.2
github.com/hashicorp/go-azure-helpers v0.51.0
github.com/hashicorp/go-azure-sdk v0.20230217.1092053
github.com/hashicorp/go-azure-sdk v0.20230217.1131029
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv
github.com/hashicorp/go-azure-helpers v0.12.0/go.mod h1:Zc3v4DNeX6PDdy7NljlYpnrdac1++qNW0I4U+ofGwpg=
github.com/hashicorp/go-azure-helpers v0.51.0 h1:8KSDGkGnWH6zOT60R3KUqsi0fk1vA7AMunaOUJZMM6k=
github.com/hashicorp/go-azure-helpers v0.51.0/go.mod h1:lsykLR4KjTUO7MiRmNWiTiX8QQtw3ILjyOvT0f5h3rw=
github.com/hashicorp/go-azure-sdk v0.20230217.1092053 h1:044WTlqd5eoUYgL9ij7oe5H1kLTCs0D9L3rGWCMsZRY=
github.com/hashicorp/go-azure-sdk v0.20230217.1092053/go.mod h1:aHinadEuBi04I1i+yvpPMZUxvxRxl5JgBOwlzIIxozU=
github.com/hashicorp/go-azure-sdk v0.20230217.1131029 h1:QbSLBbv7xpterl93SM4oZX3ptN18DLNfDrPjRIMxMqc=
github.com/hashicorp/go-azure-sdk v0.20230217.1131029/go.mod h1:aHinadEuBi04I1i+yvpPMZUxvxRxl5JgBOwlzIIxozU=
github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
Expand Down
39 changes: 39 additions & 0 deletions internal/clients/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,45 @@ func NewResourceManagerAccount(ctx context.Context, config auth.Credentials, sub
tenantId = config.TenantID
}

// Finally, defer to Azure CLI to obtain tenant ID, subscription ID and client ID when not specified and missing from claims
realAuthorizer := authorizer
if cache, ok := authorizer.(*auth.CachedAuthorizer); ok {
realAuthorizer = cache.Source
}
if cli, ok := realAuthorizer.(*auth.AzureCliAuthorizer); ok {
// Use the tenant ID from Azure CLI when otherwise unknown
if tenantId == "" {
if cli.TenantID == "" {
return nil, fmt.Errorf("azure-cli could not determine tenant ID to use")
}
tenantId = cli.TenantID
log.Printf("[DEBUG] Using tenant ID from Azure CLI: %q", tenantId)
}

// Use the subscription ID from Azure CLI when otherwise unknown
if subscriptionId == "" {
if cli.DefaultSubscriptionID == "" {
return nil, fmt.Errorf("azure-cli could not determine subscription ID to use and no subscription was specified")
}

subscriptionId = cli.DefaultSubscriptionID
log.Printf("[DEBUG] Using default subscription ID from Azure CLI: %q", subscriptionId)
}

// Use the Azure CLI client ID
if id, ok := config.Environment.MicrosoftAzureCli.AppId(); ok {
clientId = *id
log.Printf("[DEBUG] Using client ID from Azure CLI: %q", clientId)
}
}

if tenantId == "" {
return nil, fmt.Errorf("unable to configure ResourceManagerAccount: tenant ID could not be determined and was not specified")
}
if subscriptionId == "" {
return nil, fmt.Errorf("unable to configure ResourceManagerAccount: subscription ID could not be determined and was not specified")
}

account := ResourceManagerAccount{
Environment: config.Environment,

Expand Down
4 changes: 2 additions & 2 deletions internal/clients/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ func Build(ctx context.Context, builder ClientBuilder) (*Client, error) {
Environment: builder.AuthConfig.Environment,
Features: builder.Features,

SubscriptionId: builder.SubscriptionID,
TenantId: builder.AuthConfig.TenantID,
SubscriptionId: account.SubscriptionId,
TenantId: account.TenantId,
PartnerId: builder.PartnerID,
TerraformVersion: builder.TerraformVersion,

Expand Down
21 changes: 11 additions & 10 deletions vendor/github.com/hashicorp/go-azure-sdk/sdk/auth/autorest/auth.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ github.com/hashicorp/go-azure-helpers/resourcemanager/zones
github.com/hashicorp/go-azure-helpers/resourceproviders
github.com/hashicorp/go-azure-helpers/sender
github.com/hashicorp/go-azure-helpers/storage
# github.com/hashicorp/go-azure-sdk v0.20230217.1092053
# github.com/hashicorp/go-azure-sdk v0.20230217.1131029
## explicit; go 1.19
github.com/hashicorp/go-azure-sdk/resource-manager/aad/2021-05-01/domainservices
github.com/hashicorp/go-azure-sdk/resource-manager/aadb2c/2021-04-01-preview
Expand Down