[PR #1491] [MERGED] Initial support of Geolocation service #15454

Closed
opened 2026-08-05 03:07:41 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/1491
Author: @surik
Created: 1/22/2024
Status: Merged
Merged: 1/31/2024
Merged by: @surik

Base: feature/posture-checksHead: yury/add-geolite


📝 Commits (10+)

📊 Changes

18 files changed (+333 additions, -17 deletions)

View changed files

📝 .gitignore (+2 -1)
📝 client/cmd/testutil.go (+1 -2)
📝 client/internal/engine_test.go (+1 -2)
📝 go.mod (+1 -0)
📝 go.sum (+3 -1)
infrastructure_files/download-geolite2.sh (+62 -0)
📝 management/client/client_test.go (+1 -2)
📝 management/cmd/management.go (+13 -2)
📝 management/server/account.go (+5 -1)
📝 management/server/account_test.go (+1 -1)
📝 management/server/dns_test.go (+1 -1)
management/server/geolocation/geolocation.go (+189 -0)
management/server/geolocation/geolocation_test.go (+49 -0)
📝 management/server/management_proto_test.go (+1 -1)
📝 management/server/management_test.go (+1 -1)
📝 management/server/nameserver_test.go (+1 -1)
📝 management/server/route_test.go (+1 -1)
management/server/testdata/GeoLite2-City-Test.mmdb (+0 -0)

📄 Description

Describe your changes

This pull request marks the introduction of optional support for the Geolocation service. Currently, it relies on GeoLite2 databases in mmdb format. To facilitate this, we've included a script for easy retrieval of a free copy of the city database from MaxMind:

MM_ACCOUNT_ID=... MM_LICENSE_KEY=...  ./infrastructure_files/download-geolite2.sh

Both MM_ACCOUNT_ID and MM_LICENSE_KEY can be obtained from MaxMind.

Once the script is executed, the mmdb file should be placed in the datadir. The script provides clear instructions for this process:

Process completed successfully.
Now you can place GeoLite2-City_20240126/GeoLite2-City.mmdb in the 'datadir' of the management service.
Example:
    docker compose cp GeoLite2-City_20240126/GeoLite2-City.mmdb management:/var/lib/netbird/

Initialization of the management service with this mmdb file enables the Geolocation service and allows for runtime updates of the mmdb file. A background job, triggered at intervals defined by reloadCheckInterval (currently set to 60 seconds), compares the sha256 sum of a new file with the loaded one. If they differ, the service locks, loads the new file, and then unlocks. This process typically takes only a few seconds.

It's important to note that this PR does not automate the downloading of the mmdb file. Users are expected to implement this logic independently.

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • Extended the README / documentation, if necessary

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/1491 **Author:** [@surik](https://github.com/surik) **Created:** 1/22/2024 **Status:** ✅ Merged **Merged:** 1/31/2024 **Merged by:** [@surik](https://github.com/surik) **Base:** `feature/posture-checks` ← **Head:** `yury/add-geolite` --- ### 📝 Commits (10+) - [`20d3f78`](https://github.com/netbirdio/netbird/commit/20d3f7869b0fa0ee6fc89c287600b3bb9344ab5f) Initial support of GeoLite DB - [`559f435`](https://github.com/netbirdio/netbird/commit/559f43574c1d5818bf111224ad5b83dfdc6313e7) Extend Record object - [`3d75c97`](https://github.com/netbirdio/netbird/commit/3d75c97bf5e8b144e12bc18668dde1f4a6b65488) Implement geolite2 download script - [`210b5f6`](https://github.com/netbirdio/netbird/commit/210b5f6390401ca3ed99a430f9eb7665ad5d7f71) Implement geolite reload - [`b82ca02`](https://github.com/netbirdio/netbird/commit/b82ca0257ac0ff22ea79de65a4aa239dab346f0d) Fix .gitignore - [`59bd92b`](https://github.com/netbirdio/netbird/commit/59bd92b9231d9922ec701dabef192ea0f980acb9) Rename to Geolocation - [`fd76370`](https://github.com/netbirdio/netbird/commit/fd763700ca867f91405cfe530287bd955f5de511) Address linter - [`cb96a53`](https://github.com/netbirdio/netbird/commit/cb96a531d793dca4a978d6cfd84cf1ee3ac4faa4) Pass geolocation service to account manager - [`49d08e5`](https://github.com/netbirdio/netbird/commit/49d08e5d235c8b38a21204a52c6492e61e9c8d87) Implement reloader - [`aca7ab1`](https://github.com/netbirdio/netbird/commit/aca7ab17bd67c2995167464a8668fe048a3f3504) Fix tests ### 📊 Changes **18 files changed** (+333 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+2 -1) 📝 `client/cmd/testutil.go` (+1 -2) 📝 `client/internal/engine_test.go` (+1 -2) 📝 `go.mod` (+1 -0) 📝 `go.sum` (+3 -1) ➕ `infrastructure_files/download-geolite2.sh` (+62 -0) 📝 `management/client/client_test.go` (+1 -2) 📝 `management/cmd/management.go` (+13 -2) 📝 `management/server/account.go` (+5 -1) 📝 `management/server/account_test.go` (+1 -1) 📝 `management/server/dns_test.go` (+1 -1) ➕ `management/server/geolocation/geolocation.go` (+189 -0) ➕ `management/server/geolocation/geolocation_test.go` (+49 -0) 📝 `management/server/management_proto_test.go` (+1 -1) 📝 `management/server/management_test.go` (+1 -1) 📝 `management/server/nameserver_test.go` (+1 -1) 📝 `management/server/route_test.go` (+1 -1) ➕ `management/server/testdata/GeoLite2-City-Test.mmdb` (+0 -0) </details> ### 📄 Description ## Describe your changes This pull request marks the introduction of optional support for the Geolocation service. Currently, it relies on GeoLite2 databases in `mmdb` format. To facilitate this, we've included a script for easy retrieval of a free copy of the city database from MaxMind: ```bash MM_ACCOUNT_ID=... MM_LICENSE_KEY=... ./infrastructure_files/download-geolite2.sh ``` Both `MM_ACCOUNT_ID` and `MM_LICENSE_KEY` can be obtained from [MaxMind](https://dev.maxmind.com/geoip/geolite2-free-geolocation-data). Once the script is executed, the `mmdb` file should be placed in the `datadir`. The script provides clear instructions for this process: ``` Process completed successfully. Now you can place GeoLite2-City_20240126/GeoLite2-City.mmdb in the 'datadir' of the management service. Example: docker compose cp GeoLite2-City_20240126/GeoLite2-City.mmdb management:/var/lib/netbird/ ``` Initialization of the management service with this `mmdb` file enables the Geolocation service and allows for runtime updates of the `mmdb` file. A background job, triggered at intervals defined by `reloadCheckInterval` (currently set to 60 seconds), compares the sha256 sum of a new file with the loaded one. If they differ, the service locks, loads the new file, and then unlocks. This process typically takes only a few seconds. It's important to note that this PR does not automate the downloading of the `mmdb` file. Users are expected to implement this logic independently. ## Issue ticket number and link ### Checklist - [ ] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [ ] It is a refactor - [ ] Created tests that fail without the change (if possible) - [ ] Extended the README / documentation, if necessary --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 03:07:41 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#15454