diff --git a/src/Storage/Storage.Management/ChangeLog.md b/src/Storage/Storage.Management/ChangeLog.md index d6d363376904..4b8a44524c19 100644 --- a/src/Storage/Storage.Management/ChangeLog.md +++ b/src/Storage/Storage.Management/ChangeLog.md @@ -23,6 +23,7 @@ - `Update-AzRmStorageShare` * Supported enable Smb Multichannel on File service - `Update-AzStorageFileServiceProperty` +* Fixed copy inside same account issue by access source with anynymous credentail, when copy Blob inside same account with Oauth credentail ## Version 3.7.0 * Supported file share snapshot diff --git a/src/Storage/Storage/Blob/Cmdlet/StartAzureStorageBlobCopy.cs b/src/Storage/Storage/Blob/Cmdlet/StartAzureStorageBlobCopy.cs index be81d99a50d8..80e130284dc0 100644 --- a/src/Storage/Storage/Blob/Cmdlet/StartAzureStorageBlobCopy.cs +++ b/src/Storage/Storage/Blob/Cmdlet/StartAzureStorageBlobCopy.cs @@ -626,7 +626,20 @@ private async Task StartCopyFromBlob(long taskId, IStorageBlobManagement destCha { try { - await StartCopyFromUri(taskId, destChannel, srcBlob.GenerateUriWithCredentials(), destBlob).ConfigureAwait(false); + Uri srcBlobUriWithCredentail = null; + if (Channel!=null && destChannel != null && + Channel.StorageContext!= null && destChannel.StorageContext != null + && Channel.StorageContext.StorageAccountName == destChannel.StorageContext.StorageAccountName + && Channel.StorageContext.StorageAccount.Credentials.IsToken) + { + // if inside same account, source blob can be anonumous + srcBlobUriWithCredentail = srcBlob.SnapshotQualifiedUri; + } + else + { + srcBlobUriWithCredentail = srcBlob.GenerateUriWithCredentials(); + } + await StartCopyFromUri(taskId, destChannel, srcBlobUriWithCredentail, destBlob).ConfigureAwait(false); } catch (StorageException ex) { @@ -648,7 +661,20 @@ private async Task StartCopyFromBlob(long taskId, IStorageBlobManagement destCha { try { - await StartCopyFromUri(taskId, destChannel, srcBlob.GenerateUriWithCredentials(Channel.StorageContext), destBlob).ConfigureAwait(false); + Uri srcBlobUriWithCredentail = null; + if (Channel != null && destChannel != null && + Channel.StorageContext != null && destChannel.StorageContext != null + && Channel.StorageContext.StorageAccountName == destChannel.StorageContext.StorageAccountName + && Channel.StorageContext.StorageAccount.Credentials.IsToken) + { + // if inside same account, source blob can be anonumous + srcBlobUriWithCredentail = srcBlob.Uri; + } + else + { + srcBlobUriWithCredentail = srcBlob.GenerateUriWithCredentials(Channel.StorageContext); + } + await StartCopyFromUri(taskId, destChannel, srcBlobUriWithCredentail, destBlob).ConfigureAwait(false); } catch (StorageException ex) {