# IAM policy example: S3 bucket policy for TLS and org, with a least privilege rewrite

Facts read 16 Nov 2026. Page reviewed 16 Nov 2026.

A bucket policy that denies every request not sent over TLS and allows reads only to principals in one AWS Organization, identified by aws:PrincipalOrgID. The original allows reads to any principal, with TLS enforced. The rewrite adds the organization condition to the allow.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DenyInsecureTransport",
      "Effect": "Deny",
      "Principal": "*",
      "Action": "s3:*",
      "Resource": [
        "arn:aws:s3:::amzn-s3-demo-bucket",
        "arn:aws:s3:::amzn-s3-demo-bucket/*"
      ],
      "Condition": {
        "Bool": {
          "aws:SecureTransport": "false"
        }
      }
    },
    {
      "Sid": "PublicRead",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*"
    }
  ]
}
```

## What it allows

- The first statement denies every S3 action on the bucket and its objects for any request that is not sent over TLS.
- The second statement allows any principal to read any object.

- Denies 180 actions (s3:*) on arn:aws:s3:::amzn-s3-demo-bucket, arn:aws:s3:::amzn-s3-demo-bucket/* for AWS * when aws:SecureTransport Bool false.
- Allows 1 action (s3:GetObject) on arn:aws:s3:::amzn-s3-demo-bucket/* for AWS *.

Checks:
- No flags.

The allow with Principal * makes every object public, because the bucket policy trusts everyone.

## Least privilege rewrite

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DenyInsecureTransport",
      "Effect": "Deny",
      "Principal": "*",
      "Action": "s3:*",
      "Resource": [
        "arn:aws:s3:::amzn-s3-demo-bucket",
        "arn:aws:s3:::amzn-s3-demo-bucket/*"
      ],
      "Condition": {
        "Bool": {
          "aws:SecureTransport": "false"
        }
      }
    },
    {
      "Sid": "OrgRead",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*",
      "Condition": {
        "StringEquals": {
          "aws:PrincipalOrgID": "o-exampleorgid"
        }
      }
    }
  ]
}
```

The rewrite adds aws:PrincipalOrgID so only principals in organization o-exampleorgid can read. Anonymous and outside callers lose access.

- Denies 180 actions (s3:*) on arn:aws:s3:::amzn-s3-demo-bucket, arn:aws:s3:::amzn-s3-demo-bucket/* for AWS * when aws:SecureTransport Bool false.
- Allows 1 action (s3:GetObject) on arn:aws:s3:::amzn-s3-demo-bucket/* for AWS * when aws:PrincipalOrgID StringEquals o-exampleorgid.

Checks:
- No flags.

- [Paste it into the workbench](/)
- [Every S3 action and its access level](/actions/s3/)

## Related pages

- [IAM policy example: write a KMS key policy](/examples/kms-key-policy-account-admin-and-key-user/)
- [IAM policy example: let an SNS topic send to an SQS queue](/examples/sqs-queue-policy-allow-sns-topic/)
- [IAM policy example: let S3 invoke a Lambda function](/examples/lambda-resource-policy-allow-s3-invoke/)
- [All of them](/examples/)

## Sources

- Amazon S3 User Guide: bucket policy examples: https://docs.aws.amazon.com/AmazonS3/latest/userguide/example-bucket-policies.html (read 16 Nov 2026)
- Amazon S3 User Guide: security best practices: https://docs.aws.amazon.com/AmazonS3/latest/userguide/security-best-practices.html (read 16 Nov 2026)
- AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026): https://docs.aws.amazon.com/service-authorization/latest/reference/service-reference.html (read 16 Nov 2026)

Last reviewed 16 Nov 2026. Canonical: https://iampolicygenerator.com/examples/s3-bucket-policy-enforce-tls-and-organization/

This site is not affiliated with Amazon Web Services. AWS service and product names are used only to describe AWS services.
