diff --git a/pkg/blob/blob.go b/pkg/blob/blob.go index 91170118a..ec7d97bc0 100644 --- a/pkg/blob/blob.go +++ b/pkg/blob/blob.go @@ -268,6 +268,9 @@ type Driver struct { waitForAzCopyTimeoutMinutes int // azcopy for provide exec mock for ut azcopy *util.Azcopy + + // if azcopy has to trust the driver's supplying endpoint + requiredAzCopyToTrust bool } // NewDriver Creates a NewCSIDriver object. Assumes vendor version is equal to driver version & @@ -327,6 +330,12 @@ func NewDriver(options *DriverOptions, kubeClient kubernetes.Interface, cloud *s klog.Fatalf("%v", err) } + requiredAzCopyToTrust := d.getStorageEndPointSuffix() != "" && !strings.Contains(azcopyTrustedSuffixesAAD, d.getStorageEndPointSuffix()) + if requiredAzCopyToTrust { + klog.V(2).Infof("storage endpoint suffix %s is not in azcopy trusted suffixes, azcopy will trust it temporarily during volume clone and snapshot restore", d.getStorageEndPointSuffix()) + } + d.requiredAzCopyToTrust = requiredAzCopyToTrust + d.mounter = &mount.SafeFormatAndMount{ Interface: mount.New(""), Exec: utilexec.New(), diff --git a/pkg/blob/controllerserver.go b/pkg/blob/controllerserver.go index 6391c9553..53de5239f 100644 --- a/pkg/blob/controllerserver.go +++ b/pkg/blob/controllerserver.go @@ -61,6 +61,9 @@ const ( authorizationPermissionMismatch = "AuthorizationPermissionMismatch" createdByMetadata = "createdBy" + + // refer https://github.com/Azure/azure-storage-azcopy/wiki/azcopy + azcopyTrustedSuffixesAAD = "*.core.windows.net;*.core.chinacloudapi.cn;*.core.cloudapi.de;*.core.usgovcloudapi.net;*.storage.azure.net" ) // CreateVolume provisions a volume @@ -869,6 +872,11 @@ func (d *Driver) copyVolume(ctx context.Context, req *csi.CreateVolumeRequest, a // execAzcopyCopy exec azcopy copy command func (d *Driver) execAzcopyCopy(srcPath, dstPath string, azcopyCopyOptions, authAzcopyEnv []string) ([]byte, error) { + // Use --trusted-microsoft-suffixes option to avoid failure caused by + if d.requiredAzCopyToTrust { + azcopyCopyOptions = append(azcopyCopyOptions, fmt.Sprintf("--trusted-microsoft-suffixes=%s", d.getStorageEndPointSuffix())) + } + cmd := exec.Command("azcopy", "copy", srcPath, dstPath) cmd.Args = append(cmd.Args, azcopyCopyOptions...) if len(authAzcopyEnv) > 0 {