Geographic Routing
Status: Implemented
Overview
Geographic routing allows tunnel owners to route incoming requests based on the client IP's country of origin using a MaxMind GeoLite2-Country database.
Design
GeoIP Lookup (cli/internal/edge/geoip.go)
- Loads MaxMind GeoLite2-Country database from the
JETTY_EDGE_GEOIP_DB_PATHenvironment variable on first use (lazy singleton). - Provides
LookupCountry(ip string) stringreturning an ISO 3166-1 alpha-2 country code (e.g. "US", "DE"). - Graceful fallback: if the env var is unset, the file is missing, or the IP cannot be resolved, returns an empty string. Geo rules are silently skipped when the country is unknown.
Protocol Changes (cli/internal/wsproto/proto.go)
Two new fields on RoutingRule:
| Field | Type | Description |
|---|---|---|
countries |
[]string |
ISO 3166-1 alpha-2 codes (e.g. ["US","CA"]) |
geo_invert |
bool |
When true, block listed countries instead of allowing |
Edge Routing (cli/internal/edge/edge.go)
New match_type: "geo_match" case in matchRoutingRule:
- Skip if
Countrieslist is empty. - Look up client IP country via
LookupCountry. - Skip if country is empty (DB not loaded).
- Check whether the country is in the rule's list.
- Apply
GeoInvertflag: allow-mode (false) matches when country is in the list; block-mode (true) matches when country is NOT in the list.
Bridge Validation (app/Support/TunnelRoutingRulesValidator.php)
- Accepts
geo_matchas a validmatch_type. - Validates
countriesis a non-empty array of 2-letter uppercase ISO codes. - Normalises codes to uppercase and deduplicates.
- Reads optional
geo_invertboolean (defaults tofalse).
Dependencies
github.com/oschwald/maxminddb-golangv1.13.1 (added tocli/go.mod).- MaxMind GeoLite2-Country
.mmdbfile deployed to the edge server and referenced viaJETTY_EDGE_GEOIP_DB_PATH.
Send feedback
Found an issue or have a suggestion? Let us know.