fix(api): restore reverse-proxy IP resolution for /api/me#78
fix(api): restore reverse-proxy IP resolution for /api/me#78bashrusakh wants to merge 4 commits into
Conversation
📝 WalkthroughWalkthroughThis PR reworks peer identity to be scoped by (Ip, Asn) instead of Ip alone. It adds a unique database index migration, a ChangesPeer identity by IP+ASN
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant ManagementApi
participant PeerStore
participant Database
Client->>ManagementApi: GET /api/me?asn=...
ManagementApi->>ManagementApi: ResolveClientIp(headers, remoteEndpoint)
ManagementApi->>PeerStore: GetPeersByIp(clientIp)
PeerStore->>Database: Query Peers by Ip
Database-->>PeerStore: Matching rows
PeerStore-->>ManagementApi: List of PeerInfo
ManagementApi->>ManagementApi: Filter by asn
alt no match
ManagementApi-->>Client: peer: null
else multiple matches
ManagementApi-->>Client: 409 Ambiguous peer
else single match
ManagementApi-->>Client: peer info with communities
end
Related issues: Suggested labels: enhancement, api, database Suggested reviewers: ruhex 🐰 A rabbit hops where IPs collide, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
BGPLite.Tests/ManagementApiClientIpTests.cs (1)
1-36: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winTests only cover the currently-implemented (unconditionally-trusting) behavior.
These tests validate the current header precedence but don't exercise a scenario where headers should be ignored (e.g., request not from a trusted proxy). Once trusted-proxy validation is added per the
ResolveClientIpcomment, add regression coverage for the "untrusted source falls back to remote endpoint despite spoofed headers" case.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@BGPLite.Tests/ManagementApiClientIpTests.cs` around lines 1 - 36, Add a regression test in ManagementApiClientIpTests for the untrusted-source case: when ResolveClientIp receives spoofed X-Real-IP / X-Forwarded-For values but the request is not from a trusted proxy, it should ignore those headers and return the remote endpoint. Reuse the existing ResolveClientIp test pattern, but introduce a scenario that exercises the trusted-proxy validation path once it is implemented.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@BGPLite.Tests/ManagementApiClientIpTests.cs`:
- Around line 1-36: Add a regression test in ManagementApiClientIpTests for the
untrusted-source case: when ResolveClientIp receives spoofed X-Real-IP /
X-Forwarded-For values but the request is not from a trusted proxy, it should
ignore those headers and return the remote endpoint. Reuse the existing
ResolveClientIp test pattern, but introduce a scenario that exercises the
trusted-proxy validation path once it is implemented.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: a3dbb06c-8e8c-4e6e-b73b-83d83b81d958
📒 Files selected for processing (8)
BGPLite.Api/BGPLite.Api.csprojBGPLite.Api/BgpDbContext.csBGPLite.Api/ManagementApi.csBGPLite.Api/PeerStore.csBGPLite.Tests/BGPLite.Tests.csprojBGPLite.Tests/ManagementApiClientIpTests.csBGPLite.Tests/PeerStoreKeyingTests.csREADME.md
💤 Files with no reviewable changes (1)
- BGPLite.Api/BgpDbContext.cs
Summary
X-Real-IP/X-Forwarded-Forresolution in/api/mebefore peer lookup.?asn=disambiguation for shared-IP peers.Why
Validation
dotnet test BGPLite.Tests/BGPLite.Tests.csproj --no-restoredotnet format BGPLite.sln --verify-no-changesRisk
/api/meagain trusts standard reverse-proxy headers when present, matching the prior behavior.Closes #23
Summary by CodeRabbit
New Features
Bug Fixes