Skip to the workspace
Pebellslearn by building
VPC — Your Private Network  ›  Capstone Project

Security Groups

Security Groups 14 minA security group is a stateful firewall attached to an instance's network interface that allows only the inbound and outbound traffic its rules permit, and rules can refer to other security groups.

aws / Security Groups

Explore each scene at your own pace.

01 · The rule

The rule

Security Groups

Inkwell's database is in a private subnet, so the internet cannot reach it. But the image job, a test server and anything else in the VPC still could. Inkwell wants a stricter rule: only the web servers may talk to the database, and only on the database port. That rule lives in a security group.

The rule

Security groups allow, never deny; replies come back free.

A security group is a virtual firewall attached to an instance's network interface. Every packet is checked against its rules:

  • Allow rules only. A rule says which traffic is permitted: protocol, port, and source (inbound) or destination (outbound). Anything not allowed is dropped. You cannot write a "deny" rule.
  • Stateful. If a request is allowed in, its reply is allowed out automatically, and the other way round. You do not write rules for return traffic.
  • Defaults. A new group allows no inbound traffic and all outbound traffic.
  • Sources can be other groups. Instead of an IP range, a rule can say "from anything carrying security group X".
  • An instance can have several groups; the allowed traffic is the union of all their rules. Rule changes take effect immediately.

Inkwell's two groups:

web-sg  inbound   TCP 443   from 0.0.0.0/0
db-sg   inbound   TCP 5432  from web-sg

Subnets have a second, separate firewall: the network ACL. It is stateless (return traffic needs its own rule), supports both allow and deny, applies to a whole subnet, and checks numbered rules in order. The default network ACL allows everything, so most teams do their real filtering in security groups.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.