[PR #5736] Fetch signing keys directly from the embedded IdP #26616

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

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/5736
Author: @braginini
Created: 3/30/2026
Status: 🔄 Open

Base: mainHead: feature/use-local-keys-embedded


📝 Commits (3)

📊 Changes

8 files changed (+127 additions, -26 deletions)

View changed files

📝 go.mod (+1 -1)
📝 idp/dex/provider.go (+47 -0)
📝 management/internals/server/controllers.go (+9 -3)
📝 management/server/auth/manager.go (+14 -9)
📝 management/server/auth/manager_test.go (+4 -4)
📝 management/server/http/testing/testing_tools/channel/channel.go (+2 -2)
📝 management/server/idp/embedded.go (+9 -0)
📝 shared/auth/jwt/validator.go (+41 -7)

📄 Description

Entire-Checkpoint: 5eaefec1fa77

Describe your changes

Instead of making HTTP round-trips to the /keys endpoint when the embedded IDP is co-located with the management server, read signing keys directly from Dex storage. Non-embedded IDP setups continue using the HTTP-based key
fetching unchanged.

Changes:

  • shared/auth/jwt/validator.go: Added KeyFetcher func type and NewValidatorWithKeyFetcher constructor. refreshKeys/forceRefreshKeys delegate to a fetchKeys helper that uses the fetcher when set, otherwise falls back to HTTP.
    Exported Jwks.ExpiresInTime so external packages can set it.
  • idp/dex/provider.go: Added GetJWKS(ctx) on Provider — reads keys from storage and serializes them via jose.JSONWebKeySet (same as Dex's own handlePublicKeys/ValidationKeys).
  • management/server/idp/embedded.go: Added GetKeyFetcher() to OAuthConfigProvider interface, implemented on EmbeddedIdPManager to return provider.GetJWKS.
  • management/server/auth/manager.go: NewManager accepts optional KeyFetcher; uses NewValidatorWithKeyFetcher when non-nil.
  • management/internals/server/controllers.go: Wires key fetcher from OAuthConfigProvider into auth manager, falls back to GetLocalKeysLocation if fetcher is nil.
  • Test call sites updated to pass nil for the new KeyFetcher parameter.

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

Summary by CodeRabbit

  • Refactor

    • Enhanced JWT validation to support direct JWKS/key fetching from embedded OAuth providers, improving token verification reliability.
    • Authentication manager now conditionally uses direct key fetching when available.
  • Tests

    • Updated authentication tests to accommodate the new key-fetcher parameter.
  • Chores

    • Dependency updates to support the new JWT/key handling.

🔄 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/5736 **Author:** [@braginini](https://github.com/braginini) **Created:** 3/30/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feature/use-local-keys-embedded` --- ### 📝 Commits (3) - [`a49a052`](https://github.com/netbirdio/netbird/commit/a49a052f0578d38f399a188def0b9f3d05d80528) Fetch signing keys directly from the embedded IdP - [`8d09ded`](https://github.com/netbirdio/netbird/commit/8d09ded1dba984d926e3990076cca57835a13cdc) Fix go.mod - [`8d3e5f5`](https://github.com/netbirdio/netbird/commit/8d3e5f508c4495f4b153be2d50a54976117c45df) Fix nil jwt nil ### 📊 Changes **8 files changed** (+127 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `go.mod` (+1 -1) 📝 `idp/dex/provider.go` (+47 -0) 📝 `management/internals/server/controllers.go` (+9 -3) 📝 `management/server/auth/manager.go` (+14 -9) 📝 `management/server/auth/manager_test.go` (+4 -4) 📝 `management/server/http/testing/testing_tools/channel/channel.go` (+2 -2) 📝 `management/server/idp/embedded.go` (+9 -0) 📝 `shared/auth/jwt/validator.go` (+41 -7) </details> ### 📄 Description Entire-Checkpoint: 5eaefec1fa77 ## Describe your changes Instead of making HTTP round-trips to the /keys endpoint when the embedded IDP is co-located with the management server, read signing keys directly from Dex storage. Non-embedded IDP setups continue using the HTTP-based key fetching unchanged. Changes: - shared/auth/jwt/validator.go: Added KeyFetcher func type and NewValidatorWithKeyFetcher constructor. refreshKeys/forceRefreshKeys delegate to a fetchKeys helper that uses the fetcher when set, otherwise falls back to HTTP. Exported Jwks.ExpiresInTime so external packages can set it. - idp/dex/provider.go: Added GetJWKS(ctx) on Provider — reads keys from storage and serializes them via jose.JSONWebKeySet (same as Dex's own handlePublicKeys/ValidationKeys). - management/server/idp/embedded.go: Added GetKeyFetcher() to OAuthConfigProvider interface, implemented on EmbeddedIdPManager to return provider.GetJWKS. - management/server/auth/manager.go: NewManager accepts optional KeyFetcher; uses NewValidatorWithKeyFetcher when non-nil. - management/internals/server/controllers.go: Wires key fetcher from OAuthConfigProvider into auth manager, falls back to GetLocalKeysLocation if fetcher is nil. - Test call sites updated to pass nil for the new KeyFetcher parameter. ## 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 - [ ] 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 - [x] 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 is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Enhanced JWT validation to support direct JWKS/key fetching from embedded OAuth providers, improving token verification reliability. * Authentication manager now conditionally uses direct key fetching when available. * **Tests** * Updated authentication tests to accommodate the new key-fetcher parameter. * **Chores** * Dependency updates to support the new JWT/key handling. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <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:07:34 -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#26616