I have a python script that runs daily and it needs to upload a file to Azure storage at a certain time every day.
I am trying to use the AzCopy commands to upload files to azure storage automatically. I plan to sign in AzCopy once and let it run and upload automatically for as long as it can.
I start with azcopy login --tenant-id=<my tenant id>
and authenticate azcopy manually by going to the browser and entering the code.
I want to know how long can I keep it logged in before I need to reauthenticate azcopy again?
PS. I am not planning to run the command azcopy logout
to log out manually
Not sure, but in such a case the better way is a non-interactive way e.g. use a service principal to login.
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>
Reference - https://learn.microsoft.com/en-us/azure/storage/common/storage-ref-azcopy-login#examples
Update:
The same as Azure CLI, after using azcopy login
, it will generate an accessToken.json
file in your local path ~/.azcopy/
(Azure CLI is ~/.azure/
), it includes the Auzre AD access token and refresh token, when the access token was expired, azcopy will use the refresh token to get a new access token and a new refresh token. It means if your refresh token does not expires, it can always get the new access token. By default, this refresh token is revoked after 90 days of inactivity, for the specific value, it depends on the specific token lifetime configuration in your AAD tenant.
So in conclusion, if you often use azcopy command before the refresh token expires, you can always keep logged in your account.