azure: Allow for the use of MSI (#1110)

This commit is contained in:
Julien Balestra 2020-04-17 18:54:59 +02:00 committed by GitHub
parent ae818a411c
commit 1ac1986687
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 12 deletions

1
go.mod
View file

@ -6,7 +6,6 @@ require (
cloud.google.com/go v0.54.0
github.com/Azure/azure-sdk-for-go v32.4.0+incompatible
github.com/Azure/go-autorest/autorest v0.5.0
github.com/Azure/go-autorest/autorest/adal v0.2.0
github.com/Azure/go-autorest/autorest/azure/auth v0.1.0
github.com/Azure/go-autorest/autorest/to v0.2.0
github.com/Azure/go-autorest/autorest/validation v0.1.0 // indirect

View file

@ -13,8 +13,6 @@ import (
"github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2017-09-01/dns"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/adal"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/azure/auth"
"github.com/Azure/go-autorest/autorest/to"
"github.com/go-acme/lego/v3/challenge/dns01"
@ -240,20 +238,17 @@ func toRelativeRecord(domain, zone string) string {
func getAuthorizer(config *Config) (autorest.Authorizer, error) {
if config.ClientID != "" && config.ClientSecret != "" && config.TenantID != "" {
oauthConfig, err := adal.NewOAuthConfig(azure.PublicCloud.ActiveDirectoryEndpoint, config.TenantID)
credentialsConfig := auth.NewClientCredentialsConfig(config.ClientID, config.ClientSecret, config.TenantID)
spToken, err := credentialsConfig.ServicePrincipalToken()
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to get oauth token from client credentials: %v", err)
}
spt, err := adal.NewServicePrincipalToken(*oauthConfig, config.ClientID, config.ClientSecret, azure.PublicCloud.ResourceManagerEndpoint)
if err != nil {
return nil, err
}
spToken.SetSender(config.HTTPClient)
spt.SetSender(config.HTTPClient)
return autorest.NewBearerAuthorizer(spt), nil
return autorest.NewBearerAuthorizer(spToken), nil
}
return auth.NewAuthorizerFromEnvironment()
}