I\'m trying to get django to upload static files to S3, but istead I\'m getting a 403 forbidden error, and I\'m not sure why.
Full Stacktrace:
Here is a refinement with minimal permissions.
In all cases, as discussed elsewhere s3:ListAllMyBuckets
is necessary on all buckets.
In it's default configuration django-storages will upload files to S3 with public-read permissions - see django-storages Amazon S3 backend
Trial and error revealed that in this default configuration the only two permissions required are s3:PutObject
to upload a file in the first place and s3:PutObjectAcl
to set the permissions for that object to public.
No additional actions are required because from that point forward read is public on the object anyway.
IAM User Policy - public-read (default):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:ListAllMyBuckets",
"Resource": "arn:aws:s3:::*"
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": "arn:aws:s3:::bucketname/*"
}
]
}
It is not always desirable to have objects publicly readable. This is achieved by setting the relevant property in the settings file.
Django settings.py:
...
AWS_DEFAULT_ACL = "private"
...
And then the s3:PutObjectAcl
is no longer required and the minimal permissions are as follows:
IAM User Policy - private:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:ListAllMyBuckets",
"Resource": "arn:aws:s3:::*"
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject"
],
"Resource": "arn:aws:s3:::bucketname/*"
}
]
}