@@ -430,12 +430,22 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
430
430
return nil , status .Errorf (codes .Internal , "failed to create container(%s) on account(%s) type(%s) rg(%s) location(%s) size(%d), error: %v" , validContainerName , accountName , storageAccountType , resourceGroup , location , requestGiB , err )
431
431
}
432
432
if volContentSource != nil {
433
- accountSASToken , authAzcopyEnv , err := d .getAzcopyAuth (ctx , accountName , accountKey , storageEndpointSuffix , accountOptions , secrets , secretName , secretNamespace )
433
+ accountSASToken , authAzcopyEnv , err := d .getAzcopyAuth (ctx , accountName , accountKey , storageEndpointSuffix , accountOptions , secrets , secretName , secretNamespace , false )
434
434
if err != nil {
435
435
return nil , status .Errorf (codes .Internal , "failed to getAzcopyAuth on account(%s) rg(%s), error: %v" , accountOptions .Name , accountOptions .ResourceGroup , err )
436
436
}
437
- if err := d .copyVolume (ctx , req , accountName , accountSASToken , authAzcopyEnv , validContainerName , secretNamespace , accountOptions , storageEndpointSuffix ); err != nil {
438
- return nil , err
437
+ var copyErr error
438
+ copyErr = d .copyVolume (ctx , req , accountName , accountSASToken , authAzcopyEnv , validContainerName , secretNamespace , accountOptions , storageEndpointSuffix )
439
+ if accountSASToken == "" && copyErr != nil && strings .Contains (copyErr .Error (), authorizationPermissionMismatch ) {
440
+ klog .Warningf ("azcopy copy failed with AuthorizationPermissionMismatch error, should assign \" Storage Blob Data Contributor\" role to controller identity, fall back to use sas token, original error: %v" , copyErr )
441
+ accountSASToken , authAzcopyEnv , err := d .getAzcopyAuth (ctx , accountName , accountKey , storageEndpointSuffix , accountOptions , secrets , secretName , secretNamespace , true )
442
+ if err != nil {
443
+ return nil , status .Errorf (codes .Internal , "failed to getAzcopyAuth on account(%s) rg(%s), error: %v" , accountOptions .Name , accountOptions .ResourceGroup , err )
444
+ }
445
+ copyErr = d .copyVolume (ctx , req , accountName , accountSASToken , authAzcopyEnv , validContainerName , secretNamespace , accountOptions , storageEndpointSuffix )
446
+ }
447
+ if copyErr != nil {
448
+ return nil , copyErr
439
449
}
440
450
}
441
451
@@ -748,7 +758,7 @@ func (d *Driver) copyBlobContainer(ctx context.Context, req *csi.CreateVolumeReq
748
758
SubscriptionID : srcSubscriptionID ,
749
759
GetLatestAccountKey : accountOptions .GetLatestAccountKey ,
750
760
}
751
- if srcAccountSasToken , _ , err = d .getAzcopyAuth (ctx , srcAccountName , "" , storageEndpointSuffix , srcAccountOptions , nil , "" , secretNamespace ); err != nil {
761
+ if srcAccountSasToken , _ , err = d .getAzcopyAuth (ctx , srcAccountName , "" , storageEndpointSuffix , srcAccountOptions , nil , "" , secretNamespace , true ); err != nil {
752
762
return err
753
763
}
754
764
}
@@ -841,12 +851,11 @@ func (d *Driver) authorizeAzcopyWithIdentity() ([]string, error) {
841
851
// getAzcopyAuth will only generate sas token for azcopy in following conditions:
842
852
// 1. secrets is not empty
843
853
// 2. driver is not using managed identity and service principal
844
- // 3. azcopy returns AuthorizationPermissionMismatch error when using service principal or managed identity
845
- func (d * Driver ) getAzcopyAuth (ctx context.Context , accountName , accountKey , storageEndpointSuffix string , accountOptions * azure.AccountOptions , secrets map [string ]string , secretName , secretNamespace string ) (string , []string , error ) {
854
+ // 3. parameter useSasToken is true
855
+ func (d * Driver ) getAzcopyAuth (ctx context.Context , accountName , accountKey , storageEndpointSuffix string , accountOptions * azure.AccountOptions , secrets map [string ]string , secretName , secretNamespace string , useSasToken bool ) (string , []string , error ) {
846
856
var authAzcopyEnv []string
847
857
var err error
848
- useSasToken := false
849
- if ! d .useDataPlaneAPI ("" , accountName ) && len (secrets ) == 0 && len (secretName ) == 0 {
858
+ if ! useSasToken && ! d .useDataPlaneAPI ("" , accountName ) && len (secrets ) == 0 && len (secretName ) == 0 {
850
859
// search in cache first
851
860
if cache , err := d .azcopySasTokenCache .Get (accountName , azcache .CacheReadTypeDefault ); err == nil && cache != nil {
852
861
klog .V (2 ).Infof ("use sas token for account(%s) since this account is found in azcopySasTokenCache" , accountName )
@@ -856,17 +865,6 @@ func (d *Driver) getAzcopyAuth(ctx context.Context, accountName, accountKey, sto
856
865
authAzcopyEnv , err = d .authorizeAzcopyWithIdentity ()
857
866
if err != nil {
858
867
klog .Warningf ("failed to authorize azcopy with identity, error: %v" , err )
859
- } else {
860
- if len (authAzcopyEnv ) > 0 {
861
- out , testErr := d .azcopy .TestListJobs (accountName , storageEndpointSuffix , authAzcopyEnv )
862
- if testErr != nil {
863
- return "" , nil , fmt .Errorf ("azcopy list command failed with error(%v): %v" , testErr , out )
864
- }
865
- if strings .Contains (out , authorizationPermissionMismatch ) {
866
- klog .Warningf ("azcopy list failed with AuthorizationPermissionMismatch error, should assign \" Storage Blob Data Contributor\" role to controller identity, fall back to use sas token, original output: %v" , out )
867
- useSasToken = true
868
- }
869
- }
870
868
}
871
869
}
872
870
0 commit comments