jschneier / django-storages

https://django-storages.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.69k stars 846 forks source link

django-storages returns unsigned URL for S3 access #1038

Closed chan-bai closed 2 days ago

chan-bai commented 2 years ago

I have a Django application deployed in an EKS cluster as a Kubernetes pod. This pod has the right IAM attached to it using Kubernetes Service Account.

I am currently trying to store all the static files in a private S3 bucket using django-storages and boto3.

However, django-storages returns unsigned URL instead of the pre-signed URL. This results in the web pages rendering only the HTML code.

I have manually generated the pre-signed URL inside the Kubernetes pod by runningaws s3 presign s3://<URL to the S3 BUCKET>/staticfiles.json which returned the correct pre-signed URL.

These are my relevant settings

STATIC_ROOT = '/usr/src/app/static'
STATIC_URL = '<URL to the S3 BUCKET>'

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3ManifestStaticStorage'
AWS_STORAGE_BUCKET_NAME = '<S3 BUCKET NAME>'
AWS_S3_REGION_NAME = 'eu-west-2'

Versions:

django-storages==1.11.1
boto3==1.18.16
colinkingswood commented 3 days ago

A comment on the accepted answer here
https://stackoverflow.com/questions/64193171/how-to-generate-presigned-s3-urls-using-django-storages

suggests that you need

AWS_QUERYSTRING_AUTH = True

Though I am trying that with digital ocean spaces and it isn't working for me.

colinkingswood commented 1 day ago

Worth noting that it doesn't work wit a custom domain set. I only got it working after I removed that setting.