added azure domain parameter

This commit is contained in:
arjunajesh 2023-06-24 20:06:54 -04:00 committed by Michael Eischer
parent f96896a9c0
commit 068b115abc
5 changed files with 30 additions and 6 deletions

View file

@ -0,0 +1,6 @@
Enhancement: Add support for non-global Azure clouds
Restic backups on azure only worked for storages on the global domain `core.windows.net`. This meant that backups to other domains such as Azure China (`core.chinacloudapi.cn') were not supported. Restic now allows overriding the global domain using the environment variable `AZURE_ENDPOINT_SUFFIX'.
https://github.com/restic/restic/issues/2468
https://github.com/restic/restic/pull/4387

View file

@ -537,6 +537,13 @@ or
$ export AZURE_ACCOUNT_NAME=<ACCOUNT_NAME> $ export AZURE_ACCOUNT_NAME=<ACCOUNT_NAME>
$ export AZURE_ACCOUNT_SAS=<SAS_TOKEN> $ export AZURE_ACCOUNT_SAS=<SAS_TOKEN>
Restic will use Azure's global domain ``core.windows.net`` by default. You can specify other
domains to be used like so:
.. code-block:: console
$export AZURE_ENDPOINT_SUFFIX=<ENDPOINT_SUFFIX>
Afterwards you can initialize a repository in a container called ``foo`` in the Afterwards you can initialize a repository in a container called ``foo`` in the
root path like this: root path like this:

View file

@ -614,6 +614,7 @@ environment variables. The following lists these environment variables:
AZURE_ACCOUNT_NAME Account name for Azure AZURE_ACCOUNT_NAME Account name for Azure
AZURE_ACCOUNT_KEY Account key for Azure AZURE_ACCOUNT_KEY Account key for Azure
AZURE_ACCOUNT_SAS Shared access signatures (SAS) for Azure AZURE_ACCOUNT_SAS Shared access signatures (SAS) for Azure
AZURE_ENDPOINT_SUFFIX Domain of Azure Storage (default: core.windows.net)
GOOGLE_PROJECT_ID Project ID for Google Cloud Storage GOOGLE_PROJECT_ID Project ID for Google Cloud Storage
GOOGLE_APPLICATION_CREDENTIALS Application Credentials for Google Cloud Storage (e.g. $HOME/.config/gs-secret-restic-key.json) GOOGLE_APPLICATION_CREDENTIALS Application Credentials for Google Cloud Storage (e.g. $HOME/.config/gs-secret-restic-key.json)

View file

@ -53,7 +53,13 @@ func open(cfg Config, rt http.RoundTripper) (*Backend, error) {
var client *azContainer.Client var client *azContainer.Client
var err error var err error
url := fmt.Sprintf("https://%s.blob.core.windows.net/%s", cfg.AccountName, cfg.Container) var endpointSuffix string
if cfg.EndpointSuffix != "" {
endpointSuffix = cfg.EndpointSuffix
} else {
endpointSuffix = "core.windows.net"
}
url := fmt.Sprintf("https://%s.blob.%s/%s", cfg.AccountName, endpointSuffix, cfg.Container)
opts := &azContainer.ClientOptions{ opts := &azContainer.ClientOptions{
ClientOptions: azcore.ClientOptions{ ClientOptions: azcore.ClientOptions{
Transport: &http.Client{Transport: rt}, Transport: &http.Client{Transport: rt},

View file

@ -16,6 +16,7 @@ type Config struct {
AccountName string AccountName string
AccountSAS options.SecretString AccountSAS options.SecretString
AccountKey options.SecretString AccountKey options.SecretString
EndpointSuffix string
Container string Container string
Prefix string Prefix string
@ -71,4 +72,7 @@ func (cfg *Config) ApplyEnvironment(prefix string) {
if cfg.AccountSAS.String() == "" { if cfg.AccountSAS.String() == "" {
cfg.AccountSAS = options.NewSecretString(os.Getenv(prefix + "AZURE_ACCOUNT_SAS")) cfg.AccountSAS = options.NewSecretString(os.Getenv(prefix + "AZURE_ACCOUNT_SAS"))
} }
if cfg.EndpointSuffix == "" {
cfg.EndpointSuffix = os.Getenv("AZURE_ENDPOINT_SUFFIX")
}
} }