0

I have a requirement where I have to move files from Edge node to ADLS. For this I am using the AZCOPY activity.

Here is my Code

export AZCOPY_AUTO_LOGIN_TYPE="SPN"
export AZCOPY_SPA_APPLICATION_ID="$client_id"
export AZCOPY_SPA_CLIENT_SECRET="$client_secret"
export AZCOPY_TENANT_ID="$tenant_id"

if [ $? -eq 0 ]; then   ////This always returns = 0. Though I pass correct or wrong credentials.
echo $?
echo "azure copy account login is successful"
else
echo "azure copy account login is failed"
exit
fi

I tried

az login --service-principal -u $clientid -p $client_secret --tenant myfyi.onmicrosoft.com

Note: I was given only Clientid, Client Secret, and Tenant id.

That doesn't work for me. Can someone help me here.

Reddy
  • 7
  • 2
  • What is not working? `az login` or `azcopy`? Also, the shell script you shared does nothing. It's just exporting something which would always give `exit 0`.. – harshavmb Mar 25 '22 at 07:12
  • @harshavmb I am trying to perform az login and post that azcopy activity. but thats not happening with this code alone "az login --service-principal -u $clientid -p $client_secret --tenant myfyi.onmicrosoft.com" This works only when I set up the ENV using export AZCOPY_AUTO_LOGIN_TYPE="SPN" export AZCOPY_SPA_APPLICATION_ID="$client_id" export AZCOPY_SPA_CLIENT_SECRET="$client_secret" export AZCOPY_TENANT_ID="$tenant_id" and followed by az login --service-principal -u $clientid -p $client_secret --tenant myfyi.onmicrosoft.com only then it works. – Reddy Mar 25 '22 at 14:27
  • Is there any other way by which we can achieve azlogin using the above credentials. I tried all the possible ways suggested by azure Microsoft docs but they endup saying OAuth issue. – Reddy Mar 25 '22 at 14:31

1 Answers1

0

Please make sure you have assigned the Contributor role to your user account before performing operation so as to be authorized to your Azure Storage account.

For az login try to create a service principal

az ad sp create-for-rbac --role xxx

Then you can log in with the service principal with

az login --service-principal

or try also to create certificate and then login as shown here azure cli - az login with certificate protected with password - Stack Overflow


If you set an environment variable by using the command line, that variable will be readable in your command line history

Reference :azcopy login | Microsoft Docs

Please check this way

Log in as a service principal by using a client secret: Set the environment variable AZCOPY_SPA_CLIENT_SECRET to the client secret for secret based service principal auth.

azcopy login --service-principal --application-id <your service principal's application ID>

or

azcopy login --service-principal --application-id "$APP_ID" --tenant-id "$TENANT_ID"

if [[ $? -gt 0 ]]
then
    echo "azure copy account login failed"
else 
    echo "azure copy account login is successful"
fi

0 exit status means the command was successful without any errors. A non-zero exit status means command was a failure.

References:

  1. azure - How to handle AZcopy failed file transfers - Stack Overflow
  2. How to Copy All Containers along with Blobs from one Azure storage account to other storage account - Stack Overflow
  3. Use data transfer tools in Azure Stack Hub Storage - Azure Stack Hub | Microsoft Docs
kavyaS
  • 8,026
  • 1
  • 7
  • 19