Skip to content

Commit cdb02cf

Browse files
authored
Merge pull request #77 from grafana/logyball/hackathon/use-az-env-vars-to-auth
Adding Azure Environment var authentication
2 parents 6dd7502 + 95a2fc0 commit cdb02cf

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Both binaries are opinionated on how to authenticate against each Cloud Service
2828
| Provider | Notes |
2929
|-|-|
3030
| GCP | Depends on [default credentials](https://cloud.google.com/docs/authentication/application-default-credentials) |
31-
| AWS | Uses profile names from your [credentials file](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) |
32-
| Azure | Requires [Azure CLI](https://learn.microsoft.com/en-us/cli/azure/) installed on the host and [signed in](https://learn.microsoft.com/en-us/cli/azure/authenticate-azure-cli) |
31+
| AWS | Uses profile names from your [credentials file](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) or `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_REGION` env variables |
32+
| Azure | Either specify an `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`, and `AZURE_TENANT_ID`, or requires [Azure CLI](https://learn.microsoft.com/en-us/cli/azure/) installed on the host and [signed in](https://learn.microsoft.com/en-us/cli/azure/authenticate-azure-cli) |
3333

3434
### `unused` binary
3535
TUI tool to query all given providers and list them as a neat table.

cmd/internal/providers.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import (
66
"flag"
77
"fmt"
88
"log/slog"
9+
"os"
910

1011
azcompute "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
12+
"github.com/Azure/go-autorest/autorest"
1113
"github.com/Azure/go-autorest/autorest/azure/auth"
1214
"github.com/aws/aws-sdk-go-v2/config"
1315
"github.com/aws/aws-sdk-go-v2/service/ec2"
@@ -49,7 +51,14 @@ func CreateProviders(ctx context.Context, logger *slog.Logger, gcpProjects, awsP
4951
}
5052

5153
if len(azureSubs) > 0 {
52-
a, err := auth.NewAuthorizerFromCLI()
54+
var a autorest.Authorizer
55+
var err error
56+
57+
if os.Getenv("AZURE_CLIENT_ID") != "" && os.Getenv("AZURE_CLIENT_SECRET") != "" && os.Getenv("AZURE_TENANT_ID") != "" {
58+
a, err = auth.NewAuthorizerFromEnvironment()
59+
} else {
60+
a, err = auth.NewAuthorizerFromCLI()
61+
}
5362
if err != nil {
5463
return nil, fmt.Errorf("creating Azure authorizer: %w", err)
5564
}

0 commit comments

Comments
 (0)