Docs

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

PUT /{bucket}?policy

JSON policy, Content-MD5 required

GetBucketPolicy

GET /{bucket}?policy

Read the policy

DeleteBucketPolicy

DELETE /{bucket}?policy

Remove the policy

GetBucketAcl

GET /{bucket}?acl

Read the bucket ACL

PutBucketAcl

PUT /{bucket}?acl

Replaces the ACL completely

GetObjectAcl

GET /{bucket}/{key}?acl

Optional versionId

PutObjectAcl

PUT /{bucket}/{key}?acl

Optional versionId

PutBucketCors

PUT /{bucket}?cors

XML rules, Content-MD5 required

GetBucketCors

GET /{bucket}?cors

Read the rules

DeleteBucketCors

DELETE /{bucket}?cors

Remove the rules

OPTIONS (preflight)

OPTIONS /{bucket}/{key}

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.com

Test 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.com

If 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.com

ACLs

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

private (default)

yes

yes

public-read

yes

yes

public-read-write

yes

yes

authenticated-read

yes

yes

bucket-owner-read

no

yes

bucket-owner-full-control

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.com

GetBucketAcl 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-acl header
  • individual grants in the headers x-amz-grant-read, x-amz-grant-write, x-amz-grant-read-acp, x-amz-grant-write-acp and x-amz-grant-full-control
  • an AccessControlPolicy document 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.com

CORS

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

AllowedOrigin

Allowed origin, at most one * per value

AllowedMethod

GET, PUT, HEAD, POST or DELETE

AllowedHeader

Headers the browser may send, at most one * per value

ExposeHeader

Response headers the script may read

MaxAgeSeconds

How long the browser caches the preflight response

ID

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.com

GetBucketCors 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.com

Without 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-type
  • Origin and Access-Control-Request-Method are required.
  • If a rule matches, the response contains Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers, Access-Control-Expose-Headers and Access-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