Skip to content

[Feat][Core/Auth] Enable token authentication for local clusters by default - #64755

Merged
edoakes merged 44 commits into
ray-project:masterfrom
MortalHappiness:feat/token-auth-local-cluster
Sep 17, 2026
Merged

edoakes merged 44 commits into
ray-project:masterfrom
MortalHappiness:feat/token-auth-local-cluster

Conversation

@MortalHappiness

@MortalHappiness MortalHappiness commented Jul 14, 2026 •

Copy link
Copy Markdown
Member

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:
    RAY_CONFIG(std::string, AUTH_MODE, "disabled")
    . 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".

@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 automatically enables token authentication for local head clusters (ray start --head) if a token is available from any source, even when RAY_AUTH_MODE is not explicitly set. It also introduces warnings when starting unauthenticated clusters and updates the documentation and integration tests. The review feedback highlights three important issues: the automatic detection logic should gracefully handle unexpected exceptions to prevent startup crashes, and the new integration tests must be wrapped in authentication_env_guard() to avoid polluting or deleting the developer's local token files and to prevent test failures when run locally.

@MortalHappiness
MortalHappiness force-pushed the feat/token-auth-local-cluster branch from f11ac91 to 90b4d19 Compare July 14, 2026 22:51
@MortalHappiness
MortalHappiness marked this pull request as ready for review July 15, 2026 01:05
@MortalHappiness
MortalHappiness requested review from a team as code owners July 15, 2026 01:05
@ray-gardener ray-gardener Bot added the core Issues that should be addressed in Ray Core label Jul 15, 2026
@MortalHappiness
MortalHappiness marked this pull request as draft July 15, 2026 20:26
@MortalHappiness
MortalHappiness force-pushed the feat/token-auth-local-cluster branch from 21759e8 to fbaf9be Compare July 21, 2026 21:09

@dstrodtman dstrodtman 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.

stamping for docs.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Aug 5, 2026
@MortalHappiness MortalHappiness removed the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Aug 5, 2026
Signed-off-by: Chi-Sheng Liu <[email protected]>
Signed-off-by: Chi-Sheng Liu <[email protected]>
@MortalHappiness
MortalHappiness marked this pull request as ready for review August 13, 2026 18:38
@MortalHappiness

Copy link
Copy Markdown
Member Author

@rueian Ready for review now. Thanks.

@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 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 also updates the documentation and adds comprehensive integration tests to verify these behaviors. There are no review comments, so I have no feedback to provide.

@MortalHappiness MortalHappiness added the go add ONLY when ready to merge, run all tests label Aug 13, 2026
@MortalHappiness
MortalHappiness marked this pull request as draft August 13, 2026 20:36
@MortalHappiness
MortalHappiness marked this pull request as ready for review September 15, 2026 08:00

@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 enables token authentication by default for new local Ray clusters and head nodes when a token is available, updating gRPC interceptors, documentation, and various tests to support this behavior. The review feedback highlights three key issues: a critical race condition in parallel test execution that can lead to the deletion of a user's actual local auth token, a Windows build break in a Bazel genrule due to Unix-specific commands, and a potential invalid path resolution in C++ if both the HOME environment variable and passwd database lookups fail.

Comment thread python/ray/tests/conftest.py Resolved
Comment thread cpp/BUILD.bazel Resolved
Signed-off-by: Chi-Sheng Liu <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 71d9afa. Configure here.

Comment thread python/ray/tests/conftest.py Resolved
Signed-off-by: Chi-Sheng Liu <[email protected]>
Signed-off-by: Chi-Sheng Liu <[email protected]>
@rueian

rueian commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

ping @ray-project/ray-ci @ray-project/ray-llm @ray-project/ray-serve @ray-project/ray-train @ray-project/ray-tune @ray-project/ray-data for review. 🙏

@edoakes
edoakes merged commit 48894b0 into ray-project:master Sep 17, 2026
6 checks passed
sai-miduthuri pushed a commit that referenced this pull request Sep 18, 2026
…r local clusters by default (#64755) (#66248)

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 helpers `get_gpu_visible_devices_env_var`,
`mock_accelerator_detection` and `mock_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 on
`releases/2.59.0` references. 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.

Signed-off-by: Chi-Sheng Liu <[email protected]>
elliot-barn pushed a commit that referenced this pull request Sep 29, 2026
… when `ray.init()` finds a local cluster (#66467)

## Description

`test_runtime_env_container` has failed on master since #64755 enabled
token auth by default for local clusters. That change exposed two bugs:

1. **Container workers can't find the token.** The `image_uri` /
`container` plugin forwards `RAY_AUTH_MODE=token` into the podman worker
but doesn't mount the token file, so the worker crashes on startup. Fix:
mount the token file read-only and set `RAY_AUTH_TOKEN_PATH`. The token
isn't passed via `--env`, because the podman command is logged.
2. **`ray.init()` can't connect to a cluster that `ray start --head`
started with token auth.** With `RAY_AUTH_MODE` unset, the driver
connects without a token and gets rejected. Fix: when `ray.init()` finds
a running local cluster (no `address`, or `address="auto"`) and a token
exists, it enables token auth, reuses the token, and warns, just like
`ray start --head`. An explicit `address` or `RAY_ADDRESS` keeps the
current behavior, and nothing else in the #64755 behavior table changes.

## Related issues

Related to #64755.

## Additional information

N/A

---------

Signed-off-by: Chi-Sheng Liu <[email protected]>
elliot-barn added a commit that referenced this pull request Sep 29, 2026
…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]>
elliot-barn added a commit that referenced this pull request Oct 2, 2026
Token authentication is enabled by default for local clusters (#64755),
but the C++ API only loads tokens from `RAY_AUTH_TOKEN` /
`RAY_AUTH_TOKEN_PATH` — it has no fallback to the default
`~/.ray/auth_token` file that `ray start` writes. The cpp sanity example
auto-starts a cluster whose GCS then rejects the tokenless C++ driver
with `InvalidAuthToken`.

Fix: pre-generate a token and export `RAY_AUTH_TOKEN_PATH` so the
auto-started cluster and the C++ driver agree — the same approach #64755
used for the in-repo cpp bazel tests. This keeps the sanity check
exercising the supported authenticated configuration rather than
disabling auth.

**Context**: found on the 2.59.0 release — all 11 wheel-validation jobs
(Linux x86/arm64 py3.10–3.14 + macOS) failed in the cpp leg on
[release-automation build
3472](https://buildkite.com/ray-project/release-automation/builds/3472).
This script is the only CI anywhere that exercises ray-cpp against a
local token-auth cluster from published wheels, and it hadn't run since
the auth default landed (master's TestPyPI/validate steps stay blocked
on nightlies). Will need a cherry-pick to releases/2.59.0 to re-run the
validation there. Separately, proper C++ API token support (default-path
fallback) deserves an upstream issue.

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

Signed-off-by: elliot-barn <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…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]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
… when `ray.init()` finds a local cluster (ray-project#66467)

## Description

`test_runtime_env_container` has failed on master since ray-project#64755 enabled
token auth by default for local clusters. That change exposed two bugs:

1. **Container workers can't find the token.** The `image_uri` /
`container` plugin forwards `RAY_AUTH_MODE=token` into the podman worker
but doesn't mount the token file, so the worker crashes on startup. Fix:
mount the token file read-only and set `RAY_AUTH_TOKEN_PATH`. The token
isn't passed via `--env`, because the podman command is logged.
2. **`ray.init()` can't connect to a cluster that `ray start --head`
started with token auth.** With `RAY_AUTH_MODE` unset, the driver
connects without a token and gets rejected. Fix: when `ray.init()` finds
a running local cluster (no `address`, or `address="auto"`) and a token
exists, it enables token auth, reuses the token, and warns, just like
`ray start --head`. An explicit `address` or `RAY_ADDRESS` keeps the
current behavior, and nothing else in the ray-project#64755 behavior table changes.

## Related issues

Related to ray-project#64755.

## Additional information

N/A

---------

Signed-off-by: Chi-Sheng Liu <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…ct#66658)

Token authentication is enabled by default for local clusters (ray-project#64755),
but the C++ API only loads tokens from `RAY_AUTH_TOKEN` /
`RAY_AUTH_TOKEN_PATH` — it has no fallback to the default
`~/.ray/auth_token` file that `ray start` writes. The cpp sanity example
auto-starts a cluster whose GCS then rejects the tokenless C++ driver
with `InvalidAuthToken`.

Fix: pre-generate a token and export `RAY_AUTH_TOKEN_PATH` so the
auto-started cluster and the C++ driver agree — the same approach ray-project#64755
used for the in-repo cpp bazel tests. This keeps the sanity check
exercising the supported authenticated configuration rather than
disabling auth.

**Context**: found on the 2.59.0 release — all 11 wheel-validation jobs
(Linux x86/arm64 py3.10–3.14 + macOS) failed in the cpp leg on
[release-automation build
3472](https://buildkite.com/ray-project/release-automation/builds/3472).
This script is the only CI anywhere that exercises ray-cpp against a
local token-auth cluster from published wheels, and it hadn't run since
the auth default landed (master's TestPyPI/validate steps stay blocked
on nightlies). Will need a cherry-pick to releases/2.59.0 to re-run the
validation there. Separately, proper C++ API token support (default-path
fallback) deserves an upstream issue.

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

Signed-off-by: elliot-barn <[email protected]>
rueian pushed a commit that referenced this pull request Oct 6, 2026
… their own local cluster (#66778)

## 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:

```diff
 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

Signed-off-by: Chi-Sheng Liu <[email protected]>
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

core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants