Loading...

AzCopy support for Entra ID authentication

AzCopy support for Entra ID authentication

AzCopy support for Entra ID authentication using Azure CLI or PowerShell authentication tokens

 

Using AzCopy version 10.22.0 or newer you can reuse your existing Entra ID authentication tokens from Azure PowerShell and Azure CLI for authentication for blob transfers to and from your storage accounts. This will reduce the number of times you have to enter your credentials when using Azure PowerShell and Azure CLI in the same session as you login to either Azure PowerShell or Azure CLI once and you do not need to enter a separate set of credentials in AzCopy. By the end of this article, you will be able to authenticate AzCopy actions seamlessly on Linux or Windows by reusing an existing OAuth token.

 

Environment variables

To enable this new feature, you must set the AZCOPY_AUTO_LOGIN_TYPE environment variable to the appropriate value. Besides the existing authentication methods - using a Service Principal or Managed Service Identity - two new options are now available. AZCLI for Azure CLI and PSCRED for Azure PowerShell. If you want to learn more on AzCopy supported environment variables you can easily get overview using the following command: azcopy env

 

To change the login type to either reusing OAuth tokens from Azure CLI or Azure PowerShell use one of the following commands for each operating system:

 

Linux and macOS environment variables

 

 

export AZCOPY_AUTO_LOGIN_TYPE=AZCLI export AZCOPY_AUTO_LOGIN_TYPE=PSCRED

 

 

Windows environment variables

 

 

$Env:AZCOPY_AUTO_LOGIN_TYPE="AZCLI" $Env:AZCOPY_AUTO_LOGIN_TYPE="PSCRED"

 

 

 

Scenarios

The prerequisite for all samples is that you own an active Azure Subscription and already deployed a storage account with a container. Write Permissions on the data plane needs be granted for your Entra ID account (see Assign an Azure role for access to blob data).

 

Note: If you don’t own an Azure Subscription you can create your Azure Free Account today. If you are facing troubles creating a storage account or granting the needed permissions you can read the Optional section at the end of this article.

 

Please make sure you have the newest version (>=10.22.0) of the AzCopy installed on your local machine. You can download it manually  or use the provided CLI command for each scenario either using Linux or Windows.

 

Flow diagram

The following diagram shows the flow diagram of each scenario in detail.

 

dafalkne_0-1706021688648.png

 

 

 

Scenario 1: Using Linux on Windows Subsystem for Linux (WSL)

Using WSL and Ubuntu 22.04 LTS you can download the newest version of AzCopy using the following bash one-liner.

 

 

wget -cq https://aka.ms/downloadazcopy-v10-linux -O - | tar xz --strip-components=1

 

 

Optional: Verify your login type (AZCOPY_AUTO_LOGIN_TYPE) is set to use the Azure CLI

 

 

./azcopy env INFO: Name: AZCOPY_AUTO_LOGIN_TYPE Current Value: AZCLI

 

 

Now we can try to upload a file, in this case the AzCopy binary itself, to the storage account.  Please replace "<storage-account>" and "<container>" with their respective values.

 

 

./azcopy copy azcopy https://<storage-account>.blob.core.windows.net/<container>/azcopy

 

 

 

NOTE: This command will fail if you don’t have Contributor or at least a sufficient RBAC role for write access on the storage account. Please make sure you are already authenticated using "az login" and the container you try to upload to exists.

 

Scenario 2: Using Windows 11

Using Windows 11 you can download the newest version of AzCopy using the following PowerShell commands.

 

 

Invoke-WebRequest -Uri 'https://aka.ms/downloadazcopy-v10-windows' -OutFile 'azcopyv10.zip' Expand-archive -Path '.\azcopyv10.zip' -Destinationpath '.\' $AzCopy = (Get-ChildItem -path '.\' -Recurse -File -Filter 'azcopy.exe').FullName

 

 

Optional: Verify your login type (AZCOPY_AUTO_LOGIN_TYPE) is set to use Azure PowerShell

 

 

& $AzCopy env INFO: Name: AZCOPY_AUTO_LOGIN_TYPE Current Value: PSCRED

 

 

Now we can try to upload a file, in this case the AzCopy binary itself, to the storage account. Please replace "<storage-account>" and "<container>" with their respective values.

 

 

& $AzCopy copy $AzCopy https://<storage-account>.blob.core.windows.net/<container>/azcopy.exe

 

 

 

NOTE: This command will fail if you don’t have Contributor or at least a sufficient RBAC role for write access on the storage account. Please make sure you are already authenticated using "Connect-AzAccount" and the container you try to upload to exists.

 

Optional: How to create a demo storage account

To create and configure a storage account on Azure you can use the following Azure CLI commands. There are a couple of other options available outlined in the official documentation.

 

First of all, we need to create a resource group. You can change the variables for the name or location to fit your needs. For the sake of the sample, it’s fine to start with the following command and options:

 

 

az group create --name MyResourceGroup --location westus

 

 

Next, create a storage account and a container using the resource group you just created. As a storage account name is globally unique you must change the name "<storage-account>" in the following command. Also change the name of the "<container>" variable. 

 

 

az storage account create --name <storage-account> --resource-group MyResourceGroup --location westus --sku Standard_LRS az storage container create -n <container> --account-name <storage-account>

 

 

Last we need to grant our Entry ID account write permission on the storage accounts data plane, replacing "<email>", "<subscription>", "<resource-group>", "<storage-account>" and "<container>" with their respective values.

 

 

az role assignment create \ --role "Storage Blob Data Contributor" \ --assignee <email> \ --scope "/subscriptions/<subscription>/resourceGroups/<resource-group>/providers/Microsoft.Storage/storageAccounts/<storage-account>/blobServices/default/containers/<container>"

 

 

 

 

References

 

 

Published on:

Learn more
Azure Storage Blog articles
Azure Storage Blog articles

Azure Storage Blog articles

Share post:

Related posts

Update on classic storage account retirement and upcoming changes for classic storage customers

We previously announced that support would end for retired Azure classic storage accounts on 31 August 2024. Now that we are past the retireme...

1 year ago

Azure Elastic SAN for Azure VMware Solution: now Generally Available

Have you been looking to expand your storage on Azure VMware Solution (AVS), but do not need the extra compute performance and the associated ...

1 year ago

Accelerate metadata heavy workloads with Metadata Caching preview for Azure Premium Files SMB & REST

Azure Files previously announced the limited preview of Metadata caching highlighting improvements on the metadata latency (up to 55...

1 year ago

Announcing UNLIMITED Public Preview of Metadata Caching for Azure Premium SMB/REST File Shares

Azure Files is excited to announce the Unlimited public preview of Metadata Caching for the premium SMB/REST file share tier.  Unlimited ...

1 year ago

Azure Backup-SAP HANA DB Backup Delivers More Value at Lower TCO with Reduced Protected Instance Fee

Azure Backup for SAP HANA Database Delivers More Value at Lower TCO with Reduced Protected Instance Fees starting 1st Sept’2024   At Azur...

1 year ago

Switch to Azure Business Continuity Center for your at scale BCDR management needs

In response to the evolving customer requirements and environments since COVID-19, including the shift towards hybrid work models and the incr...

1 year ago

The Azure Storage product group is heading to the SNIA Developer Conference 2024

The Azure Storage product group is heading to the SNIA Developer Conference (SDC) 2024 in Santa Clara, California, USA from September 16th thr...

1 year ago

Latest advancements in Premium SSD v2 and Ultra Azure Managed Disks

We are excited to share the latest advancements in Premium SSD v2 (Pv2) and Ultra disks, the next generation of Azure disk stor...

1 year ago

Unlocking the Potential of Unstructured Data with Microsoft Copilot and Azure Native Qumulo

It has been a true pleasure to see our friends at Qumulo constantly innovating and delivering a service that adds more value with every releas...

2 years ago

Public Preview: Customer Managed Planned Failover for Azure Storage

We are excited to announce customer managed Planned Failover for Azure Storage is now available in public preview.   Over the past few ye...

2 years ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.