DEV Community

Agik Setiawan
Agik Setiawan

Posted on

3 2

Setup CORS and Policy in Object Storage like s3 or anoter Object Storage with s3cmd

In your ~/.s3cfg

[default]
access_key = ACCESS_KEY
host_base = ENDPOINT
host_bucket = YOUR_BUCKET_NAME.ENDPOINT
secret_key = SECRET_KEY
Enter fullscreen mode Exit fullscreen mode

or you can configure with command s3cmd --configure for new or reconfig default s3cmd

  • Set Policy create file policy.json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Statement1",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject",
                "s3:PutObject",
                "s3:DeleteObject",
                "s3:GetObjectVersion"
            ],
            "Resource": "arn:aws:s3:::BUCKET_NAME/*"
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

you can customize policy.json according to you needs.

open terminal

s3cmd setpolicy policy.json s3://BUCKET_NAME
Enter fullscreen mode Exit fullscreen mode
  • Set CORS create file cors.xml
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>DELETE</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>
Enter fullscreen mode Exit fullscreen mode

Open terminal

s3cmd setcors cors.xml s3://BUCKET_NAME
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay