Vultr Object Storage subscription allows users to configure Cross-Origin Resource Sharing (CORS) policies to control which external origins can access resources within their buckets. By setting appropriate CORS rules, users can specify which domains are permitted to interact with their stored data, along with allowed HTTP methods and headers. This feature is essential for web applications that require secure access to assets from multiple domains while ensuring data protection. Configuring CORS policies helps manage resource access while maintaining security standards.
Follow this guide to apply CORS policies to Vultr Object Storage subscription buckets using s3cmd
and AWS CLI.
Deploy Vultr Object Storage subscription and create a bucket.
Configure s3cmd
with Vultr Object Storage subscription.
$ s3cmd --configure
Follow the prompts and provide bucket credentials like Access Key, Secret Key, Default Region and S3 Endpoint. You can retrieve these credentials from the Vultr Object Storage subscription Overview page.
Enter the DNS-style template. For example, if you choose the New Jersey location, use %(bucket)s.ewr1.vultrobjects.com
.
DNS-style bucket+hostname:port template for accessing a
bucket [%(bucket)s.s3.amazonaws.com]: %(bucket)s.ewr1.vultrobjects.com
Upload a file in the bucket.
$ s3cmd put /<local-file-location> s3://<your-bucket-name>/
Create a new xml
file, such as cors_rules.xml
to set up a CORS bucket policy.
$ nano cors_rules.xml
Copy the content below and paste it into the xml file.
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Save and close the file.
Apply the CORS policy.
$ s3cmd setcors cors_rules.xml s3:///<your-bucket-name>
Verify the CORS policy if needed.
$ s3cmd getcors s3://<your-bucket-name>
Configure AWS CLI with Vultr Object Storage subscription.
$ aws configure --profile my-config
Follow the prompts and provide bucket credentials like Access Key, Secret Key, and Default Region. These credentials can be retrieved from the overview page of the Vultr Object Storage subscription.
Upload a file in the bucket.
$ aws --endpoint-url https://<your-hostname> --profile my-config s3api put-object --bucket <your-bucket-name> --key <remote-filename> --body <local-file-location>
Create a new json
file to set up a CORS bucket policy.
$ nano cors_rules.json
Copy and paste the below content into the file.
[
{
"AllowedOrigins": ["*"],
"AllowedMethods": ["GET", "POST", "PUT"],
"AllowedHeaders": ["*"],
"MaxAgeSeconds": 3000
}
]
Save and close the file.
Set the policy for the bucket.
$ aws --endpoint-url https://<your-hostname> s3api put-bucket-cors --bucket <your-bucket-name> --cors-configuration file://cors_rules.json --profile my-config
Check the policy applied to the bucket if needed.
$ aws --endpoint-url https://<your-hostname> s3api get-bucket-cors --bucket <your-bucket-name> --profile my-config