Private Endpoints and Egress Control
The previous lesson asked who can get in. Attackers who already have a foothold (a compromised pod, a stolen role session) ask the other question: where can data get out? In many accounts the answer is "anywhere": the NAT gateway lets every instance connect to any host on the Internet, and cloud storage APIs accept a stolen key from any network. Two families of controls change that. Private endpoints keep traffic to cloud services inside the provider's network and let policies insist on it. Egress control limits which outside destinations workloads may reach at all. Together with identity conditions they form what AWS calls a data perimeter: only trusted identities, accessing trusted resources, from expected networks.
Private endpoints
| AWS | Azure | Google Cloud | |
|---|---|---|---|
| Service traffic without the Internet | gateway endpoints (S3, DynamoDB, via route tables) and interface endpoints (PrivateLink, an ENI with a private IP) | Private Endpoint (a NIC for a PaaS resource) and service endpoints | Private Google Access, Private Service Connect |
| Policy on the endpoint | endpoint policy: which principals, actions and resources may pass | (network rules on the resource) | (VPC Service Controls perimeters) |
| Policy on the resource that requires it | condition keys aws:SourceVpce, aws:SourceVpc in bucket and key policies |
storage firewall "selected networks" / disable public network access | VPC Service Controls service perimeter |
The important security property is not the private path itself but that both ends can check it: the endpoint can refuse requests to resources outside your organisation, and the resource can refuse requests that didn't come through your endpoint.
Egress control
Outbound traffic to the Internet from private subnets normally leaves through a NAT gateway, which filters nothing. Controls, from coarse to fine:
- Security group and NACL egress rules: by address and port only; useless against "HTTPS to anywhere" because every exfiltration and command-and-control channel also uses HTTPS.
- DNS filtering: a resolver firewall (Route 53 Resolver DNS Firewall, Azure DNS security policy, Cloud DNS response policies) that only resolves allowed domains, and logs every query.
- A filtering proxy or firewall with TLS SNI or domain allow-lists (AWS Network Firewall, Azure Firewall, GCP Cloud NGFW / Secure Web Proxy, or a self-hosted proxy), so only named destinations are reachable.
The data perimeter as a model
The program checks requests against three perimeter rules, each modelled on the documented AWS condition keys, and a domain allow-list on the egress proxy. Organisation IDs, endpoint IDs and domains are synthetic.
ORG = "o-lab0example"
VPCE = "vpce-0a1b2c3d"
EGRESS_ALLOW = {"api.payments.lab.test", "registry.lab.test", "sts.eu-west-1.amazonaws.com"}
def perimeter(req):
# 1. identity perimeter (on our resources): only principals of our organisation
if req["resource_org"] == ORG and req["principal_org"] != ORG:
return "DENY identity perimeter (aws:PrincipalOrgID)"
# 2. resource perimeter (endpoint policy / SCP): our principals only touch our organisation's resources
if req["principal_org"] == ORG and req["resource_org"] != ORG:
return "DENY resource perimeter (aws:ResourceOrgID)"
# 3. network perimeter (bucket policy): our data only through our VPC endpoint
if req["resource_org"] == ORG and req.get("vpce") != VPCE:
return f"DENY network perimeter (aws:SourceVpce, came from {req.get('source_ip', 'via ' + str(req.get('vpce')))})"
return "allow"
requests = [
("app reads its own bucket", dict(principal_org=ORG, resource_org=ORG, vpce=VPCE)),
("compromised app copies to outside bucket", dict(principal_org=ORG, resource_org="o-unknown", vpce=VPCE)),
("stolen app-role session used from Internet", dict(principal_org=ORG, resource_org=ORG, source_ip="203.0.113.66")),
("vendor (other org) reads our bucket", dict(principal_org="o-vendor", resource_org=ORG, source_ip="198.51.100.9")),
("developer laptop via public endpoint", dict(principal_org=ORG, resource_org=ORG, source_ip="192.0.2.15")),
]
for label, req in requests:
print(f"{label:44} {perimeter(req)}")
print()
for host in ["api.payments.lab.test", "registry.lab.test", "paste.example.net", "a1b2c3.dyn.example.org",
"sts.eu-west-1.amazonaws.com"]:
print(f"egress {host:30} {'allow' if host in EGRESS_ALLOW else 'BLOCK (not on allow-list, logged)'}")app reads its own bucket allow
compromised app copies to outside bucket DENY resource perimeter (aws:ResourceOrgID)
stolen app-role session used from Internet DENY network perimeter (aws:SourceVpce, came from 203.0.113.66)
vendor (other org) reads our bucket DENY identity perimeter (aws:PrincipalOrgID)
developer laptop via public endpoint DENY network perimeter (aws:SourceVpce, came from 192.0.2.15)
egress api.payments.lab.test allow
egress registry.lab.test allow
egress paste.example.net BLOCK (not on allow-list, logged)
egress a1b2c3.dyn.example.org BLOCK (not on allow-list, logged)
egress sts.eu-west-1.amazonaws.com allow
Each rule stops a different attack. The resource perimeter stops a compromised workload from copying data into a bucket the attacker owns, even though the request uses valid credentials and a private endpoint. The network perimeter makes a stolen session useless outside the VPC, which turns credential theft from "game over" into "noisy failure". The identity perimeter keeps outside principals out even if a bucket policy is misconfigured. The last request shows the price: a developer's laptop is outside the network perimeter too, so real perimeters carve out exceptions (a VPN range, aws:ViaAWSService for calls made by AWS services on your behalf, specific admin roles), and every exception needs a review.
On the egress side, the two unknown domains are blocked and logged; a block on a random-looking dynamic-DNS name from a server is exactly what a detection team wants to see (DNS beaconing).
How weak perimeters and egress are detected
- Configuration: VPC endpoint policies left at the default full-access policy; buckets and keys without
aws:SourceVpce/aws:PrincipalOrgIDconditions; Azure storage accounts with public network access enabled; GCP projects with sensitive data outside a VPC Service Controls perimeter. - Traffic: flow logs and proxy logs of connections from servers to destinations outside the allow-list, unusual volumes to storage services, DNS queries for new domains.
- CloudTrail:
AccessDeniedevents whose message mentions a VPC endpoint policy or an explicit deny from the perimeter conditions are often the first sign of stolen credentials being tried from outside;GetObjectcalls with avpcEndpointIdyou don't own, or none at all where you expect one.
How it is fixed
- Add gateway endpoints for S3 and DynamoDB and interface endpoints for the services the workloads use, with endpoint policies restricted to your organisation's resources.
- Add resource-side conditions to sensitive buckets, keys and secrets: deny unless
aws:SourceVpceis yours (with documented exceptions) and deny unlessaws:PrincipalOrgIDis yours. Resource control policies (RCPs) can apply the identity rule organisation-wide. - Put all Internet egress through a domain allow-list (proxy or firewall) and resolver-level DNS filtering, and log both.
- Prefer architectures that don't need egress: pull images from a private registry mirror, send telemetry to an in-VPC collector.
Pitfalls
- An endpoint policy of
"Principal": "*", "Action": "*", "Resource": "*"(the default): the private path exists, but nothing is checked on it. - Allow-listing whole cloud storage domains for egress (
*.s3.amazonaws.com,*.blob.core.windows.net): the attacker's bucket lives there too. Use endpoints with resource perimeters instead. - Forgetting AWS services that call other services on your behalf (CloudFormation, Athena, log delivery): a strict network perimeter breaks them unless it exempts
aws:ViaAWSServiceor service principals.
Practice
1. Which rule would stop the compromised app if it uploaded to the outside bucket through the NAT gateway instead of the endpoint?
Not the endpoint policy (the request doesn't use the endpoint), but an SCP or identity-policy condition on aws:ResourceOrgID applies to the principal wherever it calls from. That is why AWS's guidance places the resource perimeter in SCPs as well as endpoint policies; and the egress proxy should not allow the storage domain at all.
2. Add a VPN exception to the network perimeter: allow requests from 192.0.2.0/24 for principals of our organisation. Which output line changes?
"developer laptop via public endpoint" becomes allow. Implement it with ipaddress.ip_address(req.get("source_ip", "0.0.0.0")) in ipaddress.ip_network("192.0.2.0/24") before rule 3. In AWS this is aws:SourceIp, which only applies to requests that don't come through a VPC endpoint.
3. The proxy log shows a server resolving a1b2c3.dyn.example.org every 60 seconds and being blocked. What do you do?
Treat it as a possible beacon: identify the process on the server (EDR, runtime detection), check when it started, look for other servers with the same pattern, and preserve evidence before rebuilding. The block contained it; the detection is the valuable part.
Test yourself
Which perimeter rule stops a compromised workload from copying data into the attacker's own bucket with valid credentials?
- Identity perimeter
- Resource perimeter (aws:ResourceOrgID in endpoint policies and SCPs)
- Security groups
- The NAT gateway
What does a network perimeter (aws:SourceVpce on the bucket) do to a stolen role session used from the Internet?
- Nothing
- Denies its requests to the bucket because they don't arrive through the VPC endpoint
- Deletes the role
- Rotates the key
Why is allowing outbound HTTPS to any destination weak egress control?
- HTTPS is slow
- Exfiltration and command-and-control use HTTPS too; only a destination allow-list limits them
- HTTPS can't be logged
- Security groups don't support 443