Search code examples
djangoamazon-s3aclpython-django-storages

django storages AWS S3 SigVer4: SignatureDoesNotMatch


My configuration (very basic):


        settings.py
        AWS_S3_REGION_NAME = 'eu-west-3'
        AWS_S3_FILE_OVERWRITE = False
        # S3_USE_SIGV4 = True # if used, nothing changes
        # AWS_S3_SIGNATURE_VERSION = "s3v4" # if used, nothing changes
        AWS_ACCESS_KEY_ID = "xxx"
        AWS_SECRET_ACCESS_KEY = "xxx"
        AWS_STORAGE_BUCKET_NAME = 'xxx'
        # AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'  # if used, no pre-signed urls
        AWS_DEFAULT_ACL = 'private'
        AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}
        AWS_LOCATION = 'xxx'
        DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
        
        INSTALLED_APPS = [
           ...,
           'storages'
        ]
        
        models.py
        class ProcessStep(models.Model):
            icon = models.FileField(upload_to="photos/process_icons/")

What I get:

  1. Pre-signed url is generated (both in icon.url and automatically on admin page)
  2. Pre-signed url response status code = 403 (Forbidden)
  3. If opened, SignatureDoesNotMatch error. With text: The request signature we calculated does not match the signature you provided. Check your key and signing method.

Tried:

  • changing access keys (both root and IAM)
  • changing bucket region
  • creating separate storage object for icon field (same error SignatureDoesNotMatch)
  • changing django-storages package version (currently using the latest 1.11.1)

Opinion:

  • boto3 client generate_presigned_url returns url with invalid signature

Questions:

  1. What should I do?
  2. Why do I get the error?

Solution

  • Patience is a virtue!

    One might wait for 1 day for everything to work