feat(auth): support separate OIDC discovery URL for back-channel calls#369
Merged
Conversation
Add an optional oidc_discovery_url (NEBI_AUTH_OIDC_DISCOVERY_URL) that decouples where nebi fetches .well-known/openid-configuration from the issuer it validates in the token's "iss" claim. In split-horizon deployments the public issuer URL that browsers use may not be resolvable from inside the cluster, so OIDC initialization fails on the discovery fetch and never recovers. When oidc_discovery_url is set, discovery is fetched from it (e.g. an in-cluster Keycloak Service) while "iss" is still validated against oidc_issuer_url, using oidc.InsecureIssuerURLContext to tell go-oidc the two are intentionally different. When unset, behavior is unchanged: discovery and issuer validation both use oidc_issuer_url.
✅ Deploy Preview for nebi-docs canceled.
|
aktech
approved these changes
Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #371
What
Adds an optional
oidc_discovery_url(NEBI_AUTH_OIDC_DISCOVERY_URL) that decouples where nebi fetches.well-known/openid-configurationfrom the issuer it validates in the token'sissclaim.Why
In split-horizon deployments the public issuer URL that browsers use is not resolvable from inside the cluster. Today nebi uses a single
oidc_issuer_urlfor both discovery andissvalidation, so OIDC init fails on the discovery fetch and loops forever:This came up deploying the nebari-nebi-pack into a private cluster where Keycloak sits behind an external gateway (browsers can reach it, in-cluster pods can't). See nebari-dev/nebari-nebi-pack#13.
How
When
oidc_discovery_urlis set, discovery is fetched from it (e.g. an in-cluster KeycloakService) whileissis still validated againstoidc_issuer_url, usingoidc.InsecureIssuerURLContextto tell go-oidc the two are intentionally different. When unset, behavior is unchanged — discovery and issuer validation both useoidc_issuer_url.Operator note
This is the same issuer-vs-discovery split that nebari-dev/nebari-operator#112 is tracking for the gateway's
SecurityPolicy.oidc. This PR covers nebi's own direct OIDC (used by the CLI device-code flow); the two should stay consistent.Deployment caveat (not a code concern)
Discovery is necessary but not sufficient. After discovery, the endpoints in the document (
token_endpoint,jwks_uri) are what nebi calls for code exchange and token verification. The IdP must return in-cluster-reachable URLs for those — for Keycloak that meanshostname-backchannel-dynamic=true(KC_HOSTNAME_STRICT_BACKCHANNEL=false) so that fetching discovery via the internal URL echoes internal back-channel URLs. nebi leaves the endpoints as the IdP returns them.Tests
internal/auth/oidc_test.go:DiscoveryURLwith a mismatched (public) issuer succeedsDiscoveryURL) still rejects anissthat doesn't match the discovery URLgo test ./internal/auth/...,go vet, andgofmtall clean.Related Issues