# Access control

How IAM policies, access key scopes, bucket policies and Block public access decide who may read and write a bucket.

Every request, through the console, the API or an S3 client, acts as an IAM user and is checked
against that user's IAM policies. Three more things can narrow or widen it: the key's scope, the
bucket policy and Block public access.

## IAM policies

Grant actions on bucket and object resources. Object storage is regionless, so the region segment
is empty:

| Resource                                         | Covers                                  |
| ------------------------------------------------ | --------------------------------------- |
| `rn:ews::<org>:s3:bucket/<name>`                 | the bucket itself                       |
| `rn:ews::<org>:s3:bucket/<name>/object/*`        | every object in the bucket              |
| `rn:ews::<org>:s3:bucket/<name>/object/public/*` | objects whose key starts with `public/` |

Read-only access to one prefix:

```json
{
  "Version": "2024-01-01",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:GetObject"],
      "Resource": "rn:ews::org-EXAMPLE1234:s3:bucket/example-uploads/object/public/*"
    }
  ]
}
```

The actions are listed in [Security](security.md).

## Key scope

An access key can carry a scope policy. The key then does only what both its IAM user and the scope
allow, through S3 and the API alike; a bucket policy does not widen it, and a Deny in the scope
always wins. See [Limit a key to one bucket](limit-a-key-to-one-bucket.md).

## Bucket policies

A bucket policy is a resource policy in AWS's grammar. It can make objects public (see
[Make objects public](make-objects-public.md)) or share them with another organization or user
(see [Share a bucket with another organization](share-a-bucket.md)).

| Field       | Accepted                                                                                                                                                             |
| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Principal` | `"*"` or `{"AWS": "*"}`: anyone, with or without a key; or `{"EWS": [...]}` naming organizations and users (up to 100). `*` and names do not mix                     |
| `Effect`    | `Allow`, `Deny`. A `Deny` applies to everyone its `Principal` covers, your own keys included                                                                         |
| `Action`    | S3 action names: `s3:GetObject`, `s3:PutObject`, `s3:DeleteObject`, `s3:*`, …; `s3:ListBucket` is read as `s3:ListObjects`                                           |
| `Resource`  | `arn:aws:s3:::<bucket>` or `arn:aws:s3:::<bucket>/<key pattern>`, or the `rn:ews:` form; only the policy's own bucket                                                |
| `Condition` | `IpAddress` / `NotIpAddress` on `aws:SourceIp`; the `Date…` operators on `aws:CurrentTime`; `Bool`, `StringEquals`, `StringNotEquals`, `StringLike`, `StringNotLike` |

A named principal is an organization id (or `arn:aws:iam::<org id>:root`) or an IAM user
(`rn:ews::<org>:iam:user/<id>`); `{"AWS": [...]}` is accepted for the same list. A name that does
not exist is refused with `Invalid principal in policy: …`.

`NotPrincipal`, `NotAction` and `NotResource` are refused. A policy is at most 20 KB.

How it combines with IAM:

- Users of your own organization are allowed when either their IAM policies or the bucket policy
  allows. A `Deny` in either always wins.
- A request from another organization is allowed only when both your bucket policy and the caller's
  own IAM policies allow it.
- Only your organization can change a bucket's configuration (policy, Block public access,
  website, CORS, replication, encryption, versioning, lifecycle); a bucket policy never grants
  that, even with `s3:*`: such a request answers `AccessDenied`.

## Block public access

| Flag                    | API field               | Effect                                                                               |
| ----------------------- | ----------------------- | ------------------------------------------------------------------------------------ |
| `BlockPublicPolicy`     | `blockPublicPolicy`     | A policy that would make the bucket public is refused                                |
| `RestrictPublicBuckets` | `restrictPublicBuckets` | The public statements of the policy are ignored for anyone outside your organization |
| `BlockPublicAcls`       | `blockPublicAcls`       | Stored for S3 tools. There are no ACLs; a public ACL on an upload is refused anyway  |
| `IgnorePublicAcls`      | `ignorePublicAcls`      | Stored for S3 tools                                                                  |

All four are on for every new bucket. The bucket is **public** when its policy grants the public
and Block public access does not stop it.

## Buckets the platform writes

A database's backup bucket (`rds-<database id>`) and a Kafka cluster's tiered-storage bucket can
be read and downloaded by your organization; writes are refused with `AccessDenied` "This bucket is managed by the platform and is read-only",
and its access settings cannot be changed.

## Related

- [Security](security.md)
- [Make objects public](make-objects-public.md)
- [IAM](/docs/iam)
