Skip to content

DataLake async file client cannot download using SAS tokens restricted to specific folders #23804

@simebg

Description

@simebg
  • Package Name: azure-storage-file-datalake
  • Package Version: 12.6.0
  • Operating System: Ubuntu 20.04
  • Python Version: 3.9.7

Describe the bug
SAS tokens for specific folders in a storage account don't work in the async client, however they do in the sync one.

SAS tokens generated on the whole container do work on both async and sync clients.

To Reproduce
Replace relevant variables in the following code, then execute it:

path = '...'
container = '...'
account_url = '...'

# sas token on specific folder (works on sync, doesn't work on async)
sas_token = '...'
# sas token on container (works on both sync and async)
# sas_token = '...'

def sync_run():
    print('Trying synchronous API...')

    from azure.storage.filedatalake import DataLakeFileClient

    with DataLakeFileClient(account_url, container, path, sas_token) as client:
        data = client.download_file().readall()
        print(f'Read {len(data)} bytes.')

def async_run():
    async def run():
        print('Trying asynchronous API...')

        from azure.storage.filedatalake.aio import DataLakeFileClient

        async with DataLakeFileClient(account_url, container, path, sas_token) as client:
            data = await (await client.download_file()).readall()
            print(f'Read {len(data)} bytes.')

    import asyncio
    asyncio.get_event_loop().run_until_complete(run())


if __name__ == '__main__':
    sync_run()
    async_run()

Expected behavior
Output should be something similar to:

$ python3 test.py 
Trying synchronous API...
Read 3060 bytes.
Trying asynchronous API...
Read 3060 bytes.

However, I get the following:

$ python3 test.py 
Trying synchronous API...
Read 3060 bytes.
Trying asynchronous API...
Traceback (most recent call last):
  File "/home/azure-async-test/test.py", line 64, in <module>
    async_run()
  File "/home/azure-async-test/test.py", line 59, in async_run
    asyncio.get_event_loop().run_until_complete(run())
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/azure-async-test/test.py", line 55, in run
    data = await (await client.download_file()).readall()
  File "/home/azure-async-test/.venv/lib/python3.9/site-packages/azure/storage/filedatalake/aio/_data_lake_file_client_async.py", line 481, in download_file
    downloader = await self._blob_client.download_blob(offset=offset, length=length, **kwargs)
  File "/home/azure-async-test/.venv/lib/python3.9/site-packages/azure/core/tracing/decorator_async.py", line 74, in wrapper_use_tracer
    return await func(*args, **kwargs)
  File "/home/azure-async-test/.venv/lib/python3.9/site-packages/azure/storage/blob/aio/_blob_client_async.py", line 480, in download_blob
    await downloader._setup()  # pylint: disable=protected-access
  File "/home/azure-async-test/.venv/lib/python3.9/site-packages/azure/storage/blob/aio/_download_async.py", line 250, in _setup
    self._response = await self._initial_request()
  File "/home/azure-async-test/.venv/lib/python3.9/site-packages/azure/storage/blob/aio/_download_async.py", line 336, in _initial_request
    process_storage_error(error)
  File "/home/azure-async-test/.venv/lib/python3.9/site-packages/azure/storage/blob/_shared/response_handlers.py", line 181, in process_storage_error
    exec("raise error from None")   # pylint: disable=exec-used # nosec
  File "<string>", line 1, in <module>
azure.core.exceptions.ClientAuthenticationError: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:46dbc42d-701e-0044-2024-48986f000000
Time:2022-04-04T13:04:00.5021799Z
ErrorCode:AuthenticationFailed
authenticationerrordetail:Invalid resource path
Content: <?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:46dbc42d-701e-0044-2024-48986f000000
Time:2022-04-04T13:04:00.5021799Z</Message><AuthenticationErrorDetail>Invalid resource path</AuthenticationErrorDetail></Error>

Additional context
The test script was run on a new venv, with azure-storage-file-datalake (12.6.0) and aiohttp (3.8.1) installed.

Metadata

Metadata

Labels

ClientThis issue points to a problem in the data-plane of the library.StorageStorage Service (Queues, Blobs, Files)customer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions