Network paths, exposure and what the logs can show
Unit 2 of 5 in Cloud identity, network and data protection.
You will be able to describe the layers that control cloud network traffic, sweep an account for things shared with the world, read a flow log and explain why the metadata service needs version 2.
Lesson
Layers that control traffic
AWS's guidance on infrastructure security in a virtual private cloud (VPC) describes layers. A VPC is a logically isolated area of the cloud, and AWS says to use separate VPCs to isolate infrastructure by workload or organizational entity. Subnets can isolate the tiers of an application, such as web, application and database, and private subnets are for instances that should not be reached directly from the internet.
AWS says to use security groups as the primary mechanism for controlling network access, and network ACLs as a stateless, coarse-grained control for cases such as denying a specific subset of traffic or as subnet-level guard rails. A security group works at the instance level, allows only allow rules and automatically allows return traffic, while a network ACL works at the subnet level, has allow and deny rules, evaluates them in order and needs return traffic allowed explicitly.
The same page says to keep route tables to the minimum routes needed, to consider separate security groups or network interfaces to control and audit management traffic apart from application traffic, to use PrivateLink so resources reach AWS services over private addresses, to use VPN or Direct Connect for private links from remote networks, and to use flow logs, a posture-checking service and a network firewall. You can practice the ideas in Network Builder on a toy network: a VLAN split is the same idea as a subnet split, and its firewall exercise is deny by default with one allowed service. Its data-center project has a step that puts a database behind a firewall and another that adds a separate management network.
Sweeping your own account for things shared with the world
Exposure is not only open ports. Copies of data can be shared. AWS says you can share an EBS snapshot publicly with all other AWS accounts or privately with specific accounts, that sharing gives others access to all of the data on the snapshot, and that Block public access for EBS snapshots can prevent public sharing.
The sweep lab goes through every region of your own account with a small read-only script and checks the places other labs do not reach: snapshots and machine images, topic and queue policies, function URLs with no authentication and image repository policies. It tests the script against a resource you seed on purpose, fixes it, turns on the account-level guard rails and sweeps again. Reading the policy, not just the name, is the lesson.
Reading a flow log
AWS describes VPC Flow Logs as a feature that captures information about IP traffic going to and from network interfaces in a VPC, published to CloudWatch Logs, S3 or Data Firehose. The data is collected outside the path of your traffic, so it does not affect throughput or latency. Flow logs help with tasks such as diagnosing overly restrictive security group rules and monitoring the traffic reaching an instance.
A record carries fields such as the source and destination address and port, the protocol, packets and bytes, the start and end of the capture window, and an action of ACCEPT or REJECT. That is who talked to whom, on which port, and whether it was allowed. It is not what was said.
AWS also lists traffic that flow logs do not capture: traffic to the Amazon DNS server, traffic to and from the instance metadata address 169.254.169.254, DHCP traffic, traffic to the Amazon Time Sync Service and traffic to the default VPC router's reserved address, among others. A hunt in flow logs can find scanning, rejected traffic and odd outbound connections, but silence in the logs does not mean silence on the wire.
The instance metadata service, and why version 2 matters
An EC2 instance can ask a local address for facts about itself, including temporary credentials for a role attached to it. AWS's page says there are two ways to reach this service: version 2 (IMDSv2), a session-oriented method, and version 1 (IMDSv1), a request and response method. By default you can use either or both, and each instance can be set to accept only version 2, which makes version 1 calls fail.
Version 2 first needs a session token, created with a PUT request, and the page says PUT requests are rejected if they contain an X-Forwarded-For header and that the response to PUT requests has a default hop limit of 1. A bug in an application that fetches web addresses for a visitor, a flaw called server-side request forgery, could be tricked into reading the metadata address and handing back the role's credentials. Requiring version 2 raises the cost of that trick. AWS's page links its own article on defense in depth against open firewalls, reverse proxies and SSRF vulnerabilities.
The lab has you reproduce the version 1 read on a throwaway instance you own, then require version 2 and see the same request fail, and it ends on the honest limit: version 2 is defense in depth, not a reason to leave the application bug in place. AWS says you can use an IAM policy to stop users other than a specified role from changing metadata options. One more point follows from two facts above: flow logs do not record metadata traffic, so detecting misuse of stolen role credentials depends on the account's audit log rather than the network log.
Key points
- Layers: separate VPCs, subnets per tier, private subnets, security groups first, network ACLs as guard rails, minimal routes.
- Snapshots and images can be shared; sharing gives away all the data on them, so sweep every region and turn on the guard rails.
- Flow logs show who talked to whom and whether it was allowed, never the content, and they skip DNS, metadata, DHCP and some other traffic.
- Require IMDSv2 on every instance; it is defense in depth against a request-forgery bug, not a fix for it.
Sources
- Amazon VPC User Guide: Infrastructure security in Amazon VPC
- Amazon EBS User Guide: Share an Amazon EBS snapshot with other AWS accounts
- Amazon VPC User Guide: Logging IP traffic using VPC Flow Logs
- Amazon VPC User Guide: Flow log records
- Amazon VPC User Guide: Flow log limitations
- Amazon EC2 User Guide: Use the Instance Metadata Service to access instance metadata
- Amazon EC2 User Guide: Modify instance metadata options for existing instances
Practice in the labs
Hunt in flow logs, require version 2 on a throwaway instance, sweep your own account, then rehearse segmentation on a toy network. The first three labs use your own free-tier account and say how to clean up so nothing keeps billing.
- Turn on VPC Flow Logs and hunt in them: rejected traffic, scanning, and unexpected egress: You turn on flow logs for your own VPC, generate traffic on purpose and write five queries that find rejected traffic, scanning and unexpected outbound connections.
- Enforce IMDSv2 to block metadata credential theft: On a throwaway instance you own you see the version 1 read, require version 2 and watch the same request fail, then terminate the instance.
- Sweep your OWN AWS account, in every region, for resources shared with the world: A read-only script walks every region for public snapshots, images, topic and queue policies, function URLs and repository policies, and you test it on a resource you seeded.
Also try, in the simulators
- Split one switch into two VLANs (Network Builder exercise): You split one switch into two VLANs so one group can no longer reach the other, the toy version of separating tiers into subnets.
- A firewall that allows one service (Network Builder exercise): You replace an allow-everything firewall rule with one that lets a single service through, which is deny by default in practice.
Knowledge check
- Which statement about security groups and network ACLs is right? Answer: A security group is stateful and has only allow rules; a network ACL is stateless and has allow and deny rules. AWS's comparison table says security groups operate at the instance level with allow rules only and automatic return traffic, while network ACLs operate at the subnet level with allow and deny rules evaluated in order and no automatic return traffic.
- You share an EBS snapshot publicly. What does AWS say you are giving others? Answer: Access to all of the data on the snapshot. AWS warns that when you share a snapshot you give others access to all of the data on it, and that you should share only with people you trust with all of it.
- A flow log shows no traffic to 169.254.169.254. What can you conclude? Answer: Nothing, because flow logs do not record traffic to the instance metadata address. AWS lists traffic to and from 169.254.169.254 among the traffic flow logs do not capture, so an empty result says nothing about metadata use.
- What does requiring IMDSv2 on an instance do? Answer: Makes version 1 calls fail and requires a session token, as defense in depth against request-forgery bugs. AWS says an instance can be configured to accept only IMDSv2 calls, which causes version 1 calls to fail. It raises the cost of a request-forgery trick but does not fix the bug that allows it.
Back to the syllabus or see all classes.