#Why this matters
Strong IAM policies cannot save a workload whose virtual network exposes internal ports or whose storage bucket allows anonymous downloads. Attackers routinely chain an exposed service or Server-Side Request Forgery (SSRF) bug with legacy instance metadata access to steal role credentials and exfiltrate data over unrestricted outbound rules.
Securing both the network perimeter and storage layer closes these paths in depth.
#Virtual Private Clouds, subnets, and traffic filtering
A Virtual Private Cloud (VPC) gives your tenant private IP space (such as 10.10.10.0/24) divided into subnets:
- Public subnets have a route to an Internet Gateway for load balancers or bastion hosts.
- Private subnets have no direct inbound internet route and host application servers and databases.
Cloud platforms enforce traffic rules using two complementary controls:
| Feature | Security Group | Network ACL (NACL) |
|---|---|---|
| Attachment level | Network interface / VM | Entire subnet |
| Statefulness | Stateful (return traffic auto-allowed) | Stateless (return ports must be allowed) |
| Rule types | Allow rules only (implicit deny) | Explicit Allow and Deny rules |
| Evaluation | All rules evaluated together | Evaluated in ascending rule-number order |
Many teams lock down inbound ports carefully while leaving the default outbound (egress) rule wide open (0.0.0.0/0 on all protocols and ports). Unrestricted egress makes life easy for an attacker: if a web application is compromised, it can fetch external tools, open reverse shells, or stream data out to any host on the internet. Restricting egress to known internal CIDRs, required HTTPS (443/tcp) destinations, or private VPC endpoints limits blast radius and triggers clear VPC Flow Logs alerts when blocked connections occur.
$ head -n 2 vpc-flow-sample.log
2 123456789012 eni-0a1b2c3d4e5f67890 10.10.10.25 198.51.100.44 49152 4444 6 4 240 1700000100 1700000160 REJECT OK
2 123456789012 eni-0a1b2c3d4e5f67890 10.10.10.25 10.10.10.80 49210 5432 6 12 1840 1700000105 1700000165 ACCEPT OKIn the first log line, 10.10.10.25 attempted outbound TCP (protocol 6) to 198.51.100.44 on port 4444, and the tightened egress rule recorded REJECT.
#Protecting instance metadata with IMDSv2
Cloud VMs retrieve configuration and temporary IAM role credentials from a local link-local address: 169.254.169.254. Under legacy IMDSv1, a simple unauthenticated HTTP GET returns those credentials. If a web application has an SSRF vulnerability, an attacker can trick the server into requesting http://169.254.169.254/latest/meta-data/iam/security-credentials/ and steal the instance role's temporary keys.
IMDSv2 defeats most SSRF exploits by requiring a session-oriented PUT request with a custom header to generate a short-lived token first, and enforcing a hop limit (HttpPutResponseHopLimit=1) so containers or NATed requests cannot relay tokens across network hops.
On a lab VM, verify that unauthenticated IMDSv1 GET calls are disabled (HttpTokens=required) and only IMDSv2 succeeds.
#Securing object storage (S3, Blob, GCS)
Object storage services such as Amazon S3, Azure Blob Storage, and Google Cloud Storage are private by default, yet misconfigured policies frequently leak backups and logs. Defence in depth for storage uses four layers:
- Block Public Access: Enable account- and bucket-level Block Public Access so no policy or ACL can grant anonymous reads.
- Scoped policies with TLS: Avoid
"Principal": "*"on private buckets, and add an explicitDenywhenaws:SecureTransportis"false"to block plaintext HTTP. - Encryption at rest: Enable server-side encryption (provider-managed or customer-managed KMS keys) to enforce key-policy controls.
- Private endpoints: Route VPC traffic through a Gateway or Private Endpoint instead of the public internet.
#Defending and common mistakes
- Leaving IMDSv1 enabled: Require IMDSv2 (
HttpTokens=required) in launch templates and organisation guardrails. - Opening
0.0.0.0/0inbound for SSH (22) or RDP (3389): Use private bastions or managed session tools (AWS Systems Manager Session Manager) instead. - Ignoring outbound Security Group rules: Audit
0.0.0.0/0egress and monitor VPC Flow Logs for unexpected connections. - Relying on obscure bucket names: Automated scanners guess names continuously; always enforce Block Public Access and TLS policies.
#Summary
Segmented VPC subnets, stateful Security Groups, and stateless NACLs control network paths, while restricted egress and VPC Flow Logs expose unexpected outbound traffic. Enforcing IMDSv2 protects temporary instance role credentials against SSRF attacks targeting 169.254.169.254. Combining Block Public Access, scoped bucket policies, TLS enforcement, and private VPC endpoints secures cloud storage even when an application flaw occurs.