azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

"az storage blob copy start" fails even with "Storage Blob Data Contributor" role

Open thiruma0203 opened this issue 7 years ago • 7 comments

Describe the bug A clear and concise description of what the bug is.

"az storage blob copy start" fails even when "Storage Blob Data Contributor" role is assigned to both source and destination storage account. Error message is like

"az storage blob copy start: error: Storage account 'destaccount' not found."

To Reproduce Steps to reproduce the behavior.

  1. On Azure VM, assign managed ID (MSI).

  2. Connect to the VM with SSH, and install latest Azure CLI.

  3. Create source and destination storage account. Put any test file on source storage account.

  4. Assign "Storage Blob Data Contributor" role to both storage account, for managed ID of the VM.

  5. Execute Azure CLI comands like below;

    az login --identity

    az storage blob copy start --destination-blob targetfile --destination-container targetcontainer --account-name destaccount --source-account-name srcaccount --source-container srccontainer --source-blob targetfile --auth-mode login

Expected behavior A clear and concise description of what you expected to happen.

Inter-storage account blob copy should be done without an error, as managed ID has enough privilege for blob data path.

Environment summary Install Method (e.g. pip, interactive script, apt-get, Docker, MSI, edge build) / CLI version (az --version) / OS version / Shell Type (e.g. bash, cmd.exe, Bash on Windows)

azure-cli 2.0.61 storage 2.3.2 Python (Linux) 2.7.5 (default, Jul 13 2018, 13:06:57) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]

Additional context Add any other context about the problem here.

With --debug option, debug log shows "az storage blob copy start" is trying to list all accessible storage accounts.

urllib3.connectionpool : Starting new HTTPS connection (1): management.azure.com:443 urllib3.connectionpool : https://management.azure.com:443 "GET /subscriptions/xxxxxxxx/providers/Microsoft.Storage/storageAccounts?api-version=2018-07-01 HTTP/1.1" 200 722 msrest.http_logger : Response status: 200 msrest.http_logger : Response headers: msrest.http_logger : 'Cache-Control': 'no-cache' msrest.http_logger : 'Pragma': 'no-cache' msrest.http_logger : 'Content-Type': 'application/json; charset=utf-8' msrest.http_logger : 'Content-Encoding': 'gzip' msrest.http_logger : 'Expires': '-1' msrest.http_logger : 'Vary': 'Accept-Encoding' msrest.http_logger : 'x-ms-request-id': 'b2c25248-b1ee-4f75-ac2f-43fae460c2f0' msrest.http_logger : 'x-ms-correlation-request-id': 'b2c25248-b1ee-4f75-ac2f-43fae460c2f0' msrest.http_logger : 'x-ms-routing-request-id': 'WESTUS:20190405T072651Z:b2c25248-b1ee-4f75-ac2f-43fae460c2f0' msrest.http_logger : 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains' msrest.http_logger : 'X-Content-Type-Options': 'nosniff' msrest.http_logger : 'Date': 'Fri, 05 Apr 2019 07:26:51 GMT' msrest.http_logger : 'Content-Length': '722' msrest.http_logger : Response content:[]

As managed ID has no Reader role over storage account, no results are returned. However I doubt Reader role is really necessary for data copy scenario.

thiruma0203 avatar Apr 05 '19 07:04 thiruma0203

@thiruma0203 it looks like that your login doesn't have the 'destaccount'. Can you try 'az storage account list -g your-resource-group' to see if 'destaccount' shows or not? Or try 'az storage account show -n destaccount' to see if destaccount is found or not? I think 'destaccount' won't show up. That means your login doesn't include 'destaccount'. That is the root cause of this error.

limingu avatar Apr 05 '19 21:04 limingu

@limingu I do have 'destaccount' in my subscription. Downloading and uploading from/to the storage account works with below comands and on the same environment.

az login --identity az storage blob upload -n blobname -c blob -f filename --account-name destaccount --auth-mode login az storage blob download -n blobname -c blob -f filename --account-name destaccount --auth-mode login

As you have suspected, 'az storage account show -n destaccount' does not return any results, as MSI only has "Storage Blob Data Contributor" role. But uploading and downloading single file succeeds with above commands. I dont see why "az storage blob copy start" bother to try to get list of storage accounts.

thiruma0203 avatar Apr 07 '19 22:04 thiruma0203

I was stumbling upon the same issue today: the client is logging-in using service principles; upload, download to the blob container does work for example using the HTTP REST API, but when executing the az storage blob upload command in the CLI, I see the same error as described above. The client has "Storage Blob Data Contributor" privileges as mentioned above. What would be a work around BTW? What user privileges would allow me to mitigate the issue for now?

asindl avatar May 27 '19 14:05 asindl

When you use az login --identity and --auth-mode login, you have to give your vm access role for your storage accounts. Here the role you assigned is Storage Blob Data Contributor, which do not have the right to access storage accounts information. One way is you can give Contributor role, wait for a while, and above command will work.

Juliehzl avatar Aug 13 '19 01:08 Juliehzl

@thiruma0203 and @asindl what about your problem now?

Juliehzl avatar Aug 25 '19 15:08 Juliehzl

For what it's worth, I had a similar issue. Giving the account the Reader and Storage Account Key Operator Service roles solved it for me.

greggilbert avatar Sep 09 '19 02:09 greggilbert

dupe of #10656

Juliehzl avatar Oct 16 '19 08:10 Juliehzl