How to Protect Your IP Range on AWS from BGP Hijacking

In 2008, a single bogus BGP announcement took YouTube offline for much of the world. This hands-on guide sets up VPC IPAM delegated RPKI for BYOIP prefixes, from the RIR handshake to automatic ROA creation and renewal, overlap detection, expiration alarms and cleanup, with CLI, CloudFormation and an honest look at what IPAM does not block.

In February 2008, Pakistan Telecom tried to block YouTube inside Pakistan and ended up taking it down for a large part of the world. It announced a /24 carved out of YouTube's /22, its upstream passed the announcement along without checking anything, and longest prefix match did the rest: every router that heard both routes preferred the more specific one, which was the fake one. YouTube got its traffic back about 80 minutes later by announcing the same /24 and then two /25s, beating the hijacker at its own game.

Figure 1: BGPlay, from RIPE NCC, showing the path of YouTube's /24 moving from ASN 36561 (YouTube) to 17557 (Pakistan).
I have spent more than 15 years as a network engineer, and for a good part of them my hijack detection was a terminal, a full routing table and a command like  show ip bgp 203.0.113.0 | exclude _64512$ , run whenever someone remembered to run it. It was not rare to see announcements from ASNs that didn't own the CIDRs (and I'm not talking about transit here). The right fix was always RPKI: publish a ROA for each prefix, so that networks running ROV drop an announcement like Pakistan Telecom's as soon as it arrives. But running your own RPKI certificate authority meant a Krill server to install, patch, back up and keep talking to the RIR, and back then that was a sysadmin job most of us "network guys" never wanted to take on.
VPC IPAM now does that job as a managed service for the prefixes you bring to AWS. It creates and renews your ROAs through delegated RPKI, and it watches your routes for overlapping announcements from other networks. It doesn't block anything: blocking is still done by other networks' routers, through ROV, and your ROA is what they check. The rest of this guide shows how to set it all up without knocking your own announcements offline on the way.

Who this guide is for

This guide assumes you already run BGP and know the RPKI basics: a ROA (Route Origin Authorization) is a signed statement saying which ASN may originate a prefix and up to which length, and ROV (Route Origin Validation) is a router checking each announcement against those ROAs and marking it Valid, Invalid or NotFound.
To follow it, you need a block registered with ARIN, RIPE NCC, APNIC or LACNIC (NIC.BR included) that you have already brought, or plan to bring, to AWS through BYOIP (Bring Your Own IP).
You can skip it if:
  • your public IPs are Elastic IPs from Amazon's own pool. Amazon already signs those ROAs.
  • your RIR is AFRINIC, or your accounts are in GovCloud or the China Regions. Check the current list of supported RIRs and Regions before planning.
  • you already run your own CA ( Krill  or the RIR's delegated service) with monitoring and renewal under control. Migrating gains you little and adds the risk of the migration itself.
Note: IPs, CIDRs, ASNs and other information in this article were replaced for security reasons.

Who does what

You configure IPAM in your AWS account and your RIR certifies IPAM as a child CA (certificate authority) for your prefixes, so IPAM can sign ROAs on your behalf and renew them before they expire. Those ROAs go to the public RPKI repositories, where validators in other networks download them. When a hijacker announces a piece of your range from another ASN, networks running ROV mark the announcement as Invalid and drop it. IPAM never talks to those routers, and it doesn't need to.

Figure 2: context. IPAM keeps the ROA valid. Blocking happens in other networks.
Note that, according to data presented at IETF 125, only 27% of ASNs run ROV, and about 60% of IPv4 routes/CIDRs have a ROA. In other words, the attack surface for CIDR hijacking is large and real. Even more so because the failure of an expired ROA is silent. When it expires, your prefix goes from Valid to NotFound, and NotFound is accepted almost everywhere. Nothing breaks and nobody gets paged, but a hijack of your range now gets through the same networks that would have blocked it yesterday. Renewal is what IPAM takes off your plate (and we'll also create an alarm to monitor it).

Before you start: inventory your announcements

The risky moment in this whole process is the first ROA. Before it exists, your prefix is NotFound everywhere and any announcement passes. After it exists, every announcement that doesn't match the ROA becomes Invalid in networks running ROV, including your own announcements.
Write down, for every prefix you plan to cover:
  • the prefix and the exact lengths you announce (the /22 and any /23 or /24 carved from it);
  • the origin ASN of each announcement;
  • where each one is announced from (AWS, your data center, a transit provider or a CDN that originates on your behalf).
Then check the list against what IPAM will create:
  • If you announce more specific prefixes, remember that the ROA IPAM creates is Strict: the max length equals the prefix length. A /22 ROA with max length /22 makes your own /24s from that block Invalid, unless each /24 has its own ROA.
  • If you are migrating, the prefix will be originated by the ASN configured on the pool, which may not be the ASN your data center uses today. Register the on-premises ASN too, so both announcements stay Valid during the cutover.
  • If your RIR is ARIN, RIPE NCC or APNIC, IPAM may pre-create ROAs from the ones you already have when you associate the registry. Review those ROAs before enabling the association, because once you enable it, they go live. With NIC.BR and LACNIC, ROAs are created when you provision the prefix.
Keep Strict as the default. A loose max length is exactly what forged-origin sub-prefix hijacking exploits. An attacker who puts your ASN as the origin in the AS path can announce a more specific prefix that your own ROA considers valid. Register each more specific prefix explicitly.

Setup

What you will build

We'll focus on what lives in AWS. An IPAM on the Advanced Tier holds an Internet Registry Association, which is IPAM's child CA under your RIR, created only once. Under it sit the BYOIP pool with your prefix (provisioning creates the ROA), the routing policy registrations for prefixes that stay on-premises, and the findings, which compare your routes with those ROAs. A CloudWatch alarm watches the ROA expiration metric. The circled numbers match the steps below.

Figure 3: what you will build, step by step.
The full code (a CloudFormation template for the IPAM, pool, association and alarm, plus a README with every CLI command and the cleanup script) is at  thiagosagara/awscommunitybuilder/ipam-rpki . This guide only shows the snippets where a parameter matters. The examples use NIC.BR, the documentation prefix 203.0.113.0/24, the private ASN 64512 and example IDs, which you replace with your own.

Step 1: create the IPAM on the Advanced Tier

Delegated RPKI, findings and routing policy registrations only exist on the Advanced Tier, so this is where the bill starts. Advanced costs US$ 0.00027 per active IP per hour, counting every active IP IPAM sees in its scope, not only the BYOIP ones. A fully used /24 comes to about US$ 49.77 per 30 days; a scope with 10,000 active IPs, about US$ 1,944.
If you already have an IPAM on the Free Tier, you can switch it to Advanced ( aws ec2 modify-ipam --tier advanced ) instead of creating a new one.

Step 2: associate your RIR

The association is how IPAM introduces itself to your RIR.
aws ec2 create-ipam-internet-registry-association \
--ipam-id <ipam-id> \
--rir NICBR \
--org-handle <your-org-handle> # on Registro.br, usually the technical ID
In the console, the path is IPAMs, your IPAM, Associate Internet registry and Create an association, where you choose the RIR and enter the org handle.

If you plan to use the CloudFormation template, be aware that  AWS::EC2::IpamInternetRegistryAssociation  doesn't accept  NICBR  as a RIR value today, but the CLI does. For a Registro.br block, create the association with the CLI.
The association goes from  create-in-progress  to  pending-enable . Only then is the delegation request ready, in the  ChildRequestXml  field:
aws ec2 describe-ipam-internet-registry-associations \
--ipam-internet-registry-association-ids <assoc-id> \
--query 'IpamInternetRegistryAssociations[0].ChildRequestXml' --output text > child-request.xml
In the console, the same XML shows up in the Complete RIR delegation tab:

Figure 5: "Complete RIR delegation" tab with the child request.
Here is something cool to look at. Since we're using NIC.BR in the example, there are no pre-created ROAs. For demonstration purposes, I repeated the process with Microsoft's (public) data, which is at ARIN, and you can see that Microsoft's ROAs load normally (the nerd in me finds this sooo cool):

Figure 6: "Associate details" with Microsoft's handle, which is at ARIN. IPAM discovers the CIDRs and ROAs from public data. On NIC.BR this list comes back empty.

Step 3: delegate at the RIR

!!! Stop here if you already have ROAs in hosted RPKI!!! Switching from hosted to delegated is not make-before-break everywhere. On LACNIC the switch is manual, and on Registro.br you have to disable the hosted RPKI before configuring the delegation. In both cases your current ROAs can disappear before IPAM creates the new ones, and your prefixes fall back to NotFound in the meantime. If that's your case:
  • export the list of current ROAs (prefix, ASN, max length) before touching anything;
  • do the switch in a change window;
  • right after Step 5, check from outside, in a public validator, that every ROA on your list exists again.
On Registro.br, the path is Numeração (numbering) and then Configurar RPKI (configure RPKI), at the bottom of the page:

Figure 7: Numeração (numbering) screen on Registro.br.

Figure 8: RPKI configuration on Registro.br.
Paste the content of  child-request.xml :

Figure 9: where the child request goes.
The RIR answers with the parent response XML, which carries  parent_handle ,  child_handle ,  service_uri  and  parent_bpki_ta . Download the file.

Figure 10: RPKI enabled and the parent response ready to download.

Step 4: enable the association

This is the step that puts the delegation live. In the console, open the association, click Enable, paste the parent response and click Parse XML. The console fills in the five fields the API needs.


Figure 11: enabling the association.
The CLI equivalent is  aws ec2 enable-ipam-internet-registry-association  with  --rpki-version ,  --service-uri ,  --child-handle ,  --parent-handle  and  --parent-bpki-ta  taken from the XML. Here the console is the simpler path.
When the state reaches  enable-complete , IPAM is your child CA. On ARIN, RIPE NCC and APNIC, the pre-created ROAs go live at this moment, which is why the inventory comes first. On NIC.BR and LACNIC nothing is signed yet: the ROA for each prefix is created in the next step.

Step 5: provision the prefix

Create a public BYOIP pool ( --public-ip-source byoip ,  --aws-service ec2 , in the public scope; the template in the repository already does this) and provision the prefix into it:
aws ec2 provision-ipam-pool-cidr \
--ipam-pool-id ipam-pool-021e97070aa08c386 \
--cidr 203.0.113.0/24 \
--cidr-authorization-context Message="CoveredByInternetRegistryAssociation",Signature=""
The empty signature is not a typo. In classic BYOIP, you prove you own the block with a message signed by your key and a self-signed certificate in the RDAP record. With the association active, the RIR has already certified IPAM as your child CA, so that proof becomes redundant and this literal message takes its place.

Without delegated RPKI
With delegated RPKI
CIDR authorization
Signed message in  --cidr-authorization-context 
Same parameter, with  Message="CoveredByInternetRegistryAssociation",Signature="" 
Proof of ownership
WHOIS/RDAP or a DNS TXT record
IPAM checks the association's CIDRs
ROA
Created by hand at the RIR before announcing
Created at provisioning
Renewal
Manual
AWS renews it
Before announcing the prefix, compare the ROAs IPAM created with your inventory:
aws ec2 get-ipam-internet-registry-association-cidrs --region us-east-1 \
--ipam-internet-registry-association-id ipam-internet-registry-assoc-015a7e704bf075179
If everything checks out, announce it as you usually do with BYOIP.

Step 6: verify and monitor

From now on there are two things to watch: whether someone is announcing inside your range, and whether your ROA is silently expiring.
In IPAM > Monitoring > Route monitoring you see the RPKI coverage (Valid, Invalid, NotFound), the ROA strength (Strict, Permissive) and the routes with overlaps. The same data comes out of the CLI with  aws ec2 get-ipam-route-protection-findings .

Figure 12: Route monitoring dashboard (illustrative example based on the AWS documentation).
This is an excerpt from the AWS documentation's finding example, with the ASN swapped for the one used in this article:
{
"Cidr": "203.0.113.0/24",
"Asn": "64512",
"RpkiStatus": "valid",
"RpkiStrength": "strict",
"Roas": [
{ "Asn": "64512", "Prefix": "203.0.113.0/24", "MaxLength": 24, "Match": true, "Expiration": "2027-06-15T00:00:00Z" }
],
"RouteOverlaps": [
{ "Prefix": "203.0.113.128/25", "Asn": "64513", "DetectedAt": "2026-03-10T15:45:00+00:00" }
]
}
The ROA is valid and Strict and, even so, there is a /25 announced by another ASN inside the /24, which is exactly what Pakistan Telecom did to YouTube.
The field to look at is  RouteOverlaps : a prefix more specific than yours, announced by another ASN (the 2008 pattern). It's the same question my  show ip bgp ... | exclude  used to answer, except now it's asked all the time, across every account and Region, and from more vantage points than one router's peers.
That solves one pain (having a ROA). For the other one (monitoring), we'll use good old CloudWatch with the  RoaExpiration  metric. It's measured in days and has four dimensions ( Cidr ,  RoaPrefix ,  Asn ,  MaxLength ), and you need all four to target a single ROA. Create the alarm in the same account and Region where IPAM publishes the metrics.
aws cloudwatch put-metric-alarm \
--alarm-name "IPAM-RoaExpiration-203.0.113.0-24" \
--namespace "AWS/IPAM" --metric-name RoaExpiration \
--dimensions Name=Cidr,Value=203.0.113.0/24 Name=RoaPrefix,Value=203.0.113.0/24 Name=Asn,Value=64512 Name=MaxLength,Value=24 \
--statistic Minimum --period 86400 --evaluation-periods 1 \
--threshold 30 --comparison-operator LessThanOrEqualToThreshold \
--treat-missing-data notBreaching \
--alarm-actions <sns-topic-arn> # always good to get an email or open a ticket

Figure 13: the RoaExpiration alarm, created.
Why these values:
  • Minimum over 86400 seconds: the metric counts days, so one data point a day is enough, and Minimum takes the worst case of the day.
  • 30 days: IPAM renews well before expiration, so a ROA that gets this close means renewal failed. Thirty days give you time to open a support case and, in the worst case, recreate the ROA by hand before it expires.
  • notBreaching: a deliberate trade-off. If the ROA disappears entirely, the metric disappears with it and this alarm stays quiet. The findings cover that case, because the prefix shows up as NotFound. If you'd rather be alerted when data is missing too, use  breaching  and accept some noise during changes.

Step 7: ROAs for prefixes that stay on-premises

Say you have four /24s, move one to AWS and keep three in your data center. The three that stayed also need ROAs, and IPAM can sign those ROAs through routing policy registrations (RPR), that is, a prefix plus a list of ASNs, one ROA per ASN, under the same association.
aws ec2 create-ipam-routing-policy-registration --region us-east-1 \
--ipam-id ipam-02d4b32338460e044 \
--ipam-internet-registry-association-id ipam-internet-registry-assoc-015a7e704bf075179 \
--cidr 198.51.100.0/24 --asns 64512
Register each prefix exactly as you announce it, or use  --permit-more-specific-announcements  with the max length you need, knowing that a loose max length weakens the protection. If the registration would make existing routes Invalid, IPAM refuses it, and  --force  overrides that check. Use  --force  only in a change window, after the inventory.
This is the part that replaces the Krill server for on-premises prefixes: no CA to run, back up or keep talking to the RIR. What it doesn't replace is the validator. IPAM doesn't speak RTR, so there's nothing to point your Cisco or Juniper at (Hello, AWS, this would be a great feature \o/). If you want ROV on your own edge, you still need a validator such as Routinator, and it protects the traffic your network accepts, not your prefix in other networks.

Cleanup

Order matters, because IPAM won't let you delete the association while registrations exist, and won't let you delete the pool while it has CIDRs:
  1. withdraw the announcement and delete the alarm;
  1. delete the routing policy registrations;
  1. deprovision the CIDR from the pool;
  1. delete the association and wait for  delete-complete ;
  1. delete the pool and the IPAM (or the CloudFormation stack).
The template sets  DeletionPolicy: Retain  on the association, so deleting the stack doesn't undo your delegation by accident. The full script is in the repository.
Removing the delegation at the RIR has to be done by hand, because neither CloudFormation nor any other IaC tool does it (for now). On Registro.br the option is "Desabilitar RPKI" (disable RPKI), and it removes the holder's entire RPKI configuration, not just the AWS part. BE VERY CAREFUL HERE, THIS CAN DIRECTLY IMPACT YOUR BGP ANNOUNCEMENTS.

Is it worth it?

IPAM wouldn't have saved YouTube everywhere in 2008, and it won't save you everywhere today. It keeps your ROA valid and renewed, and it tells you when someone announces inside your range. Blocking only happens in networks that run ROV, which today are roughly a quarter of them. If the expectation was to become immune to a hijack just by turning on a feature, that won't happen.
What it takes off the table is the part that used to fail silently: the CA nobody wanted to run, the ROA nobody remembered to renew and the  show ip bgp  nobody remembered to type. If you have BYOIP in production spread across several accounts and Regions, or still keep on-premises prefixes under a homemade CA, the Advanced Tier bill deserves a serious look. If you have a single /24 and a Krill that already works, stick with Krill.
I talked about this feature in our monthly live stream on AWS news (audio in Portuguese, with English subtitles):

Xero no Suvaco!!!

Sources

Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article