Cloud Networking Fundamentals
VPCs, cloud architecture, security groups, hybrid connectivity, and multi-cloud networking
Chapter 9: Cloud Networking Fundamentals
The $150 Million Misconfiguration
In 2019, a misconfigured Web Application Firewall at a major financial institution allowed an attacker to exploit a server-side request forgery vulnerability and access the AWS metadata service. The attacker retrieved temporary credentials from the instance metadata and used them to access over 100 million customer records stored in S3 buckets.
The technical root cause? A cloud networking misconfiguration that allowed internal traffic to reach the metadata service combined with overly permissive IAM roles. The result was one of the largest data breaches in history, a $80 million fine, and an estimated $150 million in total costs.
This incident illustrates a crucial truth: cloud networking isnβt just traditional networking in someone elseβs data centerβitβs a fundamentally different paradigm with its own architecture, its own security model, and its own failure modes. Understanding cloud networking is no longer optional for security professionals.
Why Cloud Networking Matters
If youβve been following along through this book, youβve learned how networks work: IP addresses, routing, firewalls, and all the protocols that move data from one place to another. Cloud networking uses all of these conceptsβbut implements them in software, at massive scale, with new abstractions layered on top.
Think of the difference between driving your own car and using a ride-sharing service. The basic physics of transportation are the same, but the user experience, the economics, and the failure modes are completely different. Similarly, cloud networking uses the same fundamental protocols weβve discussed, but everything is virtualized, API-driven, and shared across thousands of customers.
The shift to cloud computing has transformed how organizations build and operate networks:
| Traditional Networking | Cloud Networking |
|---|---|
| Physical hardware procurement | API-driven resource creation |
| Weeks to deploy new networks | Minutes to deploy new networks |
| Fixed topology | Programmable, dynamic topology |
| Hardware firewall appliances | Software-defined security controls |
| Capital expenditure | Operational expenditure |
| Local administrative control | Shared responsibility model |
For security professionals, this shift means:
- New attack surfaces: Cloud metadata services, IAM misconfigurations, cross-tenant attacks
- New defensive tools: Native cloud security services, infrastructure as code
- New skills required: Understanding cloud-specific networking concepts
In this chapter, weβll build up from the fundamental building blockβthe Virtual Private Cloudβthrough subnets and security controls, to more advanced topics like hybrid connectivity and the critical security topic of instance metadata services. By the end, youβll understand how cloud networks are structured and where the security risks lie.
Virtual Private Clouds (VPCs)
The foundation of cloud networking is the VPCβyour isolated piece of the cloud. Before we can discuss cloud security, we need to understand what a VPC is and how it works.
What Is a VPC?
A Virtual Private Cloud (VPC) is a logically isolated virtual network within a cloud providerβs infrastructure. Think of it as your own private data center in the cloudβyou control the IP addressing, subnets, routing, and security.
VPC Conceptual View
VPC Conceptual View:
βββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β YOUR VPC β
β (10.0.0.0/16) β
β β
β βββββββββββββββββββββββ βββββββββββββββββββββββ β
β β Public Subnet β β Private Subnet β β
β β (10.0.1.0/24) β β (10.0.2.0/24) β β
β β β β β β
β β βββββββ βββββββ β β βββββββ βββββββ β β
β β β Web β β Web β β β β App β β DB β β β
β β βββββββ βββββββ β β βββββββ βββββββ β β
β β β β β β
β βββββββββββ¬ββββββββββββ βββββββββββ¬ββββββββββββ β
β β β β
β ββββββββββββββ¬ββββββββββββββ β
β β β
β βββββββ΄ββββββ β
β β Router β β
β βββββββ¬ββββββ β
β β β
ββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββ
β
ββββββββ΄βββββββ
β Internet β
β Gateway β
ββββββββ¬βββββββ
β
[Internet]
VPC Components
| Component | Purpose | AWS Name | Azure Name | GCP Name |
|---|---|---|---|---|
| Virtual Network | Isolated network | VPC | VNet | VPC |
| IP Range | Address space | CIDR Block | Address Space | Subnet Range |
| Subdivision | Network segments | Subnet | Subnet | Subnet |
| Internet Access | Outbound connectivity | Internet Gateway | - (built-in) | - (built-in) |
| Routing | Traffic direction | Route Table | Route Table | Routes |
| Access Control | Traffic filtering | Security Groups, NACLs | NSGs | Firewall Rules |
IP Addressing in VPCs
When creating a VPC, you define a CIDR blockβthe IP address range for your virtual network.
Best practices:
- Use RFC 1918 private ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16)
- Plan for growthβexpanding CIDR ranges later is complicated
- Avoid overlapping ranges if youβll connect multiple VPCs
- Leave room for subnets in multiple availability zones
VPC IP Planning Example
VPC IP Planning Example:
βββββββββββββββββββββββ
Company VPC: 10.0.0.0/16 (65,536 addresses)
Production Subnets:
βββ Public: 10.0.0.0/24 (256 addresses) - AZ-a
βββ Public: 10.0.1.0/24 (256 addresses) - AZ-b
βββ Private: 10.0.10.0/24 (256 addresses) - AZ-a
βββ Private: 10.0.11.0/24 (256 addresses) - AZ-b
βββ Database: 10.0.20.0/24 (256 addresses) - AZ-a/b
Development VPC: 10.1.0.0/16
Staging VPC: 10.2.0.0/16
(Non-overlapping ranges allow VPC peering)
** COMMON MISTAKE**
Using 10.0.0.0/16 for every VPC. When you later need to connect VPCs or to on-premises networks, overlapping addresses create routing nightmares. Always plan address space as if all your VPCs will eventually need to communicate.
Subnets and Availability Zones
Once you have a VPC with an IP address range, the next step is dividing it into subnets. This is where cloud networking introduces its first critical security concept: the distinction between public and private subnets.
This distinction is fundamental to cloud security architecture. Getting it wrong is one of the most common causes of cloud breachesβresources that should be internal get exposed to the internet, or resources that need internet access are blocked and configured with workarounds that introduce vulnerabilities.
Public vs. Private Subnets
The distinction between public and private subnets is fundamental to cloud security:
Public Subnet:
- Has a route to an Internet Gateway
- Resources can have public IP addresses
- Accessible from the internet (if security groups allow)
- Use for: Load balancers, bastion hosts, public-facing services
Private Subnet:
- No direct route to the internet
- Resources have only private IP addresses
- Internet access via NAT Gateway (outbound only)
- Use for: Application servers, databases, internal services
Traffic Flow
Traffic Flow:
ββββββββββββ
Inbound (Internet β Your Resources):
Internet β Internet Gateway β Public Subnet β (if needed) NAT β Private Subnet
Outbound (Your Resources β Internet):
Private Subnet β NAT Gateway β Internet Gateway β Internet
ββββββββββββββββββββ
β Internet β
ββββββββββ¬ββββββββββ
β
ββββββββββ΄ββββββββββ
β Internet Gateway β
ββββββββββ¬ββββββββββ
β
βββββββββββββββββββΌββββββββββββββββββ
β β β
βββββββ΄ββββββ ββββββββ΄βββββββ βββββββ΄ββββββ
β Public β β NAT β β Public β
β Subnet β β Gateway β β Subnet β
β (AZ-a) β β β β (AZ-b) β
βββββββββββββ ββββββββ¬βββββββ βββββββββββββ
β
βββββββββββββββββββΌββββββββββββββββββ
β β β
βββββββ΄ββββββ ββββββββ΄βββββββ βββββββ΄ββββββ
β Private β β Private β β Private β
β Subnet β β Subnet β β Subnet β
β (AZ-a) β β (AZ-b) β β (AZ-c) β
βββββββββββββ βββββββββββββββ βββββββββββββ
Availability Zones
Cloud providers operate multiple data centers in each region, called Availability Zones (AZs). AZs are:
- Physically separate data centers
- Connected via high-bandwidth, low-latency links
- Isolated failure domains (power, cooling, networking)
High availability pattern: Deploy resources across multiple AZs so that failure of one AZ doesnβt cause complete outage.
MultiAZ Deployment
Multi-AZ Deployment:
βββββββββββββββββββ
βββββββββββββββββββ
β Load Balancer β
ββββββββββ¬βββββββββ
β
βββββββββββββββΌββββββββββββββ
β β β
ββββββββ΄βββββββ ββββββ΄βββββ ββββββββ΄βββββββ
β AZ-a β β AZ-b β β AZ-c β
β β β β β β
β βββββββββ β βββββββββββ β βββββββββ β
β βWeb 1 β β ββWeb 2 ββ β βWeb 3 β β
β βββββββββ β βββββββββββ β βββββββββ β
β β β β β β
β βββββββββ β βββββββββββ β βββββββββ β
β βApp 1 β β ββApp 2 ββ β βApp 3 β β
β βββββββββ β βββββββββββ β βββββββββ β
β β β β β β
βββββββββββββββ βββββββββββ βββββββββββββββ
Security Note: AZ design affects attack blast radius. Compromising a single AZ shouldnβt provide lateral movement to other AZs if security groups and network ACLs are properly configured. However, shared services (like NAT Gateways) can create cross-AZ dependencies.
Security Groups and Network ACLs
Now we arrive at the heart of cloud network security: controlling which traffic can flow where. In traditional networks, youβd configure firewall rules on dedicated firewall appliances. In the cloud, this functionality is built into the platform itself through security groups and network ACLs.
Understanding the difference between these two controlsβand how they work togetherβis essential for designing secure cloud architectures.
Cloud networking provides two primary layers of traffic filtering:
Security Groups
Security groups are stateful virtual firewalls attached to instances (or other resources).
Characteristics:
- Operate at the instance level
- Stateful: return traffic automatically allowed
- Allow rules only (no explicit deny)
- Evaluated before traffic reaches instance
Security Group Example
Security Group Example:
βββββββββββββββββββββ
Web Server Security Group:
INBOUND:
ββββββββββββ¬βββββββββββ¬ββββββββββββββββββββββ¬βββββββββββββββββββββ
β Protocol β Port β Source β Description β
ββββββββββββΌβββββββββββΌββββββββββββββββββββββΌβββββββββββββββββββββ€
β TCP β 80 β 0.0.0.0/0 β HTTP from anywhere β
β TCP β 443 β 0.0.0.0/0 β HTTPS from anywhereβ
β TCP β 22 β 10.0.0.0/16 β SSH from VPC only β
ββββββββββββ΄βββββββββββ΄ββββββββββββββββββββββ΄βββββββββββββββββββββ
OUTBOUND:
ββββββββββββ¬βββββββββββ¬ββββββββββββββββββββββ¬ββββββββββββββββββββ
β Protocol β Port β Destination β Description β
ββββββββββββΌβββββββββββΌββββββββββββββββββββββΌββββββββββββββββββββ€
β All β All β 0.0.0.0/0 β Allow all outboundβ
ββββββββββββ΄βββββββββββ΄ββββββββββββββββββββββ΄ββββββββββββββββββββ
Security group best practices:
- Principle of least privilegeβonly allow necessary traffic
- Use security group references instead of CIDR when possible
- Create separate groups for different tiers (web, app, database)
- Document the purpose of each rule
Network ACLs (NACLs)
Network ACLs are stateless firewalls at the subnet level.
Characteristics:
- Operate at the subnet level
- Stateless: must explicitly allow return traffic
- Allow and deny rules
- Processed in order by rule number
NACL Example
NACL Example:
ββββββββββββ
INBOUND Rules:
ββββββββββ¬βββββββββββ¬ββββββββββββ¬ββββββββββββββββββββ¬βββββββββ
β Rule # β Protocol β Port β Source β Action β
ββββββββββΌβββββββββββΌββββββββββββΌββββββββββββββββββββΌβββββββββ€
β 100 β TCP β 80 β 0.0.0.0/0 β ALLOW β
β 110 β TCP β 443 β 0.0.0.0/0 β ALLOW β
β 120 β TCP β 22 β 10.0.0.0/8 β ALLOW β
β 130 β TCP β 1024-65535β 0.0.0.0/0 β ALLOW ββ Ephemeral ports for return traffic
β * β All β All β 0.0.0.0/0 β DENY β
ββββββββββ΄βββββββββββ΄ββββββββββββ΄ββββββββββββββββββββ΄βββββββββ
OUTBOUND Rules:
ββββββββββ¬βββββββββββ¬ββββββββββββ¬ββββββββββββββββββββ¬βββββββββ
β Rule # β Protocol β Port β Destination β Action β
ββββββββββΌβββββββββββΌββββββββββββΌββββββββββββββββββββΌβββββββββ€
β 100 β TCP β 80 β 0.0.0.0/0 β ALLOW β
β 110 β TCP β 443 β 0.0.0.0/0 β ALLOW β
β 120 β TCP β 1024-65535β 0.0.0.0/0 β ALLOW ββ Response traffic
β * β All β All β 0.0.0.0/0 β DENY β
ββββββββββ΄βββββββββββ΄ββββββββββββ΄ββββββββββββββββββββ΄βββββββββ
Security Groups vs. NACLs
| Feature | Security Groups | Network ACLs |
|---|---|---|
| Level | Instance | Subnet |
| Statefulness | Stateful | Stateless |
| Rules | Allow only | Allow and Deny |
| Processing | All rules evaluated | Rules processed in order |
| Default | Deny all inbound, allow all outbound | Allow all |
| Use case | Primary access control | Subnet-level backup defense |
PRO TIP
Use security groups as your primary defense (theyβre easier to manage due to statefulness). Use NACLs as a backup layer to block known-bad IP ranges or as a subnet-wide emergency shutoff.
Cloud Provider Comparison
The concepts weβve discussedβVPCs, subnets, security groupsβexist in all major cloud providers, but the terminology and implementation details differ. If you work in a multi-cloud environment (and many organizations do), understanding these differences is essential.
Letβs look at how AWS, Azure, and GCP implement cloud networking, and where their approaches diverge.
AWS Networking
AWS VPC Architecture
AWS VPC Architecture:
ββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β VPC β
β β
β βββββββββββββββββββ βββββββββββββββββββ β
β β Public Subnet β β Private Subnet β β
β β β β β β
β β βββββββββββββββ β β βββββββββββββββ β β
β β β EC2 Instanceβ β β βRDS Database β β β
β β β β β β β β β β
β β β [SG: web] β β β β [SG: db] β β β
β β βββββββββββββββ β β βββββββββββββββ β β
β β β β β β
β β [NACL: public] β β [NACL: private] β β
β ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ β
β β β β
β β ββββββββββββββββββββββββ β
β β β β
β ββββββββββ΄ββββββββββ΄βββββββββββββββββ β
β β Route Table β β
β β 10.0.0.0/16 β local β β
β β 0.0.0.0/0 β igw-xxx β β
β βββββββββββββββββββ¬ββββββββββββββββββ β
β β β
β ββββββββββ΄βββββββββ β
β βInternet Gateway β β
β ββββββββββ¬βββββββββ β
βββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββ
β
[Internet]
AWS-specific services:
- VPC Endpoints: Private connectivity to AWS services without internet
- Transit Gateway: Hub for connecting multiple VPCs and on-premises networks
- PrivateLink: Private connectivity to SaaS services
- VPC Flow Logs: Network traffic logging for analysis and troubleshooting
Azure Networking
Azure VNet Architecture
Azure VNet Architecture:
βββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β VNet β
β β
β βββββββββββββββββββ βββββββββββββββββββ β
β β Subnet β β Subnet β β
β β β β β β
β β βββββββββββββββ β β βββββββββββββββ β β
β β β VM β β β β SQL DB β β β
β β β β β β β β β β
β β β [NSG: web] β β β β[NSG: data] β β β
β β βββββββββββββββ β β βββββββββββββββ β β
β β β β β β
β β [NSG: subnet] β β [NSG: subnet] β β
β βββββββββββββββββββ βββββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Azure Firewall β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Azure-specific features:
- Network Security Groups (NSGs): Can attach to subnets or NICs
- Azure Firewall: Managed firewall service with threat intelligence
- Virtual Network Service Endpoints: Private access to Azure services
- Azure Bastion: Secure RDP/SSH access without public IPs
GCP Networking
GCP VPC Architecture
GCP VPC Architecture:
ββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Global VPC β
β β
β βββββββββββββββββββ βββββββββββββββββββ β
β β Subnet β β Subnet β β
β β (us-east1) β β (europe-west1) β β
β β β β β β
β β βββββββββββββββ β β βββββββββββββββ β β
β β β Compute β β β β Compute β β β
β β β Engine VM β β β β Engine VM β β β
β β βββββββββββββββ β β βββββββββββββββ β β
β β β β β β
β β [Firewall Rules apply to entire VPC, filtered by tags] β
β βββββββββββββββββββ βββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Key difference: GCP VPCs are global by default (subnets are regional)
GCP-specific features:
- Global VPCs: Single VPC can span all regions
- Firewall Rules: Apply at VPC level, filter by network tags
- Private Google Access: Access Google APIs without public IP
- Shared VPC: Centralized VPC shared across projects
Provider Comparison Summary
| Feature | AWS | Azure | GCP |
|---|---|---|---|
| VPC Scope | Regional | Regional | Global |
| Subnet Scope | Availability Zone | Regional | Regional |
| Security Control | Security Groups + NACLs | NSGs | Firewall Rules |
| Private Service Access | VPC Endpoints | Service Endpoints | Private Google Access |
| Multi-VPC Hub | Transit Gateway | Virtual WAN | Cloud Interconnect |
Hybrid Connectivity
So far, weβve discussed cloud networking as if it exists in isolation. But most organizations donβt move everything to the cloud at onceβthey run hybrid environments with some systems in the cloud and others in traditional data centers. Connecting these environments securely is one of the most critical challenges in cloud networking.
Several options exist, each with different trade-offs in cost, performance, and complexity:
VPN Connections
Site-to-Site VPN creates an encrypted tunnel over the public internet.
VPN Architecture
VPN Architecture:
ββββββββββββββββ
On-Premises Cloud VPC
Network
ββββββββββββββββ ββββββββββββββββ
β β β β
β ββββββββββ β IPsec Tunnel over Internet β ββββββββββ β
β βVPN β βββββββββββββββββββββββββββββββββββββΊβ βVPN β β
β βGateway β β β βGateway β β
β ββββββββββ β β ββββββββββ β
β β β β
β 10.0.0.0/8 β β 172.16.0.0/12β
ββββββββββββββββ ββββββββββββββββ
Characteristics:
- Quick to set up (hours)
- Low cost (just bandwidth)
- Encrypted (IPsec)
- Variable performance (depends on internet)
- Single points of failure possible
Dedicated Connections
Direct connections provide private, dedicated links between your data center and cloud provider.
| Provider | Service Name | Bandwidth Options |
|---|---|---|
| AWS | Direct Connect | 1 Gbps, 10 Gbps, 100 Gbps |
| Azure | ExpressRoute | 50 Mbps - 10 Gbps |
| GCP | Cloud Interconnect | 10 Gbps, 100 Gbps |
Direct Connect Architecture
Direct Connect Architecture:
βββββββββββββββββββββββββββ
On-Premises Colocation Facility AWS
βββββββββββββββ βββββββββββββββββββββββββββ βββββββββββββββ
β β β β β β
β Your β β βββββββββββ ββββββββ β β ββββββββββββ
β Network βββββββΌβββ€ Your ββββ€ AWS ββββΌββββββΌβββ€ Direct ββ
β β β β Router β β DX β β β β Connect ββ
β β β βββββββββββ βRouterβ β β β Gateway ββ
β β β ββββββββ β β ββββββββββββ
β β β β β β β
βββββββββββββββ βββββββββββββββββββββββββββ β β β
β βββββ΄ββββ β
β β VPC β β
β βββββββββ β
βββββββββββββββ
Characteristics:
- Consistent, predictable performance
- Higher bandwidth available
- Not encrypted by default (add your own)
- Higher cost
- Longer setup time (weeks to months)
Security Note: Direct connections arenβt encrypted by defaultβtheyβre just dedicated private links. For sensitive traffic, implement IPsec or MACsec encryption over the direct connection. Many organizations run VPN over Direct Connect for defense in depth.
VPC Peering
VPC Peering connects two VPCs for direct communication.
VPC Peering
VPC Peering:
βββββββββββ
βββββββββββββββββββ Peering βββββββββββββββββββ
β VPC A β Connection β VPC B β
β 10.0.0.0/16 βββββββββββββββββββββββββββΊβ 172.16.0.0/16 β
β β β β
β βββββββββββ β β βββββββββββ β
β βInstance ββββββΌβββββββββββββββββββββββββββΌβββββInstance β β
β βββββββββββ β β βββββββββββ β
β β β β
βββββββββββββββββββ βββββββββββββββββββ
Requirements:
- Non-overlapping CIDR ranges
- Route table entries in both VPCs
- Security groups allowing traffic
Limitations:
- Non-transitive (AβB and BβC doesnβt mean AβC)
- Cannot peer VPCs with overlapping CIDRs
- Cross-region peering may have different pricing
Transit Gateway / Virtual WAN
For complex multi-VPC architectures, cloud providers offer hub-and-spoke connectivity:
Transit Gateway Architecture
Transit Gateway Architecture:
ββββββββββββββββββββββββββββ
βββββββββββββββββββββββ
β Transit Gateway β
β β
β (Hub for all β
β VPC connections) β
ββββββββββββ¬βββββββββββ
β
ββββββββββββββββββββββΌβββββββββββββββββββββ
β β β
βββββββ΄ββββββ βββββββ΄ββββββ βββββββ΄ββββββ
β VPC A β β VPC B β β VPC C β
β β β β β β
βProduction β βDevelopmentβ β Shared β
β β β β β Services β
βββββββββββββ βββββββββββββ βββββββββββββ
β
β
ββββββββββββ΄βββββββββββ
β On-Premises via β
β VPN / Direct β
βββββββββββββββββββββββ
Cloud Load Balancing and CDNs
Load Balancers
Cloud load balancers distribute traffic across multiple backend instances:
| Type | Layer | Use Case |
|---|---|---|
| Network Load Balancer | Layer 4 (TCP/UDP) | High performance, low latency |
| Application Load Balancer | Layer 7 (HTTP/HTTPS) | Content-based routing, WAF integration |
| Gateway Load Balancer | Layer 3 | Security appliance insertion |
Application Load Balancer
Application Load Balancer:
βββββββββββββββββββββββββ
Users β [ALB] β Path-based routing:
β
βββ /api/* β API Server Pool
βββ /static/* β Static Content Pool
βββ /* β Web Server Pool
Content Delivery Networks (CDNs)
CDNs cache content at edge locations close to users:
CDN Architecture
CDN Architecture:
ββββββββββββββββ
User in Asia User in Europe User in Americas
β β β
βΌ βΌ βΌ
βββββββββββ βββββββββββ βββββββββββ
β Edge β β Edge β β Edge β
β Tokyo β β London β β NYC β
ββββββ¬βββββ ββββββ¬βββββ ββββββ¬βββββ
β β β
βββββββββββββββββΌβββββββββββββββββββ
β
ββββββββ΄βββββββ
β Origin β
β Server β
β (your VPC) β
βββββββββββββββ
Security considerations:
- CDN can mask origin IP (but misconfiguration can leak it)
- DDoS mitigation at the edge
- WAF often integrated with CDN
- Certificate management for HTTPS
THINK ABOUT IT
If an attacker discovers your origin serverβs IP address (bypassing the CDN), what security controls remain? How would you detect if someone is trying to attack your origin directly?
Instance Metadata Service
Now we come to one of the most critical security topics in cloud networkingβand the exact vulnerability that enabled the breach described at the beginning of this chapter.
The Instance Metadata Service (IMDS) is a cloud feature that seems helpful but has become one of the most exploited attack vectors in cloud environments. Understanding it is essential for anyone working with cloud infrastructure.
What Is IMDS?
Every cloud instance can query a special HTTP endpoint (typically 169.254.169.254) to retrieve information about itself: instance ID, IP address, region, andβcriticallyβtemporary security credentials.
Metadata Service Example (AWS)
Metadata Service Example (AWS):
ββββββββββββββββββββββββββββββ
$ curl http://169.254.169.254/latest/meta-data/
ami-id
hostname
instance-id
instance-type
local-ipv4
public-ipv4
iam/ β Security credentials here!
$ curl http://169.254.169.254/latest/meta-data/iam/security-credentials/MyRole
{
"AccessKeyId": "ASIA...",
"SecretAccessKey": "...",
"Token": "...",
"Expiration": "2025-01-21T12:00:00Z"
}
IMDS Security Risks
The metadata service is a prime target for attackers:
- SSRF Attacks: If an application can be tricked into making HTTP requests to arbitrary URLs, attackers can point it at the metadata service
- Container Escapes: Containers might access the hostβs metadata service
- Credential Theft: Stolen temporary credentials provide cloud API access
IMDS Mitigations
| Mitigation | Description |
|---|---|
| IMDSv2 (AWS) | Requires session token, blocks SSRF via header requirement |
| Metadata concealment | GKEβs approach to block metadata from pods |
| Instance profiles | Least-privilege IAM roles |
| Network controls | Block 169.254.169.254 from containers |
IMDSv2 Example
IMDSv2 Example:
ββββββββββββββ
# Step 1: Get session token
$ TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" \
-H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
# Step 2: Use token to query metadata
$ curl -H "X-aws-ec2-metadata-token: $TOKEN" \
http://169.254.169.254/latest/meta-data/
# SSRF attacks can't easily add custom headers, blocking the attack
Security Note: The Capital One breach mentioned in the chapter opening exploited IMDS. Always use IMDSv2 (or equivalent protections), apply least-privilege IAM roles, and implement network controls around metadata access. See Part II, Chapter 10 for exploitation techniques.
Cloud Networking Security Best Practices
Defense in Depth
Cloud Security Layers
Cloud Security Layers:
βββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 1: Edge Protection β
β - WAF, DDoS protection, CDN β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Layer 2: Network Perimeter β
β - VPC design, security groups, NACLs β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Layer 3: Subnet Segmentation β
β - Public/private separation, micro-segmentation β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Layer 4: Instance Protection β
β - Host-based firewalls, endpoint protection β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Layer 5: Application Security β
β - Input validation, authentication, encryption β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Layer 6: Data Protection β
β - Encryption at rest and in transit, access controls β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Security Checklist
- Use private subnets for backend resources
- Implement least-privilege security groups
- Enable VPC Flow Logs
- Use VPC endpoints for AWS service access
- Enable IMDSv2 and restrict IAM role permissions
- Implement encryption in transit (TLS)
- Use dedicated security account for monitoring
- Regular security group audits
- Network architecture documentation
TRY IT YOURSELF
If you have access to a cloud account:
- Create a VPC with public and private subnets
- Launch an instance in each subnet
- Configure security groups to allow SSH to public instance only
- Verify the private instance is not directly accessible
- Enable VPC Flow Logs and observe the traffic patterns
Key Takeaways
-
VPCs provide isolated virtual networks in the cloud with your own IP addressing, routing, and security controls
-
Subnets divide VPCs; public subnets have internet access, private subnets donβt
-
Security groups (stateful, instance-level) and NACLs (stateless, subnet-level) provide layered traffic filtering
-
Cloud providers differ in terminology and implementation, but core concepts are similar
-
Hybrid connectivity options include VPN, direct connections, and VPC peering
-
IMDS is a critical attack vectorβuse IMDSv2 and restrict permissions
-
Defense in depth applies to cloud networking just as it does to traditional networks
Review Questions
-
What is a VPC, and how does it provide network isolation?
-
Explain the difference between public and private subnets.
-
How do security groups differ from network ACLs? When would you use each?
-
Why is the instance metadata service a security concern, and how can you protect it?
-
Compare VPN and direct connection options for hybrid connectivity.
Further Reading
- AWS VPC Documentation: docs.aws.amazon.com/vpc
- Azure Virtual Network: docs.microsoft.com/azure/virtual-network
- GCP VPC: cloud.google.com/vpc/docs
- βCloud Security Alliance Guidanceβ: cloudsecurityalliance.org