pdb_rir_status script removed live ASN#81
Open
gablooge wants to merge 3 commits into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #81 +/- ##
==========================================
+ Coverage 87.98% 88.96% +0.97%
==========================================
Files 20 20
Lines 1182 1241 +59
==========================================
+ Hits 1040 1104 +64
+ Misses 142 137 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: pdb_rir_status deleted a live ASN due to unvalidated RIR data (#2001)
Background
pdb_rir_statusdeleted AS219272 from PeeringDB even though the ASN was—and had been for days—allocatedin RIPE's published delegated-stats file and live in RDAP/whois.Root cause
The deletion decision trusted a single, unvalidated data source: PeeringDB's local copy of the RIR
delegated-*-extended-latestsnapshot.get_status(asn)returnsNonein three indistinguishable situations:RIPE republishes delegated statistics daily, so a newly allocated ASN may not appear in the snapshot for up to a day or two. Any of these cases caused a network to be flagged, warned, and (after
KEEP_RIR_STATUS) deleted. WithKEEP_RIR_STATUS=1, the deletion window is actually shorter than that publication lag.Two gaps combined to make this happen for a live ASN:
No integrity checking on the downloaded file.
The fetch performed neither
raise_for_status()nor any completeness validation, so truncated responses or error pages could be written to the cache and trusted. Since delegated ASN files are large, an interrupted download simply omits records.No independent confirmation before an irreversible delete.
Absence from the local delegated snapshot alone was sufficient to delete a network, even though the delegated file is only a daily snapshot and naturally lags real-world allocations.
Fix — defense in depth
rdap(RIRAssignmentLookup) — trust the data before using itraise_for_status()and a completeness check that compares the parsed ASN record count against the file's own<rir>|*|asn|*|N|summaryrecord.RIRAssignmentErroronly when no valid dataset can be obtained.os.replace()) so interrupted writes cannot leave partial cache files behind.timedelta.days, fixing the previous behavior wherecache_days=1could actually refresh after nearly 48 hours.Result:
get_status()returningNonenow means "absent from a validated, complete delegated file" instead of "absent from whatever happened to be cached."peeringdb(pdb_rir_status) — verify before deletingBefore performing the irreversible
net.delete():The RDAP lookup only runs for the small number of networks that have already passed every other deletion gate, so the additional traffic is negligible.
This behavior is controlled by the new setting:
RIR_STATUS_VERIFY_BEFORE_DELETE(default:True)These two layers use independent data sources (delegated snapshot vs. live RDAP) and only make deletion more conservative. A false deletion would now require both sources to be wrong simultaneously.
Settings
RIR_STATUS_VERIFY_BEFORE_DELETE(bool, defaultTrue) — enables the pre-delete RDAP verification.Testing
rdapAdded tests covering:
Sample fixtures were added under
tests/data/assignment/.peeringdbAdded tests covering:
Existing timer-gated deletion tests explicitly disable the verification flag.
Rollout
The PeeringDB verification uses only the already-released
rdapAPI, so it becomes effective immediately.The
rdaphardening requires a newrdaprelease and a dependency bump in PeeringDB before those protections take effect there.Deferred follow-ups
load_dataabort in aCommandErrorto present a clean operator-facing error instead of a traceback (cosmetic only; behavior is unchanged).