Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Azure Plugin auth fix #4763

Merged
merged 1 commit into from
Jun 5, 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
3 changes: 3 additions & 0 deletions .changelog/4763.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
plugin/azure-aci: Update plugin to attempt CLI auth if environment auth fails.
```
9 changes: 6 additions & 3 deletions builtin/azure/aci/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2015-11-01/subscriptions"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure/auth"
"github.com/hashicorp/go-hclog"

"github.com/hashicorp/waypoint-plugin-sdk/component"
)

Expand All @@ -27,14 +29,14 @@ func (d *Deployment) containerInstanceGroupsClient(auth autorest.Authorizer) (*c
}

// init sets up the authorizer and fetches the locations
func (d *Deployment) authenticate(ctx context.Context) (autorest.Authorizer, error) {
func (d *Deployment) authenticate(ctx context.Context, log hclog.Logger) (autorest.Authorizer, error) {
// create an authorizer from env vars or Azure Managed Service Identity
//authorizer, err := auth.NewAuthorizerFromCLI()

// first try and create an environment
authorizer, err := auth.NewAuthorizerFromEnvironment()
if err != nil {
return nil, fmt.Errorf("Unable to create subscriptions client: %s", err)
log.Warn("unable to create subscriptions client", "error", err)
}

// we need to timeout this request as this request never fails when we have
Expand All @@ -51,6 +53,7 @@ func (d *Deployment) authenticate(ctx context.Context) (autorest.Authorizer, err
defer cf2()

// the environment variable auth has failed fall back to CLI auth
log.Info("attempting CLI auth")
authorizer, err = auth.NewAuthorizerFromCLI()
if err != nil {
return authorizer, err
Expand All @@ -61,7 +64,7 @@ func (d *Deployment) authenticate(ctx context.Context) (autorest.Authorizer, err
}

return nil, fmt.Errorf(
"Unable to authenticate with the Azure API, ensure you have your credentials set as environment variables, " +
"unable to authenticate with the Azure API, ensure you have your credentials set as environment variables, " +
"or you have logged in using the 'az' command line tool",
)
}
Expand Down
2 changes: 1 addition & 1 deletion builtin/azure/aci/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (p *Platform) Deploy(
},
}

auth, err := deployment.authenticate(ctx)
auth, err := deployment.authenticate(ctx, log)
if err != nil {
return nil, status.Error(
codes.Unauthenticated,
Expand Down