-
-
Notifications
You must be signed in to change notification settings - Fork 867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Azure - Authentication error when AZURE_CUSTOM_DOMAIN
set to Azure CDN
#1116
Comments
Opened an issue on Azure Python SDK repo here: Azure/azure-sdk-for-python#23163 |
I have the same issue. Once I update the Traceback (most recent call last):
File "/home/support/repos/pythonazurestocdn/mysite/manage.py", line 22, in <module>
main()
File "/home/support/repos/pythonazurestocdn/mysite/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/support/repos/pythonazurestocdn/.venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 425, in execute_from_command_line
utility.execute()
File "/home/support/repos/pythonazurestocdn/.venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/support/repos/pythonazurestocdn/.venv/lib/python3.9/site-packages/django/core/management/base.py", line 373, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/support/repos/pythonazurestocdn/.venv/lib/python3.9/site-packages/django/core/management/base.py", line 417, in execute
output = self.handle(*args, **options)
File "/home/support/repos/pythonazurestocdn/.venv/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle
collected = self.collect()
File "/home/support/repos/pythonazurestocdn/.venv/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
handler(path, prefixed_path, storage)
File "/home/support/repos/pythonazurestocdn/.venv/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 334, in copy_file
if not self.delete_file(path, prefixed_path, source_storage):
File "/home/support/repos/pythonazurestocdn/.venv/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 248, in delete_file
if self.storage.exists(prefixed_path):
File "/home/support/repos/pythonazurestocdn/.venv/lib/python3.9/site-packages/storages/backends/azure_storage.py", line 241, in exists
blob_client.get_blob_properties()
File "/home/support/repos/pythonazurestocdn/.venv/lib/python3.9/site-packages/azure/core/tracing/decorator.py", line 83, in wrapper_use_tracer
return func(*args, **kwargs)
File "/home/support/repos/pythonazurestocdn/.venv/lib/python3.9/site-packages/azure/storage/blob/_blob_client.py", line 1242, in get_blob_properties
process_storage_error(error)
File "/home/support/repos/pythonazurestocdn/.venv/lib/python3.9/site-packages/azure/storage/blob/_shared/response_handlers.py", line 177, in process_storage_error
exec("raise error from None") # pylint: disable=exec-used # nosec
File "<string>", line 1, in <module>
azure.core.exceptions.ClientAuthenticationError: Operation returned an invalid status 'Forbidden'
ErrorCode:AuthenticationFailed |
The upstream issue response seems to indicate this is no longer a problem? |
It's still happening. We are experiencing the same issue with CDNs and django-storages 1.12.3 |
if there's a standalone repro that doesn't involve django-storages, then this is the wrong place to track the problem. Suggest taking it back upstream. |
The BlobServiceClient uses the custom domain URL, if AZURE_CUSTOM_DOMAIN is set. This obviously won't work for uploading files. See:
IMHO, saving files should use the storage account URL (ending in *.blob.core.windows.net), while the custom domain should only be used if set and return the URL from that custom domain. Simply put, one cannot write to an Azure CDN endpoint. I may be wrong though... |
I think that the documentation is misleading. I use an Azure CDN that uses a storage account as endpoint. After I have read the documentation of the Azure backend I thought I could set the AZURE_CUSTOM_DOMAIN setting to the hostname of the CDN endpoint (e.g. |
I agree with @tarak, docs say AZURE_CUSTOM_DOMAIN can be mycdn.azureedge.net. It would also make sense for the AZURE_CONNECTION_STRING setting to not override the AZURE_CUSTOM_DOMAIN. Files should be uploaded with the AZURE_CONNECTION_STRING settings and return the AZURE_CUSTOM_DOMAIN url. Another option would be to add an AZURE_CDN setting that accomplishes the above. Most people are using Azure CDN and Azure Storage in concert. |
Having the same issue as described here, setting |
Is everyone who has this issue using Akamai CDNs? Regarding the auth error I was having, I discovered the root issue to be with how Akamai CDN handles the While I think Azure SDKs are supposed to work with custom domains and CDNs (see Azure/azure-sdk-for-python#25536), there are multiple issues affecting different Azure CDN types which make using CDN endpoints quite unreliable at the moment. django-storages v1.11 (old Azure SDK) uses the storage account URL for API calls, bypassing the custom domain. I think it makes sense to restore that behaviour and have the custom domain only be used for getting the blob URL. This is how the old Azure and S3 backends work. Issues identified when connecting using CDN endpoint instead of storage URLMicrosoft CDN
Akamai CDN
|
I am using Microsoft CDN + Azure Storage Account. |
Did you report the problem that opens this thread to the Azure SDK repository? Since that repro didn't involve django-storages at all, it's clear that any fix would need to be upstream. Of course it might make sense to implement some workaround while waiting for upstream to sort this. But this is not the only codebase that uses blob storage - it's better for the world if this can be fixed at root! |
The issue is that when STATICFILES_STORAGE is defined, it is using AZURE_CUSTOM_DOMAIN to connect. |
I created a PR #1176 to revert back to the old behaviour so that |
@jschneier , when will we get a new PyPi release with this change rolled in? Thank you for the great library! |
For anyone following or looking at this thread, the fix is in the published 1.13.2 version. Thank you! |
Ever since the Azure backend was updated to the new
azure-storage-blob
library inv1.12
, using django-storages withAZURE_CUSTOM_DOMAIN
set results in Authentication errors when uploading files. For me this only happens with Akamai CDNs, but as reported by others below it affects other CDN types as well.v1.12
changed howAZURE_CUSTOM_DOMAIN
is used with BlobServiceClient. Inv1.11
and earlier, the custom domain was only used to get blob URLs. All other operations like uploading, streaming, getting metadata were being done by making requests to the actual storage account endpoint (https://<accountname>.blob.core.windows.net
) even if a custom domain was specified.In
v1.12
, the behaviour changed so that the custom domain endpoint is used for all storage operations. This uncovered several different upstream issues causing various storage requests to fail with auth errors.Issues
1. Auth error due to MAC signature mismatch when
AZURE_CUSTOM_DOMAIN
set to Akamai CDNUpstream issue: Azure/azure-sdk-for-python#26381
Uploads fail with the following error:
2. Forbidden ClientAuthenticationError when
AZURE_CUSTOM_DOMAIN
set to Microsoft CDNUpstream issue: Azure/azure-sdk-for-python#23640
Uploads fail with the following error (different than above):
The text was updated successfully, but these errors were encountered: