@@ -436,12 +436,22 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
436
436
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 )
437
437
}
438
438
if volContentSource != nil {
439
- accountSASToken , authAzcopyEnv , err := d .getAzcopyAuth (ctx , accountName , accountKey , storageEndpointSuffix , accountOptions , secrets , secretName , secretNamespace )
439
+ accountSASToken , authAzcopyEnv , err := d .getAzcopyAuth (ctx , accountName , accountKey , storageEndpointSuffix , accountOptions , secrets , secretName , secretNamespace , false )
440
440
if err != nil {
441
441
return nil , status .Errorf (codes .Internal , "failed to getAzcopyAuth on account(%s) rg(%s), error: %v" , accountOptions .Name , accountOptions .ResourceGroup , err )
442
442
}
443
- if err := d .copyVolume (ctx , req , accountName , accountSASToken , authAzcopyEnv , validContainerName , secretNamespace , accountOptions , storageEndpointSuffix ); err != nil {
444
- return nil , err
443
+ var copyErr error
444
+ copyErr = d .copyVolume (ctx , req , accountName , accountSASToken , authAzcopyEnv , validContainerName , secretNamespace , accountOptions , storageEndpointSuffix )
445
+ if accountSASToken == "" && copyErr != nil && strings .Contains (copyErr .Error (), authorizationPermissionMismatch ) {
446
+ 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 )
447
+ accountSASToken , authAzcopyEnv , err := d .getAzcopyAuth (ctx , accountName , accountKey , storageEndpointSuffix , accountOptions , secrets , secretName , secretNamespace , true )
448
+ if err != nil {
449
+ return nil , status .Errorf (codes .Internal , "failed to getAzcopyAuth on account(%s) rg(%s), error: %v" , accountOptions .Name , accountOptions .ResourceGroup , err )
450
+ }
451
+ copyErr = d .copyVolume (ctx , req , accountName , accountSASToken , authAzcopyEnv , validContainerName , secretNamespace , accountOptions , storageEndpointSuffix )
452
+ }
453
+ if copyErr != nil {
454
+ return nil , copyErr
445
455
}
446
456
}
447
457
@@ -770,7 +780,7 @@ func (d *Driver) copyBlobContainer(ctx context.Context, req *csi.CreateVolumeReq
770
780
SubscriptionID : srcSubscriptionID ,
771
781
GetLatestAccountKey : accountOptions .GetLatestAccountKey ,
772
782
}
773
- if srcAccountSasToken , _ , err = d .getAzcopyAuth (ctx , srcAccountName , "" , storageEndpointSuffix , srcAccountOptions , nil , "" , secretNamespace ); err != nil {
783
+ if srcAccountSasToken , _ , err = d .getAzcopyAuth (ctx , srcAccountName , "" , storageEndpointSuffix , srcAccountOptions , nil , "" , secretNamespace , true ); err != nil {
774
784
return err
775
785
}
776
786
}
@@ -863,11 +873,10 @@ func (d *Driver) authorizeAzcopyWithIdentity() ([]string, error) {
863
873
// getAzcopyAuth will only generate sas token for azcopy in following conditions:
864
874
// 1. secrets is not empty
865
875
// 2. driver is not using managed identity and service principal
866
- // 3. azcopy returns AuthorizationPermissionMismatch error when using service principal or managed identity
867
- func (d * Driver ) getAzcopyAuth (ctx context.Context , accountName , accountKey , storageEndpointSuffix string , accountOptions * azure.AccountOptions , secrets map [string ]string , secretName , secretNamespace string ) (string , []string , error ) {
876
+ // 3. parameter useSasToken is true
877
+ 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 ) {
868
878
var authAzcopyEnv []string
869
879
var err error
870
- useSasToken := false
871
880
if ! d .useDataPlaneAPI ("" , accountName ) && len (secrets ) == 0 && len (secretName ) == 0 {
872
881
// search in cache first
873
882
if cache , err := d .azcopySasTokenCache .Get (accountName , azcache .CacheReadTypeDefault ); err == nil && cache != nil {
@@ -878,17 +887,6 @@ func (d *Driver) getAzcopyAuth(ctx context.Context, accountName, accountKey, sto
878
887
authAzcopyEnv , err = d .authorizeAzcopyWithIdentity ()
879
888
if err != nil {
880
889
klog .Warningf ("failed to authorize azcopy with identity, error: %v" , err )
881
- } else {
882
- if len (authAzcopyEnv ) > 0 {
883
- out , testErr := d .azcopy .TestListJobs (accountName , storageEndpointSuffix , authAzcopyEnv )
884
- if testErr != nil {
885
- return "" , nil , fmt .Errorf ("azcopy list command failed with error(%v): %v" , testErr , out )
886
- }
887
- if strings .Contains (out , authorizationPermissionMismatch ) {
888
- 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 )
889
- useSasToken = true
890
- }
891
- }
892
890
}
893
891
}
894
892
0 commit comments