Repository navigation
[cherry-pick][2.59.0][Feat][Core/Auth] Enable token authentication for local clusters by default (#64755) - #66248
Conversation
…efault (ray-project#64755) ## Description Enable token authentication for local clusters by default. The table below shows the resulting behavior. Remote and worker paths are unchanged. | Entry point | `RAY_AUTH_MODE` unset, token exists | `RAY_AUTH_MODE` unset, no token | `RAY_AUTH_MODE=token` | `RAY_AUTH_MODE=disabled` | |---|---|---|---|---| | **`ray.init()`** (new local cluster, no address) | enable + **reuse** token + **warn** | enable + **generate** token + **warn** | enable (generate/reuse), no warning | disabled, no warning | | **`ray start --head`** (local head) | enable + reuse token + **warn** | disabled + **warn** | enable; **raises** if no token, no warning | disabled, no warning | | **`ray.init(address=…)`** (connect to existing) | unchanged, no auto-enable; needs token if cluster requires it | unchanged | requires token, else error | disabled | | **`ray start --address=…`** (worker) | unchanged, no auto-enable | unchanged | requires token, else error | disabled | A token "exists" if any of these resolve, checked in order: 1. `RAY_AUTH_TOKEN` environment variable 2. file at `RAY_AUTH_TOKEN_PATH` 3. default file `~/.ray/auth_token` ## Related issues N/A ## Additional information To enable this for all clusters in the future: - Change the default to "token" here: https://github.com/ray-project/ray/blob/1439e47b9b136143fbc99417cb4f50a82eff72a9/src/ray/common/ray_config_def.h#L39. That is the single source of truth, and `RAY_AUTH_MODE=disabled` stays as the opt-out. - Remove the auto-enable helper functions from this PR (`enable_token_auth_by_default`, `maybe_enable_token_auth_if_token_available`) and their call sites in `worker.py` and `scripts.py`. - Decide whether `ray start --head` should auto-generate a token instead of erroring. The worker and connect paths would then require a distributed token, which is a breaking change. - The cluster launcher, KubeRay, and autoscaler would need to distribute the token to workers automatically. Test fixtures would need to provision a token, and every client path would need to attach it. - Update `token-auth.md` and the guides that say "disabled by default". --------- Signed-off-by: Chi-Sheng Liu <[email protected]> (cherry picked from commit 48894b0)
There was a problem hiding this comment.
Code Review
This pull request enables token authentication by default for new local Ray clusters started via ray.init() and automatically enables it for ray start --head if a token is already available. It introduces helper functions to manage this default behavior, updates documentation, and refactors gRPC server interceptors to prevent memory leaks. To support default-on authentication in tests, it adds test utilities (such as request_with_auth_token and auth_token_grpc_metadata) and fixtures to isolate and restore token authentication state across test sessions. Additionally, the C++ token loader is updated to fall back to the passwd database when HOME is unset, aligning its behavior with Python. I have no feedback to provide.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit a724e0c. Configure here.
| # In this case, we need to start a new cluster. | ||
|
|
||
| enable_token_auth_by_default() | ||
|
|
There was a problem hiding this comment.
Clients skip auto token auth
High Severity
ray start --head now turns on token auth whenever a token already exists, and ray.init() writes that token to ~/.ray/auth_token. Connecting via ray.init(address=...) and joining via ray start --address= still send a token only when RAY_AUTH_MODE is already token. A later local client or worker therefore talks to an authenticated head without credentials, so the common ray start --head then ray.init(address="auto") or second-node workflow fails after any prior local ray.init().
Additional Locations (2)
Reviewed by Cursor Bugbot for commit a724e0c. Configure here.
…ntainers and reuse it when `ray.init()` finds a local cluster (#66467) (#66582) Cherry-pick of #66467 onto `releases/2.59.0`. #64755 (token auth enabled by default for local clusters) was cherry-picked to 2.59.0 in #66248, so the two bugs it exposed exist on the release branch too: 1. `image_uri` / `container` workers get `RAY_AUTH_MODE=token` but not the token file, so they crash on startup. Fix: mount the token file read-only and set `RAY_AUTH_TOKEN_PATH`. 2. `ray.init()` can't connect to a local cluster started via `ray start --head` with token auth when `RAY_AUTH_MODE` is unset. Fix: reuse the existing token (and warn) when connecting to a running local cluster. Cherry-picked cleanly with `git cherry-pick -x` from merge commit 5853ff1; the diff is identical to the upstream commit. Not a duplicate: no existing PR against `releases/2.59.0` references #66467. Testing: relying on release-branch CI (`test_token_auth_integration`, `unit/test_runtime_env_image_uri`, `test_runtime_env_container`); 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: elliot-barn <[email protected]> Co-authored-by: Chi-Sheng Liu <[email protected]>


Cherry-pick of #64755 (master commit 48894b0) onto releases/2.59.0.
One conflict resolved, in
python/ray/_private/test_utils.py. The original commit adds the auth helpers (_auth_token_header,request_with_auth_token,auth_token_grpc_metadata) directly above the accelerator helpersget_gpu_visible_devices_env_var,mock_accelerator_detectionandmock_no_accelerators, and those accelerator helpers do not exist on this branch. The pick keeps the three auth helpers and drops the accelerator block, which nothing onreleases/2.59.0references. The other 48 files applied cleanly, and the resulting commit touches the same 49 files as the master commit with the same 1202 insertions and 376 deletions.