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

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

Original Pull Request: https://github.com/netbirdio/netbird/pull/5363

State: closed
Merged: No


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/__

**Original Pull Request:** https://github.com/netbirdio/netbird/pull/5363 **State:** closed **Merged:** No --- ## 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/__
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#25655