python - S3ResponseError: 403 Forbidden using Boto -


i have permission problem on s3 bucket when try access files using boto in python. here bucket policy :

{     "version": "2008-10-17",     "id": "policy1407346649831",     "statement": [         {             "sid": "stmt1407346646598",             "effect": "allow",             "principal": {                 "aws": "arn:aws:iam::029030651757:user/my_iam_user"             },             "action": "s3:*",             "resource": ["arn:aws:s3:::my_bucket/*",                          "arn:aws:s3:::my_bucket"]         },         {             "sid": "2",             "effect": "allow",             "principal": {                 "aws": "arn:aws:iam::cloudfront:user/cloudfront origin access identity efus443hmbyf"             },             "action": "s3:getobject",             "resource": ["arn:aws:s3:::my_bucket/*",                          "arn:aws:s3:::my_bucket"]         },         {             "sid": "3",             "effect": "allow",             "principal": {                 "aws": "arn:aws:iam::cloudfront:user/cloudfront origin access identity efus443hmbyf"             },             "action": "s3:putobject",             "resource": "arn:aws:s3:::my_bucket/*"         }     ] } 

i have 3 statements. first 1 authorize user my_iam_user access bucket my_bucket, second 1 authorize cloudfront distribution read bucket , last 1 authorize cloudfront distribution write on bucket.

now have files on bucket profile_pictures/15/file1.jpg , profile_pictures/15/file2.jpg. first 1 created using signed url , cloudfront, second 1 put on s3 using boto. try access files using boto. here code:

import boto boto.s3.key import key  s3 = boto.connect_s3(     aws_access_key_id="access_key_of_my_iam_user",     aws_secret_access_key="secret_key_of_my_iam_user" ) bucket = s3.get_bucket("my_bucket", validate=false)  k1 = key(bucket) k1.key = "profile_pictures/15/file1.jpg" k1.get_contents_as_string()   k2 = key(bucket) k2.key = "profile_pictures/15/file2.jpg" k2.get_contents_as_string() 

the problem access file1 returns error:

s3responseerror: s3responseerror: 403 forbidden <?xml version="1.0" encoding="utf-8"?> <error><code>accessdenied</code><message>access denied</message><requestid>8c5de910c7b18f9e</requestid><hostid>xiku5q+b0wme3gpunmuod9kpun63t3bfu/rab/wh3rhdmkykorsdqifgyip8zfawmr1apbquefy=</hostid></error> 

whereas second 1 success. wrong?

note: time on client running code good.

even though iam user has been granted full access bucket first policy, still not automatically have access file1 because not owner of object (cloudfront is) , have not been granted explicit access object. also, presumably, iam user not owner of bucket.

if @ example 1 on page see identical situation , further explanation of of how object context used determine whether request granted or denied.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -