Home
%3CLINGO-SUB%20id%3D%22lingo-sub-734310%22%20slang%3D%22en-US%22%3EHow%20to%20Copy%20Azure%20Storage%20Account%20Files%20with%20AzCopy%20and%20Azure%20AD%20Credentials%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-734310%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20the%20last%20couple%20of%20weeks%2C%20you%20might%20have%20seen%20that%20I%20wrote%20a%20couple%20of%20blog%20posts%20on%20how%20to%20manage%20Azure%20Blob%20Storage%20with%20AzCopy.%20Including%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FITOps-Talk-Blog%2FHow-To-Upload-files-to-Azure-Blob-Storage-using-PowerShell-and%2Fba-p%2F650309%3FWT.mc_id%3Ditopstalk-blog-thmaure%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3Ehow%20you%20can%20upload%20files%20to%20Azure%20Blob%20Storage%20container%20with%20PowerShell%3C%2FA%3E%2C%20sync%20files%20to%20Azure%20Blob%20storage%20or%20even%20%3CA%20href%3D%22https%3A%2F%2Fwww.thomasmaurer.ch%2F2019%2F06%2Fmigrate-aws-s3-buckets-to-azure-blob-storage%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Emigrate%20AWS%20S3%20buckets%20to%20Azure%3C%2FA%3E.%20In%20most%20cases%20you%20have%20used%20AzCopy%2C%20you%20might%20have%20used%20SAS%20tokens%2C%20with%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fstorage%2Fcommon%2Fstorage-use-azcopy-v10%3FWT.mc_id%3Ditopstalk-blog-thmaure%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzCopy%20v10%3C%2FA%3Ehowever%20you%20can%20also%20use%20Azure%20AD%20accounts%20and%20service%20principals.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAuthenticate%20against%20Azure%20with%20AzCopy%20using%20Azure%20AD%20accounts%20is%20simple.%20You%20can%20use%20the%20AzCopy%20login%20command%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3Eazcopy%20login%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20your%20account%20is%20in%20multiple%20Azure%20AD%20tenant%2C%20you%20can%20also%20add%20the%20specific%20tenant%20ID.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3Eazcopy%20login%20--tenant-id%20%22XXXXXXXX-XXXX-XXXXX-XXXXX-XXXXXXXXXXX%22%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20find%20your%20tenant%20ID%2C%20login%20to%20the%20%3CA%20href%3D%22https%3A%2F%2Fportal.azure.com%3FWT.mc_id%3Ditopstalk-blog-thmaure%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Portal%3C%2FA%3E%2C%20go%20to%20Azure%20Active%20Directory%20-%26gt%3B%20Properties%3B%20there%20you%20find%20your%20Directory%2FTenant%20ID.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAfter%20running%20this%20command%2C%20you%20will%20need%20to%20open%20the%20device%20login%20page%20and%20enter%20your%20code%20to%20authenticate.%20If%20you%20signed-in%20correctly%2C%20you%20will%20see%20the%20following%20page%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20787px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F121904iCCDC8552AD3CE375%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Azure%20Device%20Login%20Page.jpg%22%20title%3D%22Azure%20Device%20Login%20Page.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ESet%20the%20right%20permissions%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EImportant%2C%20to%20interact%20with%20the%20Azure%20Storage%20Account%2C%20you%20will%20need%20to%20set%20the%20right%20permissions%20for%20the%20account%2C%20even%20if%20you%20are%20the%20storage%20account%20owner.%3C%2FP%3E%0A%3CP%3EIf%20you%20want%20to%20download%20files%20from%20Azure%20blob%20storage%2C%20make%20sure%20that%20your%20user%20identity%20has%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Frole-based-access-control%2Fbuilt-in-roles%23storage-blob-data-reader%3FWT.mc_id%3Ditopstalk-blog-thmaure%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EStorage%20Blob%20Data%20Reader%3C%2FA%3Erole%20assigned.%20If%20you%20want%20to%20upload%20files%2C%20you%20will%20need%20to%20assign%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Frole-based-access-control%2Fbuilt-in-roles%23storage-queue-data-contributor%3FWT.mc_id%3Ditopstalk-blog-thmaure%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EStorage%20Blob%20Data%20Contributor%3C%2FA%3Eor%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Frole-based-access-control%2Fbuilt-in-roles%23storage-blob-data-owner%3FWT.mc_id%3Ditopstalk-blog-thmaure%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EStorage%20Blob%20Data%20Owner%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20assign%20these%20roles%20on%20different%20scopes%2C%20with%20more%20and%20less%20granularity.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EContainer%20(file%20system)%3C%2FLI%3E%0A%3CLI%3EStorage%20account%3C%2FLI%3E%0A%3CLI%3EResource%20group%3C%2FLI%3E%0A%3CLI%3ESubscription%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EWith%20the%20right%20permissions%20and%20login%2C%20you%20can%20now%20easily%20upload%20and%20download%20files%20from%20your%20Azure%20Storage%20Account%20using%20AzCopy%20and%20your%20Azure%20AD%20credentials.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F121905iF1AE74803C42C877%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22AzCopy%20Login%20Copy%20Files%20Azure%20AD.jpg%22%20title%3D%22AzCopy%20Login%20Copy%20Files%20Azure%20AD.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3Eazcopy%20copy%20%E2%80%9CC%3A%5Ctemp%5Cimages%E2%80%9D%20%E2%80%9Chttps%3A%2F%2Faccount.blob.core.windows.net%2Fimages%2F%22%20--recursive%3Dtrue%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20are%20like%20me%20and%20you%20get%20the%20following%20error%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%E2%80%9CRESPONSE%20Status%3A%20403%20This%20request%20is%20not%20authorized%20to%20perform%20this%20operation%20using%20this%20permission.%E2%80%9D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F121906iD215AC116DE50B5A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22AzCopy%20Copy%20Failed%20403%20permission.jpg%22%20title%3D%22AzCopy%20Copy%20Failed%20403%20permission.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20don%E2%80%99t%20have%20the%20right%20permissions%2C%20and%20you%20will%20need%20to%20see%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fstorage%2Fcommon%2Fstorage-auth-aad-rbac-portal%3FWT.mc_id%3Ditopstalk-blog-thmaure%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Egrant%20access%20to%20Azure%20blob%20and%20queue%20data%20with%20RBAC%20in%20the%20Azure%20portal%3C%2FA%3E%2C%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fstorage%2Fcommon%2Fstorage-auth-aad-rbac-cli%3FWT.mc_id%3Ditopstalk-blog-thmaure%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20CLI%3C%2FA%3Eor%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fstorage%2Fcommon%2Fstorage-auth-aad-rbac-powershell%3FWT.mc_id%3Ditopstalk-blog-thmaure%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20PowerShell%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20hope%20this%20article%20helps%20you%2C%20especially%20when%20you%20didn%E2%80%99t%20configure%20the%20necessary%20permissions%2C%20or%20your%20account%20is%20in%20multiple%20Azure%20AD%20tenants.%20If%20you%20have%20any%20questions%2C%20please%20let%20me%20know%20in%20the%20comments.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-734310%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20AzCopy%20you%20can%20use%20Azure%20AD%20to%20authenticate%20against%20Azure%20to%20upload%20and%20download%20files%20from%20Azure%20Blob%20Storage.%20Check%20it%20out%20right%20here!%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-734310%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzCopy%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20AD%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Storage%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eblob%20storage%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ECloud%20Storage%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ELinux%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EThomas%20Maurer%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

In the last couple of weeks, you might have seen that I wrote a couple of blog posts on how to manage Azure Blob Storage with AzCopy. Including how you can upload files to Azure Blob Storage container with PowerShell, sync files to Azure Blob storage or even migrate AWS S3 buckets to Azure. In most cases you have used AzCopy, you might have used SAS tokens, with AzCopy v10 however you can also use Azure AD accounts and service principals.

 

Authenticate against Azure with AzCopy using Azure AD accounts is simple. You can use the AzCopy login command:

 

azcopy login

 

If your account is in multiple Azure AD tenant, you can also add the specific tenant ID.

 

azcopy login --tenant-id "XXXXXXXX-XXXX-XXXXX-XXXXX-XXXXXXXXXXX"

 

You can find your tenant ID, login to the Azure Portal, go to Azure Active Directory -> Properties; there you find your Directory/Tenant ID.

 

After running this command, you will need to open the device login page and enter your code to authenticate. If you signed-in correctly, you will see the following page:

 

Azure Device Login Page.jpg

 

 

Set the right permissions

 

Important, to interact with the Azure Storage Account, you will need to set the right permissions for the account, even if you are the storage account owner.

If you want to download files from Azure blob storage, make sure that your user identity has the Storage Blob Data Reader role assigned. If you want to upload files, you will need to assign Storage Blob Data Contributor or Storage Blob Data Owner.

 

You can assign these roles on different scopes, with more and less granularity.

  • Container (file system)
  • Storage account
  • Resource group
  • Subscription

With the right permissions and login, you can now easily upload and download files from your Azure Storage Account using AzCopy and your Azure AD credentials.

 

AzCopy Login Copy Files Azure AD.jpg

 

 

azcopy copy “C:\temp\images” “https://account.blob.core.windows.net/images/" --recursive=true

 

If you are like me and you get the following error:

 

“RESPONSE Status: 403 This request is not authorized to perform this operation using this permission.”

 

AzCopy Copy Failed 403 permission.jpg

 

 

You don’t have the right permissions, and you will need to see grant access to Azure blob and queue data with RBAC in the Azure portal, Azure CLI or Azure PowerShell.

 

I hope this article helps you, especially when you didn’t configure the necessary permissions, or your account is in multiple Azure AD tenants. If you have any questions, please let me know in the comments.