[PR #5363] [CLOSED] Migration path for legacy auth to embedded IDP #25649

Open
opened 2026-08-05 07:06:17 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/5363
Author: @calderbit
Created: 2/17/2026
Status: Closed

Base: mainHead: feat/legacy-auth-migration


📝 Commits (3)

  • 7a10fa6 management support for idp seed info
  • 9769397 implemented support for activity store
  • a1d8c27 reduce cognitive load on modules IdpManager function

📊 Changes

13 files changed (+1138 additions, -1 deletions)

View changed files

📝 idp/dex/provider_test.go (+292 -0)
📝 management/internals/server/modules.go (+31 -1)
📝 management/server/activity/store.go (+7 -0)
📝 management/server/activity/store/sql_store.go (+26 -0)
📝 management/server/activity/store/sql_store_test.go (+149 -0)
📝 management/server/idp/embedded.go (+3 -0)
management/server/idp/migration/migration.go (+151 -0)
management/server/idp/migration/migration_test.go (+307 -0)
📝 management/server/store/sql_store.go (+73 -0)
📝 management/server/store/store.go (+2 -0)
📝 management/server/store/store_mock.go (+29 -0)
📝 management/server/user.go (+13 -0)
📝 management/server/user_test.go (+55 -0)

📄 Description

Describe your changes

Add support for seeding an external IdP connector via the IDP_SEED_INFO environment variable when using the Embedded IdP (Dex), enabling automatic migration of existing user IDs to the Dex-encoded format.

How it works:

  1. Self-hosted instance operator sets IDP_SEED_INFO to a base64-encoded JSON connector config (OIDC)
  2. On startup, the connector is upserted into the Dex static connectors list
  3. After initialization, a migration hook iterates all users — any user whose ID cannot be decoded as a Dex user ID is re-encoded with the seeded connector ID and
    atomically updated in the database across all referencing tables (personal_access_tokens, peers, user_invites, accounts, etc.) in a single transaction with deferred
    foreign key constraints
  4. Already-migrated users (valid Dex-encoded IDs) are skipped

IDP_SEED_INFO example:

{
  "type": "oidc",
  "name": "Zitadel",
  "id": "zitadel",
  "config": {
    "issuer": "https://server.netbird.io/",
    "clientID": "360335580288057352",
    "clientSecret": "<secret>",
    "redirectURI": "https://server.netbird.io/oauth2/callback"
  }
}

Extra changes

  • This PR includes support for NB_IDP_MIGRATION_DRY_RUN=true which will output in console logs with the planned oldId -> newId for validation, found it useful to verify that the encoded newId properly matched the oldId + the provided IDP id.
  • I also included a small code path under management/server/user.go:235 which will keep the user name and email updated with what its received from the JWT token.

TODO

  • Handle migration of IDs for events / deleted_user tables
  • Write documentation PR
  • Test with more providers to make sure no ID matching issues are present

Stack

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)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__


🔄 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/5363 **Author:** [@calderbit](https://github.com/calderbit) **Created:** 2/17/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/legacy-auth-migration` --- ### 📝 Commits (3) - [`7a10fa6`](https://github.com/netbirdio/netbird/commit/7a10fa61c78b29e3cbbd9cab21fe0d1db5de8211) management support for idp seed info - [`9769397`](https://github.com/netbirdio/netbird/commit/97693973477d39f9af7e97a2653035cd1f91d47a) implemented support for activity store - [`a1d8c27`](https://github.com/netbirdio/netbird/commit/a1d8c275ca0eb9983338aaace6dd1285cc481466) reduce cognitive load on modules IdpManager function ### 📊 Changes **13 files changed** (+1138 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `idp/dex/provider_test.go` (+292 -0) 📝 `management/internals/server/modules.go` (+31 -1) 📝 `management/server/activity/store.go` (+7 -0) 📝 `management/server/activity/store/sql_store.go` (+26 -0) 📝 `management/server/activity/store/sql_store_test.go` (+149 -0) 📝 `management/server/idp/embedded.go` (+3 -0) ➕ `management/server/idp/migration/migration.go` (+151 -0) ➕ `management/server/idp/migration/migration_test.go` (+307 -0) 📝 `management/server/store/sql_store.go` (+73 -0) 📝 `management/server/store/store.go` (+2 -0) 📝 `management/server/store/store_mock.go` (+29 -0) 📝 `management/server/user.go` (+13 -0) 📝 `management/server/user_test.go` (+55 -0) </details> ### 📄 Description ## Describe your changes Add support for seeding an external IdP connector via the IDP_SEED_INFO environment variable when using the Embedded IdP (Dex), enabling automatic migration of existing user IDs to the Dex-encoded format. ### How it works: 1. Self-hosted instance operator sets `IDP_SEED_INFO` to a base64-encoded JSON connector config (OIDC) 2. On startup, the connector is upserted into the Dex static connectors list 3. After initialization, a migration hook iterates all users — any user whose ID cannot be decoded as a Dex user ID is re-encoded with the seeded connector ID and atomically updated in the database across all referencing tables (personal_access_tokens, peers, user_invites, accounts, etc.) in a single transaction with deferred foreign key constraints 4. Already-migrated users (valid Dex-encoded IDs) are skipped `IDP_SEED_INFO` example: ``` { "type": "oidc", "name": "Zitadel", "id": "zitadel", "config": { "issuer": "https://server.netbird.io/", "clientID": "360335580288057352", "clientSecret": "<secret>", "redirectURI": "https://server.netbird.io/oauth2/callback" } } ``` ### Extra changes - This PR includes support for `NB_IDP_MIGRATION_DRY_RUN=true` which will output in console logs with the planned `oldId -> newId` for validation, found it useful to verify that the encoded newId properly matched the oldId + the provided IDP id. - I also included a small code path under [management/server/user.go:235](https://github.com/netbirdio/netbird/pull/5363/changes#diff-998d2ca8f48ecbf2d1a259f3851048dacc8f8ae1dfc13c0e69a34e74eaae817aR235) which will keep the user name and email updated with what its received from the JWT token. ## TODO - [x] Handle migration of IDs for events / deleted_user tables - [ ] Write documentation PR - [ ] Test with more providers to make sure no ID matching issues are present ## Issue ticket number and link ## Stack <!-- branch-stack --> ### Checklist - [ ] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [ ] It is a refactor - [x] Created tests that fail without the change (if possible) > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [ ] Documentation is **not needed** for this change (explain why) ### Docs PR URL (required if "docs added" is checked) Paste the PR link from https://github.com/netbirdio/docs here: https://github.com/netbirdio/docs/pull/__ --- <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 07:06:17 -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#25649