Skip to main content
Cloud Networking (VPCs, Security Groups) & Storage Security
Lesson 3 of 17

Cloud Networking (VPCs, Security Groups) & Storage Security

Design segmented cloud networks with Security Groups and egress filtering, harden VM metadata access with IMDSv2, and prevent public object storage leaks.

Intermediate 26 min Cloud & DevSecOps

Learning objectives

  • Compare stateful Security Groups and stateless Network ACLs across public and private VPC subnets
  • Explain why unrestricted security-group egress increases post-compromise and exfiltration risk
  • Configure IMDSv2 to defend cloud instance credentials against SSRF attacks
  • Audit and harden object storage bucket policies using Block Public Access, TLS enforcement, and VPC Flow Logs

Recommended first: Cloud Fundamentals & Shared Responsibility (AWS, Azure, GCP)Cloud IAM: Policies, Roles, Federation & Privilege Paths

#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.

Inspecting a rejected outbound scan in VPC Flow Logs (lab interface)
$ 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 OK

In 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.

IMDSv2 session token flow inside an instanceIMDSv2 session token flow inside an instanceAppIMDSv2PUT /latest/api/token (X-aws-ec2-metadata-token-ttl-seconds: 21600)200 OK (session token)GET /latest/meta-data/iam/security-credentials/ (X-aws-ec2-metadata-token)Temporary role credentialsPlain GET without token header returns 401 Unauthorized

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:

  1. Block Public Access: Enable account- and bucket-level Block Public Access so no policy or ACL can grant anonymous reads.
  2. Scoped policies with TLS: Avoid "Principal": "*" on private buckets, and add an explicit Deny when aws:SecureTransport is "false" to block plaintext HTTP.
  3. Encryption at rest: Enable server-side encryption (provider-managed or customer-managed KMS keys) to enforce key-policy controls.
  4. 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/0 inbound 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/0 egress 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.

Knowledge check

Sign in to take the test, complete lessons and save your progress. Log in