feat: GeoIP support - #315
Conversation
There was a problem hiding this comment.
Pull request overview
Adds GeoIP-based IP enrichment (ASN org, VPN heuristic, country/city) and stores/returns this metadata alongside login sessions.
Changes:
- Add
IpEnrichmentService(MaxMind GeoLite2 ASN/City DB support) plus related options/interfaces/data model. - Extend session creation/storage/response mapping to include enrichment fields (
AsnOrg,IsVpn,CountryCode,City). - Wire up DI + configuration registration and call enrichment during session creation.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Directory.Packages.props | Adds central package version for MaxMind.GeoIP2. |
| Common/Common.csproj | Adds MaxMind.GeoIP2 package reference to Common. |
| Common/Services/Geo/IIpEnrichmentService.cs | Introduces enrichment service abstraction. |
| Common/Services/Geo/IpEnrichmentService.cs | Implements GeoLite2 DB loading + enrichment logic + VPN heuristic. |
| Common/Services/Geo/IpEnrichmentData.cs | Adds enrichment DTO/record. |
| Common/Options/GeoOptions.cs | Adds configuration options for GeoLite2 DB paths. |
| Common/Extensions/ConfigurationExtensions.cs | Adds RegisterGeoOptions() builder extension. |
| Common/OpenShockServiceHelper.cs | Registers IIpEnrichmentService in DI. |
| Common/OpenShockControllerBase.cs | Enriches remote IP and passes enrichment into session creation. |
| Common/Services/Session/ISessionService.cs | Extends CreateSessionAsync signature to accept optional enrichment. |
| Common/Services/Session/SessionService.cs | Persists enrichment fields into LoginSession. |
| Common/Redis/LoginSessions.cs | Adds enrichment fields to Redis session model. |
| API/Program.cs | Registers geo options during API startup. |
| API/Models/Response/LoginSessionResponse.cs | Exposes enrichment fields in API session response. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
# Conflicts: # API/Program.cs # Common/Extensions/ConfigurationExtensions.cs
|
Ready to review this PR? Stage has broken it down into 5 individual chapters for you: Chapters generated by Stage for commit b24627d on Jul 1, 2026 2:34pm UTC. |
- Register a default GeoOptions via TryAddSingleton in AddOpenShockServices so hosts that don't call RegisterGeoOptions() (Cron, LiveControlGateway, SeedE2E) can still activate IIpEnrichmentService instead of failing DI at startup. - Make IpEnrichmentData.IsVpn nullable so an unavailable/failed ASN lookup stays 'unknown' (null) rather than being recorded as 'not VPN' (false). - Rename GeoOptions section to 'OpenShock:Geo' to match the repo's config convention.
…ent-geo-vpn # Conflicts: # Common/OpenShockControllerBase.cs # Common/OpenShockServiceHelper.cs # Common/Services/Session/ISessionService.cs # Common/Services/Session/SessionService.cs
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (14)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe API adds GeoLite2 IP enrichment to login sessions and live control gateway assignment. It stores available ASN, VPN, country, and city data in login sessions. Gateway coordinates are published and used to narrow assignment candidates by proximity. ChangesGeolocation enrichment and gateway assignment
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~45 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant AssignLCG
participant IIpEnrichmentService
participant LCGNodeProvisioner
participant LcgNode
AssignLCG->>IIpEnrichmentService: Enrich request remote IP
IIpEnrichmentService-->>AssignLCG: Return client location
AssignLCG->>LCGNodeProvisioner: Select node using country and location
LCGNodeProvisioner->>LcgNode: Read country, coordinates, and load
LCGNodeProvisioner-->>AssignLCG: Return selected node
Merge Risk: ⚪ Minimal · up to GeoIP enrichment remains optional, and coordinate-based gateway selection preserves country and missing-coordinate fallbacks. Gateway publication supports the intended expiry behavior; the change is mergeable subject to normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change adds location data to sessions and influences gateway selection while preserving the inspected authorization controls. No new security vulnerability was established, but deployment trust and data-lifecycle assumptions remain partly unverified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The keyword list carried datacenter ASNs (amazon, google, akamai, ovh), so corporate and cloud egress was flagged as VPN, and substring matching let "pia" match "Olympia". Matching is now whole-token over consumer VPN vendors.
# Conflicts: # Directory.Packages.props
|
@coderabbitai full review |
✅ Action performedFull review finished. |
Add an IP enrichment service backed by the MaxMind GeoLite2 ASN and City databases, configured under OpenShock:Geo (AsnDbPath, CityDbPath). When neither database is available the service returns null and callers fall back to the previous behavior. Login sessions: - Record ASN organization, VPN flag, country code and city when a session is created, and expose them on LoginSessionResponse. - IsVpn is nullable so a failed or missing ASN lookup stays unknown rather than being reported as "not VPN". - VPN detection matches whole tokens against consumer VPN providers only, so datacenter/cloud egress is not flagged and substrings like "pia" in "Olympia" don't match. Gateway assignment: - LCGs can advertise an optional Latitude/Longitude, published on the LcgNode in Redis. - Hub assignment still picks the closest region by country, then narrows it by great-circle distance to the hub's GeoIP location when every node in that region has coordinates. - LcgKeepAlive now overwrites the whole node on every beat instead of diffing fields, which also backfills nodes written by older builds. A default GeoOptions is registered in AddOpenShockServices so hosts that don't configure Geo (Cron, LCG, SeedE2E) still resolve the service. Co-authored-by: LucHeart <luc@luc.cat>
Summary by CodeRabbit