Configure access control on S3 storage with AWS CLI and S3cmd
What are ACLs?
ACLs, or Access Control Lists, are sets of rules that determine who has access to objects stored in Object Storage and what actions they are allowed to perform on those objects. Proper configuration of ACLs helps ensure the security of stored data.
Info
The storage owner is responsible for configuring ACLs. Use the AWS CLI or S3cmd documentation commands to manage ACLs for objects in Gcore Object Storage.
ACLs for objects can be configured for a variety of actions, such as:
AWS CLI | S3cmd | Description |
---|---|---|
—public-read | —acl-public | Making an object publicly accessible |
—private | —acl-private | Making an object private |
—grant-full-control | —acl-grant=full-control | Granting full control over the bucket |
—grant-read | —acl-grant=read | Allowing the listing of objects in the bucket |
—grant-read-acp | —acl-grant=read_acp | Allowing the reading of ACLs |
—grant-write | —acl-grant=write | Allowing recording, overwriting, and deleting of objects |
What are policies?
Policies are JSON files that provide a more detailed way to control access to objects and buckets. They allow you to specify which actions a specific user or all users are allowed or denied to perform.
The maximum request size in the policy is 20 KB.
Note : The storage owner is responsible for configuring policies. Use the AWS CLI documentation actions, conditions, and resource types to manage policies for objects in Gcore Object Storage.
Configure access via ACLs and policies
We’ve provided examples of ACLs and policies for some common tasks in managing Object Storage.
In all the commands and JSON files, you need to replace the following with your values:
- Replace sample.jpg with your object.
- Replace my_bucket with your bucket.
- Replace
<https://s-ed1.cloud.gcore.lu>
with your hostname.
Allow an object downloading by ACL
To allow all users to download an object, use the following command with the public ACL action —acl public-read (AWS CLI) or —acl public (S3cmd).
AWS CLI:
S3cmd:
Note : This will make the specified object in the bucket publicly available to everyone.
Allow listing of a bucket by ACL
To allow all users to list objects in a bucket, use the following command with the public ACL action —grant-read (AWS CLI) or —acl-grant=read (S3cmd).
AWS CLI:
S3cmd:
Note : This will allow users to list the objects in the bucket, but they won’t have permission to read or write them.
Allow an object downloading by policy
To allow all users to download an object:
1. Create a JSON file with the following policy:
2. Apply the access policy to the bucket with the following command.
AWS CLI:
S3cmd:
As a result, the object in the bucket will be publicly available.
Note : This policy allows you to directly access the files, but it doesn’t allow you to list the files in the bucket.
Deny access to a bucket (hide a directory) by policy
To deny all users access to the “s3:GetObject” operation on a specific directory in a bucket while still allowing access to the higher-level bucket:
1. Create a JSON file with the following policy:
Note : Replace arn:aws:s3:::my_bucket/secret/* with the path to the directory you want to hide and arn:aws:s3:::my_bucket/* with the path to the higher-level bucket.
2. Apply the policy to the bucket with the following command.
AWS CLI:
S3cmd:
Allow requests from a particular IP by policy
To allow requests to the storage bucket from a specified IP address:
1. Create a JSON file with the following policy:
Note : Replace 10.0.0.0/24 with your desired IP address.
2. Apply the policy to the bucket with the following command.
AWS CLI:
S3cmd:
Allow requests from a particular website by policy
To allow referrals to the storage bucket from specified websites:
1. Create a JSON file with the following policy:
Note : Replace <http://www.example.com/>
and <http://example.com/>
with your desired websites.
2. Apply the policy to the bucket with the following command.
AWS CLI:
S3cmd:
Grant a user access to a bucket by policy
To grant a user access to a bucket:
1. Create a JSON file with the following policy:
Note : Replace 1234-test with the actual name of your storage in your account, and arn:aws:s3:::my_bucket with the actual name of your bucket.
2. Apply the policy to the bucket with the following command.
AWS CLI:
S3cmd: