Question

How to set policy of space

I tried to use s3cmd to set policy of a space. The policy file is like:

{
    "Statement": [
        {
            "Sid": "Allow get requests referred by localhost",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::my-bucket/policy/*",
            "Condition": {
                "StringLike": {
                    "aws:Referer": [
                        "http://localhost:8080/*"

                    ]
                }
            }
        }
    ]
}

and then run

s3cmd setpolicy policy s3://my-bucket

The command run without error, but when get the info:

s3cmd info s3://my-bucket

It showed there is no policy on this space:

s3://my-bucket/ (bucket):
   Location:  sgp1
   Payer:     BucketOwner
   Expiration Rule: none
   Policy:    none
  ...

And I still can not access the private file at localhost.

Does space support setpolicy or I done something wrong?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Here is my bucket policy.json create from AWS S3 and It work with DO Spaces. Don’t forget to change to your bucketname and your domain.

{
    "Version": "2017-10-17",
    "Id": "http referer policy example",
    "Statement": [
        {
            "Sid": "Allow get requests originating from www.yourdomain.com and subdomain.yourdomain.com.",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::yourbucketname/*",
            "Condition": {
                "StringLike": {
                    "aws:Referer": [
                        "https://www.yourdomain.com/*",
                        "https://subdomain.yourdomain.com/*"
                    ]
                }
            }
        }
    ]
}

My DO spaces is in nyc3 region. Also I just try setpolicy with sgp1 region. It’s work. Here is the bucket info. Notice : It seem sgp1 region have some problem, the connection fail many times. Hope DO staff will check and solve this problem.

s3://mybucketname/ (bucket):
   Location:  sgp1
   Payer:     BucketOwner
   Expiration Rule: none
   Policy:    {
    "Version": "2017-10-17",
    "Id": "http referer policy example",
    "Statement": [
        {
            "Sid": "Allow get requests originating from www.mydomain.com and subdomain.mydomain.com.",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::mybucketname/*",
            "Condition": {
                "StringLike": {
                    "aws:Referer": [
                        "https://www.mydomain.com/*",
                        "https://subdomain.mydomain.com/*"
                    ]
                }
            }
        }
    ]
}
   CORS:      none
   ACL:       xxxxxx: FULL_CONTROL

This comment has been deleted

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    Become a contributor for community

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    DigitalOcean Documentation

    Full documentation for every DigitalOcean product.

    Resources for startups and SMBs

    The Wave has everything you need to know about building a business, from raising funding to marketing your product.

    Get our newsletter

    Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

    New accounts only. By submitting your email you agree to our Privacy Policy

    The developer cloud

    Scale up as you grow — whether you're running one virtual machine or ten thousand.

    Get started for free

    Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

    *This promotional offer applies to new accounts only.