Skip to content

[Fix][Core/Auth] Enable token auth in C++ and Java drivers that start their own local cluster - #66778

Merged
rueian merged 2 commits into
ray-project:masterfrom
MortalHappiness:fix/ray-cpp-token-auth
Oct 6, 2026
Merged

rueian merged 2 commits into
ray-project:masterfrom
MortalHappiness:fix/ray-cpp-token-auth

Conversation

@MortalHappiness

@MortalHappiness MortalHappiness commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Description

Since #64755, ray start --head enables token auth when RAY_AUTH_MODE is unset and ~/.ray/auth_token exists, for example after any earlier Python ray.init(). C++ and Java drivers that start their own head don't make the same decision: their auth mode stays disabled, so they connect without a token and fail with InvalidAuthToken. The release sanity check hits this. #66467 fixed the same mismatch for Python ray.init().

This PR adds MaybeEnableTokenAuthIfTokenAvailable() next to the token loader. When RAY_AUTH_MODE is unset and a token exists, it sets RAY_AUTH_MODE=token in the process environment so that the later RayConfig re-initialization keeps it. Both drivers call it, only when they started the head:

 ProcessHelper::RayStart (C++)
   if driver && no address
+    MaybeEnableTokenAuthIfTokenAvailable()
     StartRayNode()  # ray start --head

 RayNativeRuntime.start (Java)
   if driver && no address
     RunManager.startRayHead()  # ray start --head
   if driver
     loadLibrary()
+    if started the head
+      nativeMaybeEnableTokenAuthIfTokenAvailable()
     getGcsClient()

Drivers given an explicit address are unchanged. //cpp:metric_example now runs without RAY_AUTH_MODE to cover this path.

Related issues

N/A

Additional information

N/A

@MortalHappiness MortalHappiness added the go add ONLY when ready to merge, run all tests label Oct 6, 2026
… their own local cluster

Signed-off-by: Chi-Sheng Liu <[email protected]>
@MortalHappiness
MortalHappiness marked this pull request as ready for review October 6, 2026 22:18

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces automatic token authentication enablement for C++ and Java drivers when a token is available and RAY_AUTH_MODE is unset. It adds the MaybeEnableTokenAuthIfTokenAvailable helper in C++ and exposes it to Java via JNI. However, a critical issue was identified in the Java runtime implementation: restricting the token auth auto-enablement to only when startRayHead is true will cause Java drivers to fail with InvalidAuthToken when connecting to an existing token-enabled cluster. It is recommended to call nativeMaybeEnableTokenAuthIfTokenAvailable() unconditionally for all Java drivers.

@rueian
rueian merged commit 8bf3d3e into ray-project:master Oct 6, 2026
6 checks passed
sai-miduthuri added a commit that referenced this pull request Oct 13, 2026
…va drivers that start their own local cluster (#66778) (#66801)

Cherry-pick of #66778 (master commit
8bf3d3e) onto `releases/2.60.0`.

`releases/2.60.0` already has #64755 (token auth enabled by default for
local clusters) and #66467, so C++ and Java drivers that start their own
head fail with `InvalidAuthToken` on this branch too: `ray start --head`
enables token auth when `RAY_AUTH_MODE` is unset and `~/.ray/auth_token`
exists, but the driver's auth mode stays `disabled`. The release sanity
check hits this. The fix adds `MaybeEnableTokenAuthIfTokenAvailable()`
next to the token loader and calls it from both drivers only when they
started the head.

Applied cleanly with `git cherry-pick -x`; the diff is identical to the
master commit. All 9 touched files, plus the APIs the new code calls
(`TryLoadToken(ignore_auth_mode)`, `SetEnv`), are byte-identical to
master at 8bf3d3e after the pick.

Not a duplicate: no existing PR against `releases/2.60.0` references
#66778.

Testing: relying on release-branch CI (`//cpp:metric_example`, which now
runs without `RAY_AUTH_MODE` to cover this path, plus the C++ and Java
driver tests); no local tests run.

AI assistance was used to prepare this cherry-pick.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Chi-Sheng Liu <[email protected]>
Signed-off-by: sai.miduthuri <[email protected]>
Co-authored-by: Chi-Sheng Liu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants