Ravindra BagaleCourses & study guides मराठी Track your progress

Ravi Sir's Cards › AWS › S3 VPC endpoint and source IP

AWS Cloud

Amazon S3 bucket policies: VPC endpoints and office source IP

This page keeps the next S3 bucket-policy cards on one topic page, after the public website and CloudFront OAC page. It has the eight cards from “S3 bucket policy project 3: restrict access to a VPC endpoint” and the eight cards from “S3 bucket policy project 4: restrict by office source IP”. Those packs are about where a request may come from. Later projects (HTTPS, SSE-KMS, cross-account logs, and so on) can be their own topic pages later.

Each card still has its image and its original text. Under each group you will also find a short Why, What, How example, and an exam tip, in easy English. The names, bucket names, CIDRs and endpoint ids in the stories are made up for learning.

Restrict access to a VPC endpoint

Why this matters

Private data should not leave the VPC path to the public S3 endpoint. If an ETL job in a private subnet can still reach S3 through NAT, the traffic is no longer only on the VPC endpoint you planned.

What it is

A common bucket policy pattern is to Deny s3:* unless aws:SourceVpce matches your endpoint id. Align the bucket policy with the endpoint policy, and put routes to the S3 prefix list in the subnet route tables. For most private S3 access, a gateway endpoint is the default (prefix-list routes, no ENI charge pattern). An interface endpoint uses ENIs and security groups, with more control and more cost, and is for special DNS or security-group needs. A public path through NAT will be denied by a SourceVpce fence — that is the point of the deny test.

How it works — a real example

Suppose Lucas Meyer’s ETL in private subnets must read a bucket only via vpce-…. He creates a gateway endpoint, associates the routes, and puts a Deny-unless SourceVpce policy on the bucket. From a bastion in the VPC the read is allowed. From a laptop on the internet it is denied. Ananya Iyer debugs a miss by checking the route table association first, not only the JSON. The names and endpoint id are made up for learning.

Common mistake / exam tip

Bucket policy alone is not the whole story — endpoint policies apply too. Confirm there is no NAT leak when you test the deny. Use a gateway endpoint for ordinary private S3 access unless you have a clear reason for an interface endpoint.

Restrict to VPC endpoint

Revision card: Restrict to VPC endpoint. Private data should not leave the VPC path to the public S3 endpoint. Deny s3:* unless aws:SourceVpce matches your gateway/interface endpoint id. Create endpoint → routes → bucket Deny-unless → test in-VPC allow / internet deny. Lucas Meyer ETL in private subnets reads S3 only via vpce-….
Card 1 of 16: Restrict to VPC endpoint · Download PNG
Read card text

What this card says

Why do we need it?

Private data should not leave the VPC path to the public S3 endpoint.

What is it?

Deny s3:* unless aws:SourceVpce matches your gateway/interface endpoint id. SourceVpce

How to do it

Create endpoint → routes → bucket Deny-unless → test in-VPC allow / internet deny.

Example

Lucas Meyer ETL in private subnets reads S3 only via vpce-….

Endpoint policy layers

Revision card: Endpoint policy layers. Bucket policy alone is not the whole story — endpoint policies apply too. Align both; fix routes to the S3 prefix list; confirm no NAT leak for the deny test. From bastion in VPC: allow. From laptop: deny. Ananya Iyer debugs missing route table association first.
Card 2 of 16: Endpoint policy layers · Download PNG
Read card text

What this card says

Why do we need it?

Bucket policy alone is not the whole story — endpoint policies apply too.

What is it?

Align both; fix routes to the S3 prefix list; confirm no NAT leak for the deny test. prefix list

How to do it

From bastion in VPC: allow. From laptop: deny.

Example

Ananya Iyer debugs missing route table association first.

Comparison: Private or public path?

Comparison: VPC endpoint path vs Public S3 endpoint via NAT. VPC endpoint path: aws:SourceVpce fence; no public egress needed for S3. Public S3 endpoint via NAT: Traffic exits NAT to public S3; SourceVpce Deny bites.
Card 3 of 16: Comparison: Private or public path? · Download PNG
Read card text

What this card says

VPC endpoint path

aws:SourceVpce fence; no public egress needed for S3.

Public S3 endpoint via NAT

Traffic exits NAT to public S3; SourceVpce Deny bites.

Key points

Private-subnet ETL. Ad-hoc laptop uploads.

Example

CreateVpcEndpoint + Deny-unless / NAT Gateway → s3.amazonaws.com

Use when

Sensitive private data planes. Admin laptops (usually denied by this policy).

Comparison: Gateway or interface?

Comparison: S3 gateway endpoint vs S3 interface endpoint. S3 gateway endpoint: Prefix-list routes; no ENI charge pattern. S3 interface endpoint: ENIs + security groups; more control/cost.
Card 4 of 16: Comparison: Gateway or interface? · Download PNG
Read card text

What this card says

S3 gateway endpoint

Prefix-list routes; no ENI charge pattern.

S3 interface endpoint

ENIs + security groups; more control/cost.

Key points

Most private S3 access. Special DNS/SG needs.

Example

CreateVpcEndpoint Gateway / CreateVpcEndpoint Interface

Use when

Default private S3. Advanced cases.

Interview: SourceVpce vs SourceVpc?

Interview card: SourceVpce vs SourceVpc?. SourceVpce is the endpoint id; SourceVpc is the VPC id — different keys. Most S3 gateway designs use SourceVpce. vpce-0abc in StringEquals/NotEquals.
Card 5 of 16: Interview: SourceVpce vs SourceVpc? · Download PNG
Read card text

What this card says

What it is

SourceVpce is the endpoint id; SourceVpc is the VPC id — different keys. SourceVpce

Why it matters

Most S3 gateway designs use SourceVpce.

How / example

vpce-0abc in StringEquals/NotEquals.

Interview: Why allow-in-VPC still fails?

Interview card: Why allow-in-VPC still fails?. Missing route to the S3 gateway prefix list sends traffic to public path → Deny. Also check endpoint policy conflicts. Associate endpoint with private RT fixes it.
Card 6 of 16: Interview: Why allow-in-VPC still fails? · Download PNG
Read card text

What this card says

What it is

Missing route to the S3 gateway prefix list sends traffic to public path → Deny. route table

Why it matters

Also check endpoint policy conflicts.

How / example

Associate endpoint with private RT fixes it.

Interview: Why Deny-unless pattern?

Interview card: Why Deny-unless pattern?. Explicit Deny when SourceVpce ≠ yours blocks other Allows. List both bucket and object ARNs on the Deny Resource. Laptop aws s3 ls → AccessDenied.
Card 7 of 16: Interview: Why Deny-unless pattern? · Download PNG
Read card text

What this card says

What it is

Explicit Deny when SourceVpce ≠ yours blocks other Allows. Deny

Why it matters

List both bucket and object ARNs on the Deny Resource.

How / example

Laptop aws s3 ls → AccessDenied.

Interview: Gateway or interface for S3?

Interview card: Gateway or interface for S3?. Gateway endpoints are the common free private path for S3; interface is optional/advanced. Interface uses ENIs and security groups. Lab uses gateway endpoint + SourceVpce.
Card 8 of 16: Interview: Gateway or interface for S3? · Download PNG
Read card text

What this card says

What it is

Gateway endpoints are the common free private path for S3; interface is optional/advanced. gateway endpoint

Why it matters

Interface uses ENIs and security groups.

How / example

Lab uses gateway endpoint + SourceVpce.

Restrict by office source IP

Why this matters

Finance exports should not download from coffee-shop Wi-Fi. A stolen access key used off-network should fail if you also fence the source IP.

What it is

A common pattern is to Deny s3:* unless aws:SourceIp is in the office or NAT CIDRs, with IpAddress or NotIpAddress operators (not a casual StringEquals on a CIDR). S3 sees the public egress address after NAT, not the private 10.x address, so you allowlist the NAT or firewall egress /32 or ranges, and you update the policy when the ISP changes. VPN users must egress via an IP that is on the list, or they are denied. You can combine this with a TLS Deny (aws:SecureTransport) for defense in depth. A SourceIp fence is about where the caller is; identity-only IAM is about who the caller is. Break-glass admins may need access from anywhere with MFA, which is a different pattern.

How it works — a real example

Suppose Arjun Mehta allows only 203.0.113.0/24 to a statements bucket. Office desktops work. A phone hotspot is denied. Rahul Deshmukh later updates the policy after the office ISP renumbers the NAT. A home VPN whose egress IP is not in the list also gets AccessDenied. The names and CIDRs are made up for learning.

Common mistake / exam tip

Do not allowlist private RFC1918 addresses for S3 SourceIp — S3 never sees 10.x after NAT. Document split-tunnel VPN surprises. Test with curl from the office and from a hotspot. Keep a written break-glass path if you must reach the bucket from outside the office CIDR.

Office SourceIp fence

Revision card: Office SourceIp fence. Finance exports should not download from coffee-shop Wi‑Fi. Deny s3:* unless aws:SourceIp is in office/NAT CIDRs; prefer NotIpAddress Deny pattern. Collect CIDRs → policy → allow from office → deny from home → document break-glass. Arjun Mehta UPI ops allow only 203.0.113.0/24 to the statements bucket.
Card 9 of 16: Office SourceIp fence · Download PNG
Read card text

What this card says

Why do we need it?

Finance exports should not download from coffee-shop Wi‑Fi.

What is it?

Deny s3:* unless aws:SourceIp is in office/NAT CIDRs; prefer NotIpAddress Deny pattern. SourceIp

How to do it

Collect CIDRs → policy → allow from office → deny from home → document break-glass.

Example

Arjun Mehta UPI ops allow only 203.0.113.0/24 to the statements bucket.

NAT egress and CIDRs

Revision card: NAT egress and CIDRs. S3 sees the public egress IP, not the private 10.x address. Allowlist NAT/firewall egress /32 or ranges; update when ISP changes. Test with curl from office vs phone hotspot. Rahul Deshmukh updates policy after office ISP renumbers.
Card 10 of 16: NAT egress and CIDRs · Download PNG
Read card text

What this card says

Why do we need it?

S3 sees the public egress IP, not the private 10.x address. NAT

What is it?

Allowlist NAT/firewall egress /32 or ranges; update when ISP changes.

How to do it

Test with curl from office vs phone hotspot.

Example

Rahul Deshmukh updates policy after office ISP renumbers.

Comparison: Office CIDR or VPN?

Comparison: Office SourceIp allowlist vs VPN-only access. Office SourceIp allowlist: aws:SourceIp matches office/NAT egress. VPN-only access: Users must egress via corporate VPN IP.
Card 11 of 16: Comparison: Office CIDR or VPN? · Download PNG
Read card text

What this card says

Office SourceIp allowlist

aws:SourceIp matches office/NAT egress.

VPN-only access

Users must egress via corporate VPN IP.

Key points

Desktop finance exports on campus. Remote staff on corp VPN.

Example

IpAddress aws:SourceIp / same with VPN egress CIDR

Use when

Campus-bound data. Remote workforce.

Comparison: Network or identity?

Comparison: SourceIp fence vs Identity-only IAM. SourceIp fence: Blocks stolen keys used off-network. Identity-only IAM: Relies on who the caller is, not where.
Card 12 of 16: Comparison: Network or identity? · Download PNG
Read card text

What this card says

SourceIp fence

Blocks stolen keys used off-network.

Identity-only IAM

Relies on who the caller is, not where.

Key points

Statements bucket from office only. Admin role usable anywhere with MFA.

Example

NotIpAddress Deny / MFA + least privilege without IP

Use when

High-sensitivity downloads. Break-glass admins.

Interview: Which key for office IP?

Interview card: Which key for office IP?. aws:SourceIp with IpAddress / NotIpAddress operators — not StringEquals on CIDR casually. Include NAT egress IPs for private subnets. 203.0.113.0/24 allowlist.
Card 13 of 16: Interview: Which key for office IP? · Download PNG
Read card text

What this card says

What it is

aws:SourceIp with IpAddress / NotIpAddress operators — not StringEquals on CIDR casually. SourceIp

Why it matters

Include NAT egress IPs for private subnets.

How / example

203.0.113.0/24 allowlist.

Interview: Why allowlist NAT not 10.x?

Interview card: Why allowlist NAT not 10.x?. S3 sees the public egress address after NAT, not the private RFC1918 IP. Update policy when egress IP changes. Only 203.0.113.10/32 works for that NAT.
Card 14 of 16: Interview: Why allowlist NAT not 10.x? · Download PNG
Read card text

What this card says

What it is

S3 sees the public egress address after NAT, not the private RFC1918 IP. NAT

Why it matters

Update policy when egress IP changes.

How / example

Only 203.0.113.10/32 works for that NAT.

Interview: What about VPN users?

Interview card: What about VPN users?. Their egress IP must be on the allowlist or they are denied. Document split-tunnel surprises. Home VPN egress not in list → AccessDenied.
Card 15 of 16: Interview: What about VPN users? · Download PNG
Read card text

What this card says

What it is

Their egress IP must be on the allowlist or they are denied. VPN

Why it matters

Document split-tunnel surprises.

How / example

Home VPN egress not in list → AccessDenied.

Interview: Combine IP with TLS?

Interview card: Combine IP with TLS?. Yes — Deny insecure transport plus SourceIp fence is common. Defense in depth. Office HTTP still denied by TLS Deny.
Card 16 of 16: Interview: Combine IP with TLS? · Download PNG
Read card text

What this card says

What it is

Yes — Deny insecure transport plus SourceIp fence is common. SecureTransport

Why it matters

Defense in depth.

How / example

Office HTTP still denied by TLS Deny.

FAQ

What condition key restricts a bucket to a VPC endpoint?

aws:SourceVpce, usually in a Deny-unless pattern that matches your gateway or interface endpoint id.

Why can a correct bucket policy still fail from inside the VPC?

The subnet may be missing the route to the S3 prefix list, or the endpoint policy may not allow the call. Align both policies, then test from a host in the VPC and from the internet.

Should I use a gateway endpoint or an interface endpoint for S3?

These cards treat a gateway endpoint as the default for most private S3 access. Use an interface endpoint when you need ENIs, security groups, or special DNS. Interface endpoints cost more.

What happens to laptop or NAT uploads when SourceVpce Deny is on?

Traffic that goes out through NAT to the public S3 endpoint does not present your SourceVpce. The deny test should reject it. Admin laptops on the internet are usually denied by this policy.

Which condition key fences office IP addresses?

aws:SourceIp with IpAddress or NotIpAddress. Allowlist the public egress CIDRs, including NAT or firewall addresses, not the private 10.x addresses.

Why must I allowlist the NAT IP instead of 10.x?

S3 sees the public address after NAT, not the private RFC1918 IP. If the ISP changes the egress IP, update the policy.

What about staff on VPN?

Their egress IP must be on the allowlist, or they are denied. Split-tunnel VPNs often surprise people because home ISP IPs are not in the list.

Can I combine a source IP fence with HTTPS?

Yes. A Deny for insecure transport (aws:SecureTransport) plus a SourceIp fence is a common defense-in-depth pattern. Office HTTP can still be denied by the TLS rule.

These chapter pages are already on the site (checked live, HTTP 200, on 19 Nov 2026):

See all AWS revision cards