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

Add support for "sovereign" Azure cloud environments #4997

Merged
merged 2 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 16 additions & 1 deletion physical/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

storage "github.com/Azure/azure-sdk-for-go/storage"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/armon/go-metrics"
"github.com/hashicorp/errwrap"
cleanhttp "github.com/hashicorp/go-cleanhttp"
Expand Down Expand Up @@ -66,7 +67,21 @@ func NewAzureBackend(conf map[string]string, logger log.Logger) (physical.Backen
}
}

client, err := storage.NewBasicClient(accountName, accountKey)
cloudEnvironmentName := os.Getenv("AZURE_ENVIRONMENT")
if cloudEnvironmentName == "" {
cloudEnvironmentName = conf["cloudEnvironment"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think environment should be suitable for the config element.

if cloudEnvironmentName == "" {
cloudEnvironmentName = "AzurePublicCloud"
}
}
cloudEnvironment, err := azure.EnvironmentFromName(cloudEnvironmentName)
if err != nil {
errorMsg := fmt.Sprintf("failed to look up Azure environment descriptor for name %q: {{err}}",
cloudEnvironmentName)
return nil, errwrap.Wrapf(errorMsg, err)
}

client, err := storage.NewBasicClientOnSovereignCloud(accountName, accountKey, cloudEnvironment)
if err != nil {
return nil, errwrap.Wrapf("failed to create Azure client: {{err}}", err)
}
Expand Down
36 changes: 28 additions & 8 deletions physical/azure/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ import (
"time"

storage "github.com/Azure/azure-sdk-for-go/storage"
"github.com/Azure/go-autorest/autorest/azure"
cleanhttp "github.com/hashicorp/go-cleanhttp"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/helper/logging"
"github.com/hashicorp/vault/physical"
)

func cloudEnvironmentForCleanupClient(name string) (azure.Environment, error) {
if name == "" {
return azure.EnvironmentFromName("AzurePublicCloud")
}
return azure.EnvironmentFromName(name)
}

func TestAzureBackend(t *testing.T) {
if os.Getenv("AZURE_ACCOUNT_NAME") == "" ||
os.Getenv("AZURE_ACCOUNT_KEY") == "" {
Expand All @@ -23,19 +31,25 @@ func TestAzureBackend(t *testing.T) {

accountName := os.Getenv("AZURE_ACCOUNT_NAME")
accountKey := os.Getenv("AZURE_ACCOUNT_KEY")
cloudEnvironmentName := os.Getenv("AZURE_ENVIRONMENT")

ts := time.Now().UnixNano()
name := fmt.Sprintf("vault-test-%d", ts)

cleanupClient, _ := storage.NewBasicClient(accountName, accountKey)
cleanupCloudEnvironment, err := cloudEnvironmentForCleanupClient(cloudEnvironmentName)
if err != nil {
t.Fatalf("err: %s", err)
}
cleanupClient, _ := storage.NewBasicClientOnSovereignCloud(accountName, accountKey, cleanupCloudEnvironment)
cleanupClient.HTTPClient = cleanhttp.DefaultPooledClient()

logger := logging.NewVaultLogger(log.Debug)

backend, err := NewAzureBackend(map[string]string{
"container": name,
"accountName": accountName,
"accountKey": accountKey,
"container": name,
"accountName": accountName,
"accountKey": accountKey,
"cloudEnvironment": cloudEnvironmentName,
}, logger)

defer func() {
Expand All @@ -60,19 +74,25 @@ func TestAzureBackend_ListPaging(t *testing.T) {

accountName := os.Getenv("AZURE_ACCOUNT_NAME")
accountKey := os.Getenv("AZURE_ACCOUNT_KEY")
cloudEnvironmentName := os.Getenv("AZURE_ENVIRONMENT")

ts := time.Now().UnixNano()
name := fmt.Sprintf("vault-test-%d", ts)

cleanupClient, _ := storage.NewBasicClient(accountName, accountKey)
cleanupCloudEnvironment, err := cloudEnvironmentForCleanupClient(cloudEnvironmentName)
if err != nil {
t.Fatalf("err: %s", err)
}
cleanupClient, _ := storage.NewBasicClientOnSovereignCloud(accountName, accountKey, cleanupCloudEnvironment)
cleanupClient.HTTPClient = cleanhttp.DefaultPooledClient()

logger := logging.NewVaultLogger(log.Debug)

backend, err := NewAzureBackend(map[string]string{
"container": name,
"accountName": accountName,
"accountKey": accountKey,
"container": name,
"accountName": accountName,
"accountKey": accountKey,
"cloudEnvironment": cloudEnvironmentName,
}, logger)

defer func() {
Expand Down
6 changes: 6 additions & 0 deletions website/source/docs/configuration/storage/azure.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ storage "azure" {
accountName = "my-storage-account"
accountKey = "abcd1234"
container = "container-efgh5678"
cloudEnvironment = "AzurePublicCloud"
}
```

Expand All @@ -43,6 +44,10 @@ The current implementation is limited to a maximum of 4 megabytes per blob.
- `container` `(string: <required>)` – Specifies the Azure Storage Blob
container name.

- `cloudEnvironment` `(string: "AzurePublicCloud")` - Specifies the cloud
environment the storage account belongs to by way of the case-insensitive
name defined in the [Azure Go SDK][azure-environment].

- `max_parallel` `(string: "128")` – Specifies The maximum number of concurrent
requests to Azure.

Expand All @@ -61,3 +66,4 @@ storage "azure" {
```

[azure-storage]: https://azure.microsoft.com/en-us/services/storage/
[azure-environment]: https://godoc.org/github.com/Azure/go-autorest/autorest/azure#pkg-variables