@@ -590,8 +590,18 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
590
590
if err != nil {
591
591
return nil , status .Errorf (codes .Internal , "failed to getAzcopyAuth on account(%s) rg(%s), error: %v" , accountOptions .Name , accountOptions .ResourceGroup , err )
592
592
}
593
- if err := d .copyVolume (ctx , req , accountName , accountSASToken , authAzcopyEnv , secretName , secretNamespace , secret , shareOptions , accountOptions , storageEndpointSuffix ); err != nil {
594
- return nil , err
593
+ var copyErr error
594
+ copyErr = d .copyVolume (ctx , req , accountName , accountSASToken , authAzcopyEnv , secretNamespace , shareOptions , accountOptions , storageEndpointSuffix )
595
+ if accountSASToken == "" && copyErr != nil && strings .Contains (copyErr .Error (), authorizationPermissionMismatch ) {
596
+ klog .Warningf ("azcopy copy failed with AuthorizationPermissionMismatch error, should assign \" Storage File Data Privileged Contributor\" role to controller identity, fall back to use sas token, original error: %v" , copyErr )
597
+ accountSASToken , authAzcopyEnv , err := d .getAzcopyAuth (ctx , accountName , accountKey , storageEndpointSuffix , accountOptions , secret , secretName , secretNamespace , true )
598
+ if err != nil {
599
+ return nil , status .Errorf (codes .Internal , "failed to getAzcopyAuth on account(%s) rg(%s), error: %v" , accountOptions .Name , accountOptions .ResourceGroup , err )
600
+ }
601
+ copyErr = d .copyVolume (ctx , req , accountName , accountSASToken , authAzcopyEnv , secretNamespace , shareOptions , accountOptions , storageEndpointSuffix )
602
+ }
603
+ if copyErr != nil {
604
+ return nil , copyErr
595
605
}
596
606
// storeAccountKey is not needed here since copy volume is only using SAS token
597
607
storeAccountKey = false
@@ -741,13 +751,13 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
741
751
}
742
752
743
753
// copyVolume copy an azure file
744
- func (d * Driver ) copyVolume (ctx context.Context , req * csi.CreateVolumeRequest , accountName string , accountSASToken string , authAzcopyEnv []string , secretName , secretNamespace string , secrets map [ string ] string , shareOptions * fileclient.ShareOptions , accountOptions * azure.AccountOptions , storageEndpointSuffix string ) error {
754
+ func (d * Driver ) copyVolume (ctx context.Context , req * csi.CreateVolumeRequest , accountName , accountSASToken string , authAzcopyEnv []string , secretNamespace string , shareOptions * fileclient.ShareOptions , accountOptions * azure.AccountOptions , storageEndpointSuffix string ) error {
745
755
vs := req .VolumeContentSource
746
756
switch vs .Type .(type ) {
747
757
case * csi.VolumeContentSource_Snapshot :
748
758
return status .Errorf (codes .InvalidArgument , "copy volume from volumeSnapshot is not supported" )
749
759
case * csi.VolumeContentSource_Volume :
750
- return d .copyFileShare (ctx , req , accountName , accountSASToken , authAzcopyEnv , secretName , secretNamespace , secrets , shareOptions , accountOptions , storageEndpointSuffix )
760
+ return d .copyFileShare (ctx , req , accountName , accountSASToken , authAzcopyEnv , secretNamespace , shareOptions , accountOptions , storageEndpointSuffix )
751
761
default :
752
762
return status .Errorf (codes .InvalidArgument , "%v is not a proper volume source" , vs )
753
763
}
@@ -999,7 +1009,7 @@ func (d *Driver) ListSnapshots(_ context.Context, _ *csi.ListSnapshotsRequest) (
999
1009
return nil , status .Error (codes .Unimplemented , "" )
1000
1010
}
1001
1011
1002
- func (d * Driver ) copyFileShareByAzcopy (ctx context. Context , srcFileShareName , dstFileShareName , srcPath , dstPath , srcAccountName , dstAccountName , srcResourceGroupName , accountSASToken string , authAzcopyEnv []string , secretName , secretNamespace string , secrets map [ string ] string , accountOptions * azure.AccountOptions , storageEndpointSuffix string ) error {
1012
+ func (d * Driver ) copyFileShareByAzcopy (srcFileShareName , dstFileShareName , srcPath , dstPath , srcAccountName , dstAccountName string , authAzcopyEnv []string , accountOptions * azure.AccountOptions ) error {
1003
1013
azcopyCopyOptions := defaultAzcopyCopyOptions
1004
1014
jobState , percent , err := d .azcopy .GetAzcopyJob (dstFileShareName , authAzcopyEnv )
1005
1015
klog .V (2 ).Infof ("azcopy job status: %s, copy percent: %s%%, error: %v" , jobState , percent , err )
@@ -1021,33 +1031,6 @@ func (d *Driver) copyFileShareByAzcopy(ctx context.Context, srcFileShareName, ds
1021
1031
return fmt .Errorf ("timeout waiting for copy fileshare %s:%s to %s:%s complete, current copy percent: %s%%" , srcAccountName , srcFileShareName , dstAccountName , dstFileShareName , percent )
1022
1032
}
1023
1033
copyErr := volumehelper .WaitUntilTimeout (time .Duration (d .waitForAzCopyTimeoutMinutes )* time .Minute , execFuncWithAuth , timeoutFunc )
1024
- if accountSASToken == "" && copyErr != nil && strings .Contains (copyErr .Error (), authorizationPermissionMismatch ) {
1025
- klog .Warningf ("azcopy list failed with AuthorizationPermissionMismatch error, should assign \" Storage File Data Privileged Contributor\" role to controller identity, fall back to use sas token, original error: %v" , copyErr )
1026
- var srcSasToken , dstSasToken string
1027
- srcAccountOptions := & azure.AccountOptions {
1028
- Name : srcAccountName ,
1029
- ResourceGroup : srcResourceGroupName ,
1030
- SubscriptionID : accountOptions .SubscriptionID ,
1031
- GetLatestAccountKey : accountOptions .GetLatestAccountKey ,
1032
- }
1033
- if srcSasToken , _ , err = d .getAzcopyAuth (ctx , srcAccountName , "" , storageEndpointSuffix , srcAccountOptions , nil , "" , secretNamespace , true ); err != nil {
1034
- return err
1035
- }
1036
- if srcAccountName == dstAccountName {
1037
- dstSasToken = srcSasToken
1038
- } else {
1039
- if dstSasToken , _ , err = d .getAzcopyAuth (ctx , dstAccountName , "" , storageEndpointSuffix , accountOptions , secrets , secretName , secretNamespace , true ); err != nil {
1040
- return err
1041
- }
1042
- }
1043
- execFuncWithSasToken := func () error {
1044
- if out , err := d .execAzcopyCopy (srcPath + srcSasToken , dstPath + dstSasToken , azcopyCopyOptions , []string {}); err != nil {
1045
- return fmt .Errorf ("exec error: %v, output: %v" , err , string (out ))
1046
- }
1047
- return nil
1048
- }
1049
- copyErr = volumehelper .WaitUntilTimeout (time .Duration (d .waitForAzCopyTimeoutMinutes )* time .Minute , execFuncWithSasToken , timeoutFunc )
1050
- }
1051
1034
if copyErr != nil {
1052
1035
klog .Warningf ("CopyFileShare(%s, %s, %s) failed with error: %v" , accountOptions .ResourceGroup , dstAccountName , dstFileShareName , copyErr )
1053
1036
} else {
@@ -1309,12 +1292,11 @@ func (d *Driver) authorizeAzcopyWithIdentity() ([]string, error) {
1309
1292
// getAzcopyAuth will only generate sas token for azcopy in following conditions:
1310
1293
// 1. secrets is not empty
1311
1294
// 2. driver is not using managed identity and service principal
1312
- // 3. azcopy returns AuthorizationPermissionMismatch error when using service principal or managed identity
1313
- // 4. parameter useSasToken is true
1295
+ // 3. parameter useSasToken is true
1314
1296
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 ) {
1315
1297
var authAzcopyEnv []string
1316
1298
var err error
1317
- if ! useSasToken && len (secrets ) == 0 && len (secretName ) == 0 {
1299
+ if ! useSasToken && ! d . useDataPlaneAPI ( "" , accountName ) && len (secrets ) == 0 && len (secretName ) == 0 {
1318
1300
// search in cache first
1319
1301
if cache , err := d .azcopySasTokenCache .Get (accountName , azcache .CacheReadTypeDefault ); err == nil && cache != nil {
1320
1302
klog .V (2 ).Infof ("use sas token for account(%s) since this account is found in azcopySasTokenCache" , accountName )
0 commit comments