Let's say I'm building a Dropbox clone: Filebox. I'm storing all my user's files with S3 and I'm using Cloudfront as my CDN.
So I've got a restricted S3 bucket (files.filebox.com
) with a bucket policy that allows s3:GetObject
to only the Origin Access Identity I created via Cloudfront. This forces all 'file' requests to go through Cloudfront and disallows anyone to access a file via the S3 URLs.
The Bucket Policy for files.filebox.com
{
"Version": "2008-10-17",
"Id": "AllowCloudfrontGet",
"Statement": [
{
"Sid": "AllowCloudFrontGet",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity XXXXXXXXXXXX"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::files.filebox.com/*"
}
]
}
The Unexpected Behaviour
Let's say, for simplicity sake, I'm storing all files with a canned ACL of public-read
.
So this URL should work:
https://files.filebox.com/<userID>/some-file.txt
But this one should result in a 403:
https://s3.amazonaws.com/files.filebox.com/<userID>/some-file.txt
But I'm seeing the opposite results. The S3 URL works fine, but the files.filebox.com
URL, which is going through Cloudfront, is throwing a MissingKey
error.
The files.filebox.com
URL does work, but only if I sign the URL, even for objects that have an ACL of public-read
.
Questions
Given that the bucket policy only allows s3:GetObject
for the CF OAI, shouldn't the S3 URL fail with a 403, even if the object has a public-read
ACL?
I can't find any information on this in the documentation other than vague language that seems to indicate that a restricted bucket should 403 for any requests that don't come through via Cloudfront.
When I set the ACL of an object to public-read
does that not obviate the need to sign the Cloudfront URL, even on a restricted bucket?
Do I need to add another Statement
to my Bucket Policy that allows unsigned URL access to public-read
objects?
I attempted this, but it didn't work. I'm not sure how to write a Statement
like this even ...
How do I truly deny any requests that come through via the S3 URLs?
I'd like to throw a 403 for any requests that come through on S3 URLs, even for objects with an ACL of public-read
.