diff --git a/helm/kagent/templates/_helpers.tpl b/helm/kagent/templates/_helpers.tpl index d570e067f..51305abc2 100644 --- a/helm/kagent/templates/_helpers.tpl +++ b/helm/kagent/templates/_helpers.tpl @@ -269,3 +269,27 @@ imagePullSecrets: {{- end -}} {{- end -}} +{{/* +Body of oauth2-proxy's custom sign_in.html template (see +templates/oauth2-proxy-templates.yaml). Kept as its own named template, rather +than inline in that ConfigMap, so oauth2-proxy.extraEnv in values.yaml can hash +the content. + +oauth2-proxy renders this as its own Go html/template (not a Helm template) when +it shows the sign-in page to an unauthenticated visitor -- e.g. a request to +/agents/foo is served this page at /oauth2/sign_in?rd=%2Fagents%2Ffoo. +`Redirect` is oauth2-proxy's template variable carrying that original +destination (escaped with a Helm string-literal action so Helm emits it for +oauth2-proxy to evaluate, instead of trying to evaluate it itself). It is +forwarded to kagent's branded /login page. +*/}} +{{- define "kagent.oauth2ProxySignInHTML" -}} + + +
+ + + +Redirecting to login... + +{{- end -}} diff --git a/helm/kagent/templates/oauth2-proxy-templates.yaml b/helm/kagent/templates/oauth2-proxy-templates.yaml index 0223c9d21..70397c527 100644 --- a/helm/kagent/templates/oauth2-proxy-templates.yaml +++ b/helm/kagent/templates/oauth2-proxy-templates.yaml @@ -7,13 +7,9 @@ metadata: labels: {{- include "kagent.labels" . | nindent 4 }} data: + # The body lives in the kagent.oauth2ProxySignInHTML named template + # (_helpers.tpl) so oauth2-proxy.extraEnv in values.yaml can hash the content to + # force a rollout when it changes. sign_in.html: | - - - - - - - Redirecting to login... - + {{- include "kagent.oauth2ProxySignInHTML" . | nindent 4 }} {{- end }} diff --git a/helm/kagent/values.yaml b/helm/kagent/values.yaml index d16588ff6..2f46c203a 100644 --- a/helm/kagent/values.yaml +++ b/helm/kagent/values.yaml @@ -978,6 +978,9 @@ oauth2-proxy: # Cluster-specific OIDC settings - override these per deployment # These are set as env vars and referenced in args for easy patching extraEnv: + # Forces a rollout whenever the sign_in.html ConfigMap's content changes. + - name: KAGENT_OAUTH2_PROXY_SIGNIN_TEMPLATE_CHECKSUM + value: '{{ include "kagent.oauth2ProxySignInHTML" . | sha256sum }}' - name: OIDC_ISSUER_URL value: "" - name: OIDC_REDIRECT_URL diff --git a/ui/src/app/login/page.tsx b/ui/src/app/login/page.tsx index c64316334..1a559e10e 100644 --- a/ui/src/app/login/page.tsx +++ b/ui/src/app/login/page.tsx @@ -1,12 +1,20 @@ import Link from "next/link"; import KagentLogo from "@/components/kagent-logo"; +import { sanitizeRedirect } from "@/lib/loginRedirect"; import { skipToContentLinkClassName } from "@/lib/skipToContent"; import { cn } from "@/lib/utils"; // SSO redirect path - defaults to oauth2-proxy's start endpoint const SSO_REDIRECT_PATH = process.env.SSO_REDIRECT_PATH || "/oauth2/start"; -export default function LoginPage() { +export default async function LoginPage({ + searchParams, +}: { + searchParams: Promise<{ rd?: string }>; +}) { + const { rd } = await searchParams; + const redirectTo = sanitizeRedirect(rd); + return ( <> {/* Preload background image for faster rendering */} @@ -53,7 +61,7 @@ export default function LoginPage() {