Skip to content

Commit 7e5f9ab

Browse files
myasnikovdaniillexfrei
authored andcommitted
fix(dashboard): re-auth via /oauth2/sign_in so token-proxy mode works
The dashboard gatekeeper runs one of two mutually exclusive proxies, chosen by the cluster's oidc-enabled flag (templates/gatekeeper.yaml). /oauth2/start exists only in oauth2-proxy. The token-proxy branch registers only sign_in, sign_out and userinfo under the /oauth2 prefix, so there /oauth2/start falls through to the catch-all reverse-proxy handler, which does not re-verify the token. With a present but expired cookie it proxies the request to the console upstream, the SPA reloads, gets a 401 again and loops. /oauth2/sign_in is the one entry point both modes implement, so the default 401 handler goes there. oauth2-proxy's sign_in hands straight off to OAuthStart because the gatekeeper passes --skip-provider-button, and it resolves rd through the same app-director, so the OIDC path behaves as it does through /oauth2/start. token-proxy serves its token form there. It does not honour rd yet, so after sign-in the user lands on / instead of looping. Assisted-by: LLM Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent badbec6 commit 7e5f9ab

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎packages/system/dashboard/images/console/apps/console/src/__tests__/k8s-client/client.unauthorized.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe("K8sClient onUnauthorized (401) handling", () => {
110110
})
111111

112112
describe("K8sClient default unauthorized handler", () => {
113-
it("redirects to /oauth2/start with the current location preserved as rd", async () => {
113+
it("redirects to /oauth2/sign_in with the current location preserved as rd", async () => {
114114
// jsdom's location.assign is non-configurable, so swap the whole object.
115115
const original = window.location
116116
const assign = vi.fn()
@@ -128,10 +128,12 @@ describe("K8sClient default unauthorized handler", () => {
128128
)
129129

130130
// Relative rd (no origin) preserves the destination without tripping
131-
// oauth2-proxy's open-redirect rejection.
131+
// oauth2-proxy's open-redirect rejection. The target must stay
132+
// /oauth2/sign_in: token-proxy (oidc-enabled=false) serves no
133+
// /oauth2/start, so that path falls through to its catch-all.
132134
expect(assign).toHaveBeenCalledTimes(1)
133135
expect(assign).toHaveBeenCalledWith(
134-
`/oauth2/start?rd=${encodeURIComponent("/apps/postgres?tab=config#x")}`,
136+
`/oauth2/sign_in?rd=${encodeURIComponent("/apps/postgres?tab=config#x")}`,
135137
)
136138
} finally {
137139
Object.defineProperty(window, "location", {

‎packages/system/dashboard/images/console/packages/k8s-client/src/client.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ export interface K8sClientConfig {
44
onUnauthorized?: () => void
55
}
66

7+
// /oauth2/sign_in is the only sign-in entry both gatekeeper modes serve:
8+
// oauth2-proxy jumps straight to the provider there (--skip-provider-button)
9+
// and token-proxy renders its token form; /oauth2/start is oauth2-proxy-only.
710
function defaultOnUnauthorized(): void {
811
if (typeof window === "undefined") return
912
const rd = window.location.pathname + window.location.search + window.location.hash
10-
window.location.assign(`/oauth2/start?rd=${encodeURIComponent(rd)}`)
13+
window.location.assign(`/oauth2/sign_in?rd=${encodeURIComponent(rd)}`)
1114
}
1215

1316
export class K8sApiError extends Error {

0 commit comments

Comments
 (0)