Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

chore: add sas token support for abs. #2123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions pkg/apis/etcd/v1beta2/backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
BackupStorageTypeABS BackupStorageType = "ABS"
AzureSecretStorageAccount = "storage-account"
AzureSecretStorageKey = "storage-key"
AzureSecretSASURI = "storage-sas-uri"
AzureCloudKey = "cloud"

// Google GCS related consts
Expand Down
1 change: 1 addition & 0 deletions pkg/backup/backup_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (bm *BackupManager) EnsureMaxBackup(ctx context.Context, basePath string, m
if err != nil {
return fmt.Errorf("failed to delete snapshot: %v", err)
}
logrus.Infof("Successfully deleted snapshot: (%s)", snapshotPath)
}
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/backup/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func MakeBackupName(ver string, rev int64) string {
func ParseBucketAndKey(path string) (string, string, error) {
toks := strings.SplitN(path, "/", 2)
if len(toks) != 2 || len(toks[0]) == 0 || len(toks[1]) == 0 {
return "", "", fmt.Errorf("Invalid S3 path (%v)", path)
// this is used by gcs/oss/abs/s3
return "", "", fmt.Errorf("Invalid path (%v)", path)
}
return toks[0], toks[1], nil
}
28 changes: 22 additions & 6 deletions pkg/util/azureutil/absfactory/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,34 @@ func NewClientFromSecret(kubecli kubernetes.Interface, namespace, absSecret stri
storageAccount := se.Data[api.AzureSecretStorageAccount]
storageKey := se.Data[api.AzureSecretStorageKey]
cloudName := se.Data[api.AzureCloudKey]
sasURI := se.Data[api.AzureSecretSASURI]

cloud, err := parseAzureEnvironment(string(cloudName))
if err != nil {
return nil, err
}
var bc storage.Client
if len(sasURI) != 0 {
qIndex := strings.IndexAny(sasURI, "?")
if qIndex != -1 {
baseURL := sasURI[0:qIndex]
sasToken := sasURI[qIndex+1:]

bc, err := storage.NewBasicClientOnSovereignCloud(
string(storageAccount),
string(storageKey),
cloud)
if err != nil {
return nil, fmt.Errorf("failed to create Azure storage client: %v", err)
bc, err := storage.NewAccountSASClientFromEndpointToken(baseURL, sasToken)
if err != nil {
return nil, fmt.Errorf("create ABS client (from SAS token) failed: %v", err)
}
} else {
return nil, fmt.Errorf("No '?' in the URI, invalid sas token uri")
}
} else {
bc, err := storage.NewBasicClientOnSovereignCloud(
string(storageAccount),
string(storageKey),
cloud)
if err != nil {
return nil, fmt.Errorf("failed to create Azure storage client: %v", err)
}
}

abs := bc.GetBlobService()
Expand Down