Sub topic 8
Isolating environments with separate route tables
This chapter assumes you have created a transit gateway with default association and propagation turned off, attached VPCs to it, and know what association and propagation mean. It also assumes you can add VPC route table entries that point at a transit gateway.
Why one route table is not enough
A transit gateway with a single route table behaves like a flat network. Every attachment is associated with that table and propagates into it, so every VPC can reach every other VPC. That is fine for a lab. It is a problem when production and development share the same hub, because a mistake in a development VPC can then reach production.
A transit gateway can hold many route tables. Segmentation means splitting attachments across several of them and controlling which routes each table contains. A source can only reach a destination if the source's route table has a route to it.
The two rules that make segmentation work
- Association decides which table an attachment's outbound traffic uses. An attachment is associated with exactly one route table. Traffic that enters the transit gateway from that attachment is looked up in that table.
- Propagation decides which tables learn an attachment's CIDR. An attachment can propagate its routes into many route tables, or none.
So the route table an attachment is associated with controls where it can send traffic. The tables it propagates into control who can send traffic to it. Segmentation is the deliberate pairing of these two settings.
A worked design: prod, dev, and shared services
Suppose you have three VPCs:
| VPC | CIDR | Role |
|---|---|---|
| prod | 10.1.0.0/16 | Production workloads |
| dev | 10.2.0.0/16 | Development workloads |
| shared | 10.3.0.0/16 | DNS, logging, and artifact services |
The requirements are that prod and dev can each reach shared, and that prod and dev cannot reach each other. Create three transit gateway route tables, prod-rtb, dev-rtb, and shared-rtb, and configure them as follows.
| Attachment | Associated with | Propagates into |
|---|---|---|
| prod | prod-rtb | shared-rtb |
| dev | dev-rtb | shared-rtb |
| shared | shared-rtb | prod-rtb, dev-rtb |
The resulting route tables are:
| Route table | Routes it contains | Effect |
|---|---|---|
| prod-rtb | 10.3.0.0/16 → shared | prod can reach shared only |
| dev-rtb | 10.3.0.0/16 → shared | dev can reach shared only |
| shared-rtb | 10.1.0.0/16 → prod, 10.2.0.0/16 → dev | shared can answer both |
shared-rtb needs both routes so replies can return. Neither prod-rtb nor dev-rtb has a route for the other environment's CIDR, so the transit gateway drops that traffic.
Building it with the CLI
Create the three route tables. The commands print each table's ID. The examples below use placeholder IDs, so substitute your own.
for name in prod-rtb dev-rtb shared-rtb; do
aws ec2 create-transit-gateway-route-table \
--transit-gateway-id tgw-0123456789abcdef0 \
--tag-specifications "ResourceType=transit-gateway-route-table,Tags=[{Key=Name,Value=$name}]"
doneAssociate each attachment with its own table:
aws ec2 associate-transit-gateway-route-table \
--transit-gateway-route-table-id tgw-rtb-0prod00000000000a \
--transit-gateway-attachment-id tgw-attach-0prod0000000000a
aws ec2 associate-transit-gateway-route-table \
--transit-gateway-route-table-id tgw-rtb-0dev000000000000b \
--transit-gateway-attachment-id tgw-attach-0dev00000000000b
aws ec2 associate-transit-gateway-route-table \
--transit-gateway-route-table-id tgw-rtb-0shared0000000000c \
--transit-gateway-attachment-id tgw-attach-0shared00000000cThen set up propagation. Prod and dev propagate into the shared table, and shared propagates into both of theirs:
# prod and dev -> shared-rtb
aws ec2 enable-transit-gateway-route-table-propagation \
--transit-gateway-route-table-id tgw-rtb-0shared0000000000c \
--transit-gateway-attachment-id tgw-attach-0prod0000000000a
aws ec2 enable-transit-gateway-route-table-propagation \
--transit-gateway-route-table-id tgw-rtb-0shared0000000000c \
--transit-gateway-attachment-id tgw-attach-0dev00000000000b
# shared -> prod-rtb and dev-rtb
aws ec2 enable-transit-gateway-route-table-propagation \
--transit-gateway-route-table-id tgw-rtb-0prod00000000000a \
--transit-gateway-attachment-id tgw-attach-0shared00000000c
aws ec2 enable-transit-gateway-route-table-propagation \
--transit-gateway-route-table-id tgw-rtb-0dev000000000000b \
--transit-gateway-attachment-id tgw-attach-0shared00000000cPropagation takes a short time to apply. Check what a table contains before you test traffic:
aws ec2 search-transit-gateway-routes \
--transit-gateway-route-table-id tgw-rtb-0dev000000000000b \
--filters "Name=state,Values=active,blackhole"dev-rtb should list only 10.3.0.0/16. If 10.1.0.0/16 appears, prod is propagating into the wrong table.
Adding a blackhole as a guardrail
Isolation by absence relies on nobody enabling the wrong propagation later. A static blackhole route makes the intent explicit. A blackhole route matches traffic and silently drops it:
aws ec2 create-transit-gateway-route \
--transit-gateway-route-table-id tgw-rtb-0dev000000000000b \
--destination-cidr-block 10.1.0.0/16 \
--blackholeFor the same prefix, a static route is preferred over a propagated one. If someone later enables prod propagation into dev-rtb, the blackhole still wins. This works only for an identical prefix. A propagated route with a longer prefix, such as a /24 inside the prod VPC, would win by longest-prefix match.
Common errors and gotchas
- Association conflicts. An attachment can have only one association. To move it, call
disassociate-transit-gateway-route-tablefirst, then associate it with the new table. Traffic from that attachment has no route during the gap. - One-way routing. If prod can send to shared but replies fail, check that
shared-rtbhas a route back to prod. Isolation designs often forget the return path. - VPC routes are still required. Transit gateway tables only control traffic inside the hub. Each VPC's subnet route table still needs an entry pointing at the transit gateway. The prod VPC needs a route for
10.3.0.0/16, and it should not have one for10.2.0.0/16. - Overlapping propagated routes. If two attachments propagate the same CIDR into one table, the table holds both and picks between them using route evaluation rules. Avoid this by keeping CIDRs unique per table.
- Segmentation is not a firewall. It works at the CIDR level only. It cannot allow one port and deny another. Use security groups and network ACLs inside each VPC for that.
Verifying isolation
Use one test per rule. From an instance in dev, reach a shared-services address, which should succeed, then try a prod address, which should time out. If the prod test succeeds, list the routes in dev-rtb and look for a 10.1.0.0/16 entry. Reachability Analyzer, covered later in this tutorial, can confirm the path without sending traffic.
Exercise
You attach a new staging VPC (10.4.0.0/16). It must reach shared services (10.3.0.0/16) and be unreachable from prod and dev. Which association and propagation settings do you use, and why does shared still reach staging?
Show answer
Create a staging-rtb, or reuse a dedicated table, and associate the staging attachment with it. Enable propagation of the shared attachment into staging-rtb so staging has a route to 10.3.0.0/16. Enable propagation of the staging attachment into shared-rtb only, so shared has a return route to 10.4.0.0/16. Do not propagate staging into prod-rtb or dev-rtb, and do not propagate prod or dev into staging-rtb. Shared can reach staging because shared-rtb contains the 10.4.0.0/16 route. Prod and dev cannot, because their tables do not.