You cannot scale a bucket per tenant forever. You run into account limits, naming collisions, and policy sprawl. Prefixes scale, but only if you back them with per tenant keys, strict IAM boundaries, and tests that prove a compromised tenant role cannot see or encrypt anything outside its lane. Here is what worked for us, what broke, and how we fixed it.
Layout: One Bucket, Many Prefixes, Optional Access Points
We use a single regional bucket, versioning on, object ownership bucket owner enforced, and ACLs disabled. Prefix scheme:
- tenant-id is a stable UUID or slug, not PII
- top level prefixes avoid collisions across services
Example layout:
- s3://myapp-data/tenant-123/inbox/
- s3://myapp-data/tenant-123/processed/
- s3://myapp-data/tenant-456/inbox/
Access strategy options we tried:
- Direct bucket policy plus IAM on roles. Fewer moving parts, good for hundreds to thousands of tenants.
- S3 Access Point per tenant. Clearer scoping and cleaner KMS controls via encryption context, but you will manage an extra resource per tenant.
We pick direct bucket access for small to mid scale, then move specific heavy tenants to per tenant Access Points when they need higher throughput controls or explicit KMS scoping.
Per Tenant Keys: Why, How, and Cost
Why unique KMS keys per tenant:
- Key level disable isolates quickly during incident response.
- Separate CloudTrail key logs for forensics.
- Cleaner permissions stories with Access Points and encryption context.
Cost and quota reality:
- Each customer managed symmetric key is about 1 USD per month.
- S3 SSE KMS requests add about 0.03 USD per 10,000 operations. Each PUT invokes GenerateDataKey, each GET invokes Decrypt.
- KMS request throughput is account scoped per Region. Watch 4xx from KMS and shard busy tenants to their own keys.
We let S3 call KMS on behalf of callers, and we constrain the key so it can only be used by S3 against the intended bucket or access point and prefix. You cannot add arbitrary tenant metadata to SSE KMS encryption context for S3, but you can match on aws:s3:arn.
Example KMS key policy for tenant abc with an access point:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnableRoot",
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::123456789012:root"},
"Action": "kms:*",
"Resource": "*"
},
{
"Sid": "AllowS3ViaAccessPointAndPrefix",
"Effect": "Allow",
"Principal": {"Service": "s3.amazonaws.com"},
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:SourceAccount": "123456789012",
"kms:EncryptionContext:aws:s3:arn": "arn:aws:s3:us-east-1:123456789012:accesspoint/tenant-abc-ap/object/tenant-abc/*"
},
"ArnLike": {
"aws:SourceArn": "arn:aws:s3:us-east-1:123456789012:accesspoint/tenant-abc-ap"
}
}
}
]
}
If you are not using Access Points, constrain to the bucket and prefix instead:
"StringLike": {
"kms:EncryptionContext:aws:s3:arn": "arn:aws:s3:::myapp-data/tenant-abc/*"
}
IAM: Session Tags, Permission Boundaries, and Policy Templates
We do not bake tenant IDs into static policies. We pass them as session tags when our identity broker calls sts:AssumeRole. The AssumeRole target has a permissions boundary so downstream inline or attached policies cannot grant more than intended.
- Session tag key: tenant:TenantId
- Optional tag key: tenant:KmsKeyArn
Trust policy for the tenant execution role:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::123456789012:role/identity-broker"},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {"sts:ExternalId": "myapp-prod"},
"ForAllValues:StringLike": {"sts:TagKeys": ["tenant:TenantId", "tenant:KmsKeyArn"]}
}
}
]
}
Permissions boundary applied to the tenant execution role:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowTenantS3PrefixOnly",
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": "arn:aws:s3:::myapp-data",
"Condition": {
"StringLike": {"s3:prefix": ["${aws:PrincipalTag/tenant:TenantId}/*"]}
}
},
{
"Sid": "AllowTenantObjectOpsWithKms",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject",
"s3:GetObjectTagging",
"s3:PutObjectTagging"
],
"Resource": "arn:aws:s3:::myapp-data/${aws:PrincipalTag/tenant:TenantId}/*",
"Condition": {
"StringEquals": {
"s3:x-amz-server-side-encryption": "aws:kms",
"s3:x-amz-server-side-encryption-aws-kms-key-id": "${aws:PrincipalTag/tenant:KmsKeyArn}"
}
}
},
{
"Sid": "DenyEverythingElse",
"Effect": "Deny",
"NotAction": ["s3:ListBucket", "s3:GetObject", "s3:PutObject", "s3:DeleteObject", "s3:GetObjectTagging", "s3:PutObjectTagging"],
"Resource": "*"
}
]
}
We keep the inline policy on the role minimal. The boundary enforces the ceiling, so accidental broader policies attached later are still contained. If your team wants a sanity check on this pattern before rollout, an outside architecture review for your AWS isolation model catches unsafe defaults that have crept in over time.
Access Points: Prefix Scope and Cleaner KMS Rules
When a tenant needs its own virtual endpoint, S3 Access Points reduce policy complexity.
Access Point policy template:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ListOnlyTenantPrefix",
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:us-east-1:123456789012:accesspoint/${aws:PrincipalTag/tenant:TenantId}-ap",
"Condition": {
"StringLike": {"s3:prefix": ["${aws:PrincipalTag/tenant:TenantId}/*"]}
}
},
{
"Sid": "TenantObjectOpsWithTagEnforcement",
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
"Resource": "arn:aws:s3:us-east-1:123456789012:accesspoint/${aws:PrincipalTag/tenant:TenantId}-ap/object/${aws:PrincipalTag/tenant:TenantId}/*",
"Condition": {
"StringEquals": {
"s3:x-amz-server-side-encryption": "aws:kms",
"s3:x-amz-server-side-encryption-aws-kms-key-id": "${aws:PrincipalTag/tenant:KmsKeyArn}"
}
}
},
{
"Sid": "RequireTenantTagOnWrite",
"Effect": "Deny",
"Principal": {"AWS": "*"},
"Action": ["s3:PutObject"],
"Resource": "arn:aws:s3:us-east-1:123456789012:accesspoint/${aws:PrincipalTag/tenant:TenantId}-ap/object/${aws:PrincipalTag/tenant:TenantId}/*",
"Condition": {
"StringNotEquals": {"s3:RequestObjectTag/TenantId": "${aws:PrincipalTag/tenant:TenantId}"}
}
}
]
}
With Access Points we bind each tenant KMS key policy to its matching access point arn and prefix as shown earlier. This prevents an app bug from accidentally writing the right prefix with the wrong key.
Bucket Policy Baseline: Encryption and Public Access
Even with IAM and Access Points, put guardrails at the bucket.
- Block Public Access at account and bucket.
- Require KMS encryption and the right key id.
- Optional, enforce TLS and SigV4.
Example baseline bucket policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyNonTLS",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": ["arn:aws:s3:::myapp-data", "arn:aws:s3:::myapp-data/*"],
"Condition": {"Bool": {"aws:SecureTransport": "false"}}
},
{
"Sid": "DenyIncorrectEncryption",
"Effect": "Deny",
"Principal": "*",
"Action": ["s3:PutObject"],
"Resource": "arn:aws:s3:::myapp-data/*",
"Condition": {
"StringNotEquals": {"s3:x-amz-server-side-encryption": "aws:kms"}
}
},
{
"Sid": "DenyWrongKey",
"Effect": "Deny",
"Principal": "*",
"Action": ["s3:PutObject"],
"Resource": "arn:aws:s3:::myapp-data/*",
"Condition": {
"StringNotEqualsIfExists": {
"s3:x-amz-server-side-encryption-aws-kms-key-id": [
"arn:aws:kms:us-east-1:123456789012:key/tenant-abc-key",
"arn:aws:kms:us-east-1:123456789012:key/tenant-def-key"
]
}
}
}
]
}
We generate this allow list automatically from our tenant registry in IaC. CDK or Terraform both work. If you prefer CDK, we wrote why in our notes on AWS CDK advantages for cloud workflows.
Proving Isolation: Blast Radius Tests You Can Run
Policy that is not tested will drift. We run these tests in CI against a staging account with realistic tenant data volumes.
Checks we always include:
- Cross tenant read and write attempts must fail with AccessDenied.
- Listing without the right prefix must return zero keys or AccessDenied.
- Using the wrong KMS key id must fail with AccessDenied or KMS InvalidCiphertext.
- Disabling a tenant key must halt new writes for that tenant and must not impact others.
Python script to exercise the controls. It assumes you can assume a tenant role with session tags.
import boto3
from botocore.exceptions import ClientError
ACCOUNT_ID = "123456789012"
ROLE_ARN = f"arn:aws:iam::{ACCOUNT_ID}:role/tenant-exec"
REGION = "us-east-1"
BUCKET = "myapp-data"
TENANT = "tenant-abc"
OTHER_TENANT = "tenant-def"
KMS_KEY_ARN = f"arn:aws:kms:{REGION}:{ACCOUNT_ID}:key/tenant-abc-key"
sts = boto3.client("sts")
assumed = sts.assume_role(
RoleArn=ROLE_ARN,
RoleSessionName=f"test-{TENANT}",
Tags=[
{"Key": "tenant:TenantId", "Value": TENANT},
{"Key": "tenant:KmsKeyArn", "Value": KMS_KEY_ARN},
],
ExternalId="myapp-prod",
)["Credentials"]
sess = boto3.Session(
aws_access_key_id=assumed["AccessKeyId"],
aws_secret_access_key=assumed["SecretAccessKey"],
aws_session_token=assumed["SessionToken"],
region_name=REGION,
)
s3 = sess.client("s3")
def must_fail(fn, desc):
try:
fn()
raise AssertionError(f"Expected AccessDenied for: {desc}")
except ClientError as e:
code = e.response.get("Error", {}).get("Code")
assert code in ("AccessDenied", "AccessDeniedException", "InvalidCiphertextException"), f"Unexpected error {code} for {desc}"
print(f"OK denied: {desc}")
# 1. Write in my prefix with the right KMS key
s3.put_object(
Bucket=BUCKET,
Key=f"{TENANT}/inbox/probe.txt",
Body=b"hello",
ServerSideEncryption="aws:kms",
SSEKMSKeyId=KMS_KEY_ARN,
Tagging=f"TenantId={TENANT}",
)
print("OK write in-tenant with KMS")
# 2. Read my object
s3.get_object(Bucket=BUCKET, Key=f"{TENANT}/inbox/probe.txt")
print("OK read in-tenant")
# 3. Cross-tenant read must fail
must_fail(lambda: s3.get_object(Bucket=BUCKET, Key=f"{OTHER_TENANT}/inbox/probe.txt"), "cross-tenant read")
# 4. Cross-tenant list must be filtered
resp = s3.list_objects_v2(Bucket=BUCKET, Prefix=f"{OTHER_TENANT}/")
assert resp.get("KeyCount", 0) == 0, "Should not list other tenant prefix"
print("OK list filtered")
# 5. Wrong key id must fail
must_fail(
lambda: s3.put_object(
Bucket=BUCKET,
Key=f"{TENANT}/inbox/wrong-key.txt",
Body=b"nope",
ServerSideEncryption="aws:kms",
SSEKMSKeyId=f"arn:aws:kms:{REGION}:{ACCOUNT_ID}:key/tenant-def-key",
Tagging=f"TenantId={TENANT}",
),
"put with wrong KMS key",
)
print("All isolation checks passed")
We also run a key disable drill. Disable tenant-abc key, confirm new PutObject fails for tenant-abc, then enable and retry. This is part of our chaos routines. If you want a structured way to exercise this with your team, we often run it alongside a short technical risk review workshop.
Operations: Auditing, Rotation, and Throughput Pitfalls
- Rotation. Turn on annual rotation for each tenant key. It is a flip of a flag and operationally safe because S3 stores the key id with each object.
- Auditing. Enable CloudTrail data events for S3 on your bucket and for KMS on customer managed keys. Log to a write only audit bucket. Feed Macie or Athena for detections.
- IAM Access Analyzer. Run it on the account to catch accidental public or cross account grants.
- Throughput. For hot tenants doing heavy GETs, consider their own access point and potentially separate KMS key. Watch KMS Throttling metrics. Spread heavy traffic across prefixes to parallelize S3 partitions.
- Replication. If you plan multi Region DR with S3 CRR, you need a multi Region key in each Region and replication rules that re encrypt on the destination. We described the RTO RPO tradeoffs in our guide on multi Region active passive versus active active.
What Broke And How We Fixed It
- We initially tried to use aws:PrincipalTag inside KMS key policy for SSE KMS with S3. It does not work because S3 is the principal calling KMS. Use encryption context tied to bucket or access point instead.
- We forgot to enforce object tags on PutObject. That made get by tag guards useless. Add a deny on missing or wrong s3:RequestObjectTag for writes.
- We allowed s3:ListBucket without a prefix condition. Tenants discovered they could enumerate prefixes. Lock ListBucket to s3:prefix for the caller.
- We shipped policies without a permissions boundary at first. Months later someone attached broader S3 access for a backfill job and created a near miss. Boundaries would have prevented it.
Where To Start And How To Roll Out Safely
- Codify the bucket, access points, keys, and IAM policies in IaC. Add unit tests that render JSON and snapshot them. If you want help hardening the defaults, our team runs focused security aware engineering engagements to get you to least privilege faster.
- Start with a greenfield staging account. Wire the identity broker to pass session tags. Run the blast radius tests on every PR that touches auth, storage, or IAM.
- Migrate tenants in slices. Create their keys first, then flip their writer to require the key id, then backfill re encryption if needed.
- Monitor 4xx from S3 and KMS. They are your early signals that a tenant rolled a bad config or an attacker is probing.
If you want to socialize the plan internally, pull in a second set of eyes from your platform team or outside. We can also help shape a realistic migration timeline and cost model via our cloud DevOps practice.
That is the core. One bucket, clear prefixes, per tenant keys, IAM boundaries with session tags, and tests that fail loudly. It keeps the blast radius small without turning your AWS account into a museum of buckets.



