Lesson 4 of 6 Edge Protection and Application Security

Controlling Network Flows in Depth

This lesson explains the network controls that allow only the flows an application needs, between tiers, between VPCs and to the outside, and the distinct role each plays.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify the role of each network control.
  • Reference security groups rather than CIDR ranges between tiers.
  • Explain how network flows are governed across accounts.

The controls and their roles

Network traffic is controlled at several layers, each with a distinct role. Security groups attach to instances and network interfaces. They are stateful, have allow rules only, and can reference other security groups, which is how tiers are connected, for example allowing the database group to accept traffic only from the application group. Network ACLs apply to subnets. They are stateless and have allow and deny rules, so they suit explicit denials of address ranges and coarse boundaries between subnets.

AWS Network Firewall inspects traffic at the VPC or transit level, with stateful and stateless rules and intrusion prevention. It provides domain-based egress filtering and TLS inspection. Route 53 Resolver DNS Firewall blocks lookups of malicious or unapproved domains. VPC Lattice auth policies authorise each request between services at the application layer, based on the caller's identity. The following table summarises the controls.

ControlLayer and stateUse
Security groupsInstance or interface; stateful; allow rules onlyRules between tiers by referencing other security groups
Network ACLsSubnet; stateless; allow and deny rulesExplicit denies of address ranges and coarse subnet boundaries
AWS Network FirewallVPC or transit; stateful and stateless; IPSDomain-based egress filtering, intrusion prevention, TLS inspection
Route 53 Resolver DNS FirewallDNSBlocking lookups of malicious or unapproved domains
VPC Lattice auth policiesApplication (layer 7)Per-request authorisation between services
Sort into groups

Which flow control?

Exam skills 1.4.3

Choose the control that best fits each requirement.

Log in to try this activity Interactive activities are free with an account.

Security group practices

Security groups stay accurate as the environment changes when rules reference other security groups rather than CIDR ranges between tiers: the database group allows the database port from the application group, so any instance that joins the application tier is allowed automatically and any that leaves it is not. Ranges that appear in many rules, such as on-premises networks or partner addresses, are kept in managed prefix lists, so a change is made once.

Inbound rules open to 0.0.0.0/0 belong only on internet-facing load balancers, never on instances or databases. Because security groups can only allow, blocking a particular address range requires a network ACL deny rule or a firewall.

The following diagram shows a chain of security group references across three tiers of an application.

Three tiers connected by security group references. sg-alb accepts TCP 443 only from the CloudFront origin-facing prefix list, sg-app accepts TCP 8080 only from sg-alb, and sg-db accepts TCP 5432 only from sg-app. Because no rule between tiers uses an IP range, instances that Auto Scaling adds to a tier are allowed as soon as they launch.
Each arrow is an inbound rule on the group it points to, whose source is the group or prefix list before it.

Governing flows across accounts

Across hundreds of accounts, network rules drift unless they are governed centrally. AWS Config rules, deployed to every account in a conformance pack, audit security groups for overly permissive access, such as SSH open to the internet, and remediate them through Systems Manager Automation, while baseline security groups are deployed with StackSets.

Network Access Analyzer verifies the network against stated intent, for example that no path leads from the internet to any database subnet, and reports every path that violates it. VPC Flow Logs provide evidence of the flows that actually occur, which shows whether rules are wider than the traffic they carry.

Worked example

Three-tier flows with referenced security groups

A three-tier application must allow only the flows the tiers need, and the rules must keep working as Auto Scaling adds and removes instances. Each tier's security group references the tier in front of it rather than IP ranges:

Security group   Inbound rule                                   Source
---------------  ---------------------------------------------  --------------------------------------
sg-alb           TCP 443                                        CloudFront origin-facing prefix list
sg-app           TCP 8080                                       sg-alb
sg-db            TCP 5432                                       sg-app
sg-db            (no other inbound rules)

A new application instance is reachable from the load balancer and can reach the database as soon as it launches, without any rule change. A network ACL on the database subnets adds an explicit deny for a range that an incident response team has flagged, which security groups cannot express. Across the organisation, an AWS Config rule deployed in a conformance pack reports any security group that allows inbound traffic from 0.0.0.0/0 on ports other than 80 and 443, and Network Access Analyzer confirms that no path leads from an internet gateway to the database subnets.

Check yourself

How can overly permissive security group rules be found and fixed across an organisation?

Show answer

With AWS Config rules, such as restricted-ssh, deployed through an organisation conformance pack with automatic remediation.

Exam Tips

Remember for the exam

  • Security groups are stateful and allow only; network ACLs are stateless and can deny.
  • Reference security groups between tiers instead of IP ranges.
  • To allow egress only to approved domains, use Network Firewall domain lists.
  • To audit overly permissive security groups across the organisation, use AWS Config rules in a conformance pack.
  • To prove that no unintended network paths exist, use Network Access Analyzer.