[History Server] Authenticate users against the Kubernetes TokenReview API #5204
Login form errors return JSON
Medium Severity
<!-- DESCRIPTION START -->
A failed browser POST to /login responds with a JSON body instead of the HTML login form. The form is the intended human sign-in path, so an invalid or expired token replaces the page with raw JSON and leaves no in-page way to retry.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: d1b84ad7-35b9-4cce-a56d-bc198c0efa9f -->
<!-- LOCATIONS START
historyserver/pkg/historyserver/auth.go#L252-L255
historyserver/pkg/historyserver/auth.go#L243-L246
LOCATIONS END -->
<details>
<summary>Additional Locations (1)</summary>
historyserver/pkg/historyserver/auth.go#L243-L246</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmUwZTkwZTcxLTc4MWQtNGFmZi1iMWNjLTEwZTY3NTZhMDQ1NCIsImVuY3J5cHRpb25LZXkiOiJRNmpaZ1JROXNOYl9vb3RzN015Ylk4bEVjNzFuU0F0S3RPR2FIOWVXc1BjIiwiYnJhbmNoIjoiZmVhdC9ocy10b2tlbnJldmlldy1hdXRoIiwicmVwb093bmVyIjoicmF5LXByb2plY3QiLCJyZXBvTmFtZSI6Imt1YmVyYXkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmUwZTkwZTcxLTc4MWQtNGFmZi1iMWNjLTEwZTY3NTZhMDQ1NCIsImVuY3J5cHRpb25LZXkiOiJRNmpaZ1JROXNOYl9vb3RzN015Ylk4bEVjNzFuU0F0S3RPR2FIOWVXc1BjIiwiYnJhbmNoIjoiZmVhdC9ocy10b2tlbnJldmlldy1hdXRoIiwicmVwb093bmVyIjoicmF5LXByb2plY3QiLCJyZXBvTmFtZSI6Imt1YmVyYXkiLCJwck51bWJlciI6NTIwNCwiY29tbWl0U2hhIjoiOGE2Yjc4ZDdkOGQxYzk1ZDg1Yzk1NTI0ZDk3MmE3MDYzODhhNmIwZCIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by Cursor Bugbot for commit 8a6b78d7d8d1c95d85c95524d972a706388a6b0d. Configure here.</sup>
Zero TTL caches tokens forever
Medium Severity
<!-- DESCRIPTION START -->--auth-cache-ttl is passed straight into the expirable LRU, where a TTL of 0 or a negative duration means entries never expire. That contradicts the flag text that a revoked token works for at most this long, and unlike --session-cache-ttl the value is not validated.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 9af2273e-b6d7-4193-b17b-2df23083cb0f -->
<!-- LOCATIONS START
historyserver/pkg/historyserver/auth.go#L66-L70
historyserver/cmd/historyserver/main.go#L51-L52
LOCATIONS END -->
<details>
<summary>Additional Locations (1)</summary>
historyserver/cmd/historyserver/main.go#L51-L52</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjRlNjU5MTRiLTc3MjQtNDA4OC04YjZmLTRmMmZlN2QyOTVkNCIsImVuY3J5cHRpb25LZXkiOiJ4aGU1eVZsc29VTFItenFqM21xVk1SSkVfcFdwRXNWX1hmTTBuSGFTVEhRIiwiYnJhbmNoIjoiZmVhdC9ocy10b2tlbnJldmlldy1hdXRoIiwicmVwb093bmVyIjoicmF5LXByb2plY3QiLCJyZXBvTmFtZSI6Imt1YmVyYXkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjRlNjU5MTRiLTc3MjQtNDA4OC04YjZmLTRmMmZlN2QyOTVkNCIsImVuY3J5cHRpb25LZXkiOiJ4aGU1eVZsc29VTFItenFqM21xVk1SSkVfcFdwRXNWX1hmTTBuSGFTVEhRIiwiYnJhbmNoIjoiZmVhdC9ocy10b2tlbnJldmlldy1hdXRoIiwicmVwb093bmVyIjoicmF5LXByb2plY3QiLCJyZXBvTmFtZSI6Imt1YmVyYXkiLCJwck51bWJlciI6NTIwNCwiY29tbWl0U2hhIjoiOGE2Yjc4ZDdkOGQxYzk1ZDg1Yzk1NTI0ZDk3MmE3MDYzODhhNmIwZCIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by Cursor Bugbot for commit 8a6b78d7d8d1c95d85c95524d972a706388a6b0d. Configure here.</sup>
Post-login redirect allows off-origin bounce
Medium Severity
<!-- DESCRIPTION START -->safeNext treats a leading backslash as a same-origin path because url.Parse leaves Host empty, then that value is used as the post-login Location. Browsers treat /\evil.example as a network-path URL, so a crafted next can send a just-authenticated user off this origin after the session cookie is set.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: fa4c9ace-28cc-4679-bb1e-297b465a6a70 -->
<!-- LOCATIONS START
historyserver/pkg/historyserver/auth.go#L215-L225
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmZiM2E5OTZkLWE4YzYtNDg1OC05NmRjLWJlMjJmNWYyYTk1OSIsImVuY3J5cHRpb25LZXkiOiI2MU15ZDZNQUFSbTl3cXVPbFh4YnhqazNOYmpyUTBodTRZcFR2dzgxSTBBIiwiYnJhbmNoIjoiZmVhdC9ocy10b2tlbnJldmlldy1hdXRoIiwicmVwb093bmVyIjoicmF5LXByb2plY3QiLCJyZXBvTmFtZSI6Imt1YmVyYXkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmZiM2E5OTZkLWE4YzYtNDg1OC05NmRjLWJlMjJmNWYyYTk1OSIsImVuY3J5cHRpb25LZXkiOiI2MU15ZDZNQUFSbTl3cXVPbFh4YnhqazNOYmpyUTBodTRZcFR2dzgxSTBBIiwiYnJhbmNoIjoiZmVhdC9ocy10b2tlbnJldmlldy1hdXRoIiwicmVwb093bmVyIjoicmF5LXByb2plY3QiLCJyZXBvTmFtZSI6Imt1YmVyYXkiLCJwck51bWJlciI6NTIwNCwiY29tbWl0U2hhIjoiYWM1ZDRmN2MyNDM1NzYwNDBlYzVmYmVlOWQwMzBkZjdjNTJjZWU2OCIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by Cursor Bugbot for commit ac5d4f7c243576040ec5fbee9d030df7c52cee68. Configure here.</sup>
Login success lands on missing page
Medium Severity
<!-- DESCRIPTION START -->safeNext defaults an empty or rejected next to /, and logout sends the browser to /login with no next. There is no handler for / (routerRoot is commented out), so the documented paste-a-token flow and every re-login after logout finish on a 404 instead of the cluster selector.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: d68364cd-21b6-439b-9fe9-447db9776f5b -->
<!-- LOCATIONS START
historyserver/pkg/historyserver/auth.go#L215-L225
historyserver/pkg/historyserver/auth.go#L265-L269
LOCATIONS END -->
<details>
<summary>Additional Locations (1)</summary>
historyserver/pkg/historyserver/auth.go#L265-L269</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmNlZTU4MjZmLTdlMTgtNGY0ZS1hODk0LTYwMWM2ZjE5MDcwMCIsImVuY3J5cHRpb25LZXkiOiIwUWNBbUMwSUFrSnJmT2E5X2ZBLTR4cTR6dlNTMXJIY2FKdGtQeWZiUko4IiwiYnJhbmNoIjoiZmVhdC9ocy10b2tlbnJldmlldy1hdXRoIiwicmVwb093bmVyIjoicmF5LXByb2plY3QiLCJyZXBvTmFtZSI6Imt1YmVyYXkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmNlZTU4MjZmLTdlMTgtNGY0ZS1hODk0LTYwMWM2ZjE5MDcwMCIsImVuY3J5cHRpb25LZXkiOiIwUWNBbUMwSUFrSnJmT2E5X2ZBLTR4cTR6dlNTMXJIY2FKdGtQeWZiUko4IiwiYnJhbmNoIjoiZmVhdC9ocy10b2tlbnJldmlldy1hdXRoIiwicmVwb093bmVyIjoicmF5LXByb2plY3QiLCJyZXBvTmFtZSI6Imt1YmVyYXkiLCJwck51bWJlciI6NTIwNCwiY29tbWl0U2hhIjoiYWM1ZDRmN2MyNDM1NzYwNDBlYzVmYmVlOWQwMzBkZjdjNTJjZWU2OCIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by Cursor Bugbot for commit ac5d4f7c243576040ec5fbee9d030df7c52cee68. Configure here.</sup>
<!-- BUGBOT_REVIEW -->
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
There are 4 total unresolved issues (including 2 from previous reviews).
<!-- BUGBOT_FIX_ALL -->
<a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aTo0MzA2ZjA1ZC1iZmZhLTRmZTQtYjY3Yy00MDNiZTlhYjdkOTIiLCJlbmNyeXB0aW9uS2V5IjoiNzJoLUxRaEgyaVRHZ08tWVR3Y2VVQnpuVk96bmlRanpPdnpfYS1yQWVPYyIsImJyYW5jaCI6ImZlYXQvaHMtdG9rZW5yZXZpZXctYXV0aCIsInJlcG9Pd25lciI6InJheS1wcm9qZWN0IiwicmVwb05hbWUiOiJrdWJlcmF5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix All in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>
<!-- /BUGBOT_FIX_ALL -->
<sup>Reviewed by Cursor Bugbot for commit ac5d4f7c243576040ec5fbee9d030df7c52cee68. Configure here.</sup>
Should we also validate authCacheTTL > 0 and authCookieMaxAge > 0 as well when enableAuth is true? It seems like expirable.NewLRU treats ttl <= 0 as no expiration, which would cache tokens indefinitely.
To answer your questions:
For the scoping: keeping this separate from the SubjectAccessReview makes sense to me. Could you open a follow-up issue to track the work including this one?
I'm also on the side of a built in login page. But I curious about how it would work with the Cookies we currently have (since I believe, it isn't completely migrated yet). And also if there's a login, is there also a logout as well?
For the filter gate, I think that makes sense to me, but want to hear thoughts of others.
Please also take a look at the Cursor bot comments, I think the safeNext defaulting is valid.
@chiayi The follow up issue has been created. #5355
The two cookie families are independent: hs_auth_token is checked by the container-level AuthFilter, the five context cookies (cluster_name / cluster_namespace / session_name / owner_kind / owner_name) by the per-route CookieHandle. This PR does not read or write the context cookies. /login and /logout are raw handlers outside the filter chain so they stay reachable unauthenticated, and /select_cluster repeats the check inline. There is a logout — it clears hs_auth_token and redirects to /login.
Is #5065 the migration you meant? If it is a different one, tell me which and I will re-check.
chiayi
KunWuLuan
Why are these changes needed?
The History Server serves stored session data -- job logs, actor state, node and
event history -- to anyone who can reach its port. There is no authentication of
its own today: the only credential in the codebase is the one it presents to a
live cluster's dashboard (
--use-auth-token-mode). Anything already collectedinto object storage is readable by any caller.
This adds an opt-in check of the caller's own Kubernetes identity in front of
every data path, via the TokenReview API. It is off by default (
--enable-auth),so existing deployments are unaffected.
The two credentials stay separate: the user's Kubernetes token is never derived
from, nor forwarded as, the Ray auth token, and the egress path strips it before
proxying.
What's in it:
auth.go: TokenReview-backedAuthenticatorwith a hash-keyed expirable LRU,so raw tokens are never retained; a container-level
AuthFiltergating everygo-restful WebService;
/loginand/logoutregistered outside the filterchain so they stay reachable while unauthenticated
503 -- an unreachable API server must never be mistaken for a valid token
Authorizationheader is a hard 401rather than a silent fallback to the cookie, so a misconfigured client cannot
end up authenticated as whoever the browser session belongs to
302 /login?next=..., XHR callers get the{code,message}JSON error contract./select_clusterchecks explicitly ratherthan rendering a selector whose
fetch('/clusters')would 401Set-Cookie, and the post-loginredirect target is constrained to this origin
Authorization/x-ray-authorizationstrip on the proxy path becomes unconditional, andhs_auth_tokenis removed from the outgoingCookieheaderconfig/service_account_auth.yamlbinds the built-insystem:auth-delegatorClusterRole, which is all TokenReview needs
Scope, and where I'd like input
This is authentication, not authorization. Any token the cluster accepts can
read every session the History Server holds -- which matches how the server reads
storage today: one identity, unaware of who is asking. Restricting a user to the
namespaces they can already see needs a SubjectAccessReview per request against
the owning RayCluster; I left that for a follow-up and said so in the README, so
nobody mistakes
--enable-authfor tenant isolation. Happy to fold it into thisPR instead if you'd rather it land as one piece.
Two other things I'd rather settle in review than defend later:
1. The built-in login page. It exists so a single link keeps working in a
browser, and it takes a pasted
kubectl create tokenvalue. The alternative isto serve only 401/403 and let an OIDC-aware proxy in front handle the human
flow. I went with the self-contained option because it needs no extra
infrastructure, but I'll drop it if you'd rather not own login UI here.
2.
restful.Filteras the gate. A container-level filter means newWebServices are authenticated by default rather than by remembering to opt in.
The cost is that
/select_cluster, which is a rawhttp.Handle, needs thesame check written out explicitly.
Related issue number
None.
Labels
doc-updates-requiredlabel.breaking-changelabel.(No label permissions here. This is user-facing but off by default and documented
in
historyserver/README.md;doc-updates-requiredmay still be worth adding atrelease time. Not breaking.)
Checks
- [x] Unit tests
- [ ] Manual tests
auth_test.gocovers 401 vs 503 mapping, review caching, header precedence andthe hard failure on a bad scheme, cookie stripping (including a similarly named
cookie that must survive), off-origin redirect rejection, the browser-vs-XHR
branch, and the selector's four states (unauthenticated, authenticated,
TokenReview down, auth disabled).