Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S3 Hosting/Query String Authentication broken with extra parameters

I have a Django project setup with S3 as the static file host.

settings.py

AWS_STORAGE_BUCKET_NAME = 'project-1'
conn = boto.connect_s3()
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
S3_URL = 'http://project-1.s3.amazonaws.com/'
STATIC_URL = S3_URL

And then I make references to static files in my templates using the template tag, like so:

<script src="{% static 'js/jquery.payment.js' %}"></script>

This renders correctly inside the browser, but the URL has 3 other parameters on them, Signature, Expires, and AWSAccessKeyId. The latter two do not have any affect on the file, but accessing the file with the rendered Signature value results in an InvalidAccessKeyId error, with the message "The AWS Access Key Id you provided does not exist in our records."

Manually taking away the Signature parameter lets me access the file fine. Taking away all three parameters is fine. Taking away either of the latter two parameters results in an error: "Query-string authentication requires the Signature, Expires and AWSAccessKeyId parameters".

Amazon's S3 documentation reveals that query string authentication is used to allow you access to files that you would normally need authentication to, and that the Expires parameter is not, as I thought it was, related to caching. Since it appears that these files don't require any authentication (i.e. I can access them when no URL parameters are present), I need help either:

  1. making staticfiles/boto not force these parameters on my urls
  2. making staticfiles/boto obtain a valid Signature value
like image 609
Randall Ma Avatar asked Jan 12 '23 23:01

Randall Ma


1 Answers

Set AWS_QUERYSTRING_AUTH = False.

like image 195
Randall Ma Avatar answered Jan 16 '23 02:01

Randall Ma