fix: default Keycloak issuer to keycloakx layout (port 80, /auth)#140
Open
viniciusdc wants to merge 1 commit into
Open
fix: default Keycloak issuer to keycloakx layout (port 80, /auth)#140viniciusdc wants to merge 1 commit into
viniciusdc wants to merge 1 commit into
Conversation
The generated SecurityPolicy built its OIDC issuer from
DefaultKeycloakServicePort (8080) and DefaultKeycloakContextPath ("")
even though DefaultKeycloakServiceName already targets the
codecentric/keycloakx chart, which serves HTTP on port 80 under /auth.
Envoy's OAuth2 filter then dialed :8080 with no /auth prefix, OIDC
discovery timed out, and requests to an auth-enabled NebariApp returned
HTTP 500 instead of redirecting to Keycloak -- reproducible straight
from the quickstart.
Set the defaults to port 80 and /auth so the issuer is reachable out of
the box, and set KEYCLOAK_ISSUER_SERVICE_PORT / KEYCLOAK_ISSUER_CONTEXT_PATH
explicitly in the manager manifest so the deployed issuer is obvious and
easy to retarget. Root-path Keycloak deployments can override both via env.
Add a reconciler-level test asserting the split-endpoint behavior end to
end: the back-channel Token endpoint stays in-cluster while the
browser-facing Authorization and EndSession endpoints use the public
ExternalURL host.
Closes #136
Closes #113
Docker Images BuiltImages pushed to Quay.io for branch
Test the operator: kubectl apply -k https://github.com/nebari-dev/nebari-operator.git/config/default?ref=fix/oidc-issuer-keycloakx-defaults
kubectl set image deployment/nebari-operator-controller-manager manager=quay.io/nebari/nebari-operator:fix-oidc-issuer-keycloakx-defaults -n nebari-operator-system |
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.
Summary
Enabling auth on a
NebariAppreturned HTTP 500 instead of redirecting to Keycloak, reproducible straight from the operator's own quickstart. The generatedSecurityPolicypointed Envoy at an unreachable Keycloak issuer URL, so OIDC discovery timed out.This is PR 1 of the routing/SecurityPolicy consolidation tracked in #139.
Root cause
The OIDC issuer is built from
DefaultKeycloakServicePort(8080) andDefaultKeycloakContextPath(""). ButDefaultKeycloakServiceNamealready hardcodes thekeycloak-keycloakx-httpservice, and the codecentric/keycloakx chart serves HTTP on port 80 under/auth(itshttp.relativePath, whichdev/scriptsalso set explicitly). The defaults were internally inconsistent: they named the keycloakx service but used a port/path that service never listens on.Result — the operator generated:
Envoy dialed
:8080(no listener) →dial tcp ...:8080: i/o timeout→SecurityPolicystuckAccepted=False→ 500.Change
constants.go—DefaultKeycloakServicePort8080 → 80,DefaultKeycloakContextPath"" → "/auth", so the issuer is reachable out of the box on the chart the operator already targets. Both remain overridable viaKEYCLOAK_ISSUER_SERVICE_PORT/KEYCLOAK_ISSUER_CONTEXT_PATHfor a root-path Keycloak.config/manager/manager.yaml— set those two env vars explicitly so the deployed issuer is obvious in the manifest and easy to retarget.reconciler_test.go— newTestBuildSecurityPolicySpec_KeycloakSplitEndpointsexercising the split-endpoint behavior end to end with a realKeycloakProvider: Token stays in-cluster, Authorization/EndSession use the publicExternalURLhost. Full-URL assertions also guard the issuer fix here.auth_test.go— updated the default-derived expectations; the explicit-override case (9090/ explicit"") is unchanged.Test plan
go build ./...andgo vet ./...clean.go test ./internal/config/... ./internal/controller/reconcilers/auth/...— pass, including the new split-endpoint test.internal/controllerenvtest suite (TestControllers) fails locally on a scheme-registration gap that also fails on cleanmain(unrelated to this change; needsmake test's CRD setup).Scope
provider.issuermust trackExternalURLunder a KeycloakfrontendUrl) — that's an open investigation, deferred per Epic: Routing & SecurityPolicy consolidation #139. The new test pins current behavior (issuer stays in-cluster) so OIDC SecurityPolicy.Issuer field stays on in-cluster URL; investigate iss-claim mismatch with Keycloak frontendUrl deployments #112's eventual change is a deliberate, visible diff.