Access: policies, ACLs, CORS
You control access to chili on two levels. IAM users, groups and their policies are managed in the chili Console under IAM & object access. Through the S3 API you can also set rules directly on the bucket: bucket policies, ACLs and CORS. All examples use path style and the endpoint https://s3-ch-east.chilistorage.com.
For most cases the access levels in the Console are enough. You need bucket policies when a bucket should have a fixed rule regardless of individual users, for example a ban on deleting a certain path.
Operations
Operation | Method and path | Notes |
|---|---|---|
PutBucketPolicy |
| JSON policy, |
GetBucketPolicy |
| Read the policy |
DeleteBucketPolicy |
| Remove the policy |
GetBucketAcl |
| Read the bucket ACL |
PutBucketAcl |
| Replaces the ACL completely |
GetObjectAcl |
| Optional |
PutObjectAcl |
| Optional |
PutBucketCors |
| XML rules, |
GetBucketCors |
| Read the rules |
DeleteBucketCors |
| Remove the rules |
OPTIONS (preflight) |
| Browser CORS pre-check |
Bucket policies and IAM policies
Both use the AWS IAM JSON syntax with the elements Version, Statement, Sid, Effect, Principal, Action, Resource and Condition. Resources use the format arn:aws:s3:::bucket and arn:aws:s3:::bucket/path/*.
- IAM policies are attached to users or groups. You manage them in the Console. chili does not offer an IAM API.
- Bucket policies are attached to the bucket and apply to all requests to that bucket.
An explicit Deny always wins, whether it is in an IAM policy or in the bucket policy. This makes bucket policies a good fit for restrictions that even a user with broad permissions should not get around.
PutBucketPolicy
Sets or replaces the policy of a bucket.
PUT /my-bucket?policy HTTP/1.1
Host: s3-ch-east.chilistorage.com
Content-MD5: <Base64 MD5 of the body>Example: nobody may delete objects under archive/. Other paths are not affected.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "KeepArchive",
"Effect": "Deny",
"Principal": "*",
"Action": ["s3:DeleteObject", "s3:DeleteObjectVersion"],
"Resource": "arn:aws:s3:::my-bucket/archive/*"
}
]
}aws s3api put-bucket-policy \
--bucket my-bucket \
--policy file://policy.json \
--endpoint-url https://s3-ch-east.chilistorage.comTest a new policy first with a key that is not your only administrative access. A Deny rule that is too broad can lock you out; remove it with DeleteBucketPolicy.
GetBucketPolicy
Returns the current policy as JSON.
aws s3api get-bucket-policy \
--bucket my-bucket \
--endpoint-url https://s3-ch-east.chilistorage.comIf the bucket has no policy, chili responds with NoSuchBucketPolicy.
DeleteBucketPolicy
Removes the policy. Only the IAM policies from the Console apply afterwards.
aws s3api delete-bucket-policy \
--bucket my-bucket \
--endpoint-url https://s3-ch-east.chilistorage.comACLs
ACLs are the older S3 permission model. chili supports them for compatibility with existing applications. For new projects we recommend IAM policies in the Console and, where needed, bucket policies. They are easier to review and can be limited to paths.
Canned ACL | Bucket | Object |
|---|---|---|
| yes | yes |
| yes | yes |
| yes | yes |
| yes | yes |
| no | yes |
| no | yes |
We advise against public-read and public-read-write. To share single files, pre-signed URLs are a better fit, see Authentication.
GetBucketAcl and GetObjectAcl
GET /my-bucket?acl HTTP/1.1
GET /my-bucket/report.pdf?acl&versionId=<VERSION_ID> HTTP/1.1<AccessControlPolicy>
<Owner>
<ID>OWNER_ID</ID>
<DisplayName>OWNER_NAME</DisplayName>
</Owner>
<AccessControlList>
<Grant>
<Grantee>
<ID>OWNER_ID</ID>
</Grantee>
<Permission>FULL_CONTROL</Permission>
</Grant>
</AccessControlList>
</AccessControlPolicy>aws s3api get-object-acl \
--bucket my-bucket --key report.pdf \
--endpoint-url https://s3-ch-east.chilistorage.comGetBucketAcl requires the READ_ACP permission or bucket ownership.
PutBucketAcl and PutObjectAcl
The ACL is replaced completely. There are three ways to set it:
- a canned ACL in the
x-amz-aclheader - individual grants in the headers
x-amz-grant-read,x-amz-grant-write,x-amz-grant-read-acp,x-amz-grant-write-acpandx-amz-grant-full-control - an
AccessControlPolicydocument in the body
If the request has a body, chili ignores the ACL headers. If you use grant headers, a canned ACL sent at the same time is ignored.
aws s3api put-object-acl \
--bucket my-bucket --key report.pdf \
--acl private \
--endpoint-url https://s3-ch-east.chilistorage.comCORS
CORS rules allow web applications in the browser to access a bucket directly, for example for uploads from a single-page app. Without a matching rule the browser blocks such requests.
PutBucketCors
PUT /my-bucket?cors HTTP/1.1
Host: s3-ch-east.chilistorage.com
Content-MD5: <Base64 MD5 of the body>Element | Meaning |
|---|---|
| Allowed origin, at most one |
|
|
| Headers the browser may send, at most one |
| Response headers the script may read |
| How long the browser caches the preflight response |
| Rule name, at most 255 characters |
Each rule needs at least one origin and one method.
<CORSConfiguration>
<CORSRule>
<ID>web-upload</ID>
<AllowedOrigin>https://app.example.ch</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
<ExposeHeader>ETag</ExposeHeader>
<MaxAgeSeconds>3000</MaxAgeSeconds>
</CORSRule>
</CORSConfiguration>aws s3api put-bucket-cors \
--bucket my-bucket \
--cors-configuration '{"CORSRules":[{"ID":"web-upload","AllowedOrigins":["https://app.example.ch"],"AllowedMethods":["GET","PUT"],"AllowedHeaders":["*"],"ExposeHeaders":["ETag"],"MaxAgeSeconds":3000}]}' \
--endpoint-url https://s3-ch-east.chilistorage.comGetBucketCors and DeleteBucketCors
aws s3api get-bucket-cors --bucket my-bucket \
--endpoint-url https://s3-ch-east.chilistorage.com
aws s3api delete-bucket-cors --bucket my-bucket \
--endpoint-url https://s3-ch-east.chilistorage.comWithout a CORS configuration, GetBucketCors responds with NoSuchCORSConfiguration.
OPTIONS preflight
Before many cross-origin requests the browser sends an OPTIONS request. chili compares it with the bucket's CORS rules.
OPTIONS /my-bucket/upload.bin HTTP/1.1
Host: s3-ch-east.chilistorage.com
Origin: https://app.example.ch
Access-Control-Request-Method: PUT
Access-Control-Request-Headers: content-typeOriginandAccess-Control-Request-Methodare required.- If a rule matches, the response contains
Access-Control-Allow-Origin,Access-Control-Allow-Methods,Access-Control-Allow-Headers,Access-Control-Expose-HeadersandAccess-Control-Max-Age. - If no rule matches, these headers are missing and the browser blocks the actual request.
- The preflight request is not signed. The actual request still needs a valid signature or a pre-signed URL.
Next
- Authentication: Signature V4 and pre-signed URLs
- chili Console: IAM users, groups and access levels
- Object Lock (API):
s3:BypassGovernanceRetention - Error codes:
AccessDenied,NoSuchBucketPolicy