Skip to content

[Core/Auth] Make token auth the default for all clusters - #67523

Merged
elliot-barn merged 10 commits into
ray-project:masterfrom
MortalHappiness:feat/token-auth-67055-default-all-clusters
Nov 3, 2026
Merged

elliot-barn merged 10 commits into
ray-project:masterfrom
MortalHappiness:feat/token-auth-67055-default-all-clusters

Conversation

@MortalHappiness

@MortalHappiness MortalHappiness commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Description

AUTH_MODE now defaults to token, so every cluster runs with token auth unless RAY_AUTH_MODE=disabled is set. Until now only a local cluster turned auth on, and only through special cases that read whether a token already existed. With token as the default those special cases do nothing, so this PR deletes them:

 src/ray/common/ray_config_def.h
-  AUTH_MODE = "disabled"
+  AUTH_MODE = "token"

 ray.init()
-  enable_token_auth_by_default()                      # new local cluster
-  if address in (None, "auto"):
-    maybe_enable_token_auth_if_token_available()      # connect to a local cluster
   ensure_token_if_auth_enabled()

 ray start --head
-  maybe_enable_token_auth_if_token_available()
   fail if token mode and no token

 ray metrics launch-prometheus
-  maybe_enable_token_auth_if_token_available() + warning when unset and no token
   get_prometheus_authorization_config()               # unset mode with no token now fails here

 C++ / Java drivers that start their own cluster
-  MaybeEnableTokenAuthIfTokenAvailable()              # plus its JNI method and Java call
   CreateTokenIfMissingForOwnCluster()

The old warnings fired only when RAY_AUTH_MODE was unset, which no longer means auth is off. They are replaced by one warning from Node(head=True) when the head starts with RAY_AUTH_MODE=disabled. Worker nodes, drivers and clients don't warn.

RAY_AUTH_MODE now accepts only token and disabled, case-insensitively. Any other value, including an empty one, used to turn auth off silently. With token as the default, a typo would start an unauthenticated cluster without warning. Such a value now fails at startup with Invalid RAY_AUTH_MODE '<value>': set it to 'token' or 'disabled'.

Before, on a fresh HOME, the documented local flow failed at the second node:

$ ray get-auth-token --generate
$ ray start --head --port=6379
$ ray start --address=127.0.0.1:6379
ray.exceptions.AuthenticationError: RPC error: InvalidAuthToken: Authentication token is missing or incorrect. Note: RAY_AUTH_MODE is currently 'disabled' (not 'token'). ...

ray.init(address="127.0.0.1:6379") failed with the same error, since only an address of None or "auto" turned auth on. After this PR both join with token auth on, with no extra steps.

ray up now reads a top-level auth_mode key (token or disabled) in the cluster YAML instead of the RAY_AUTH_MODE of the shell that runs it. It ships the token unless the key is disabled. When the key is set, every node's start commands run with RAY_AUTH_MODE set to that value, including workers the autoscaler adds later.

The behavior change is in ray_config_def.h, authentication_mode.cc, rpc_token_authentication.pxi, authentication_token_setup.py, worker.py, scripts.py, node.py, install_and_start_prometheus.py, the ray up path (commands.py, updater.py, autoscaler.py, ray_installer.py, ray-schema.json) and the removed C++, JNI and Java helpers. The other files are test, test-build or comment changes.

Test fixtures:

  • python/ray/tests/conftest.py used to turn auth off by removing RAY_AUTH_MODE. It now sets RAY_AUTH_MODE=disabled.
  • ray start --head never creates a token, and neither do tests that run Ray's servers and clients with no driver. Python tests like these, Serve's included, use the new create_auth_token fixture. call_ray_start_context and module-scoped fixtures use hold_test_auth_mode(), which does the same. Both create the token first and keep it until the test or head is done. The per-test cleanup deletes ~/.ray/auth_token after every test, which would break a head shared across a test module.
  • C++ tests that run gRPC servers and clients with no driver set auth_token = True on ray_cc_test. That reads a random token generated at build time by the //src/ray/common:auth_token_file genrule (moved from cpp/BUILD.bazel), so no token is written in source and every other test still exercises token creation.
  • The HA Docker test containers and the dashboard UI test get a token through RAY_AUTH_TOKEN, generated at run time. The UI test logs in through POST /api/authenticate before opening the dashboard.
  • get_load_metrics_report, test_serve_ha.py and test_cli_3.py call the dashboard directly and now send the token.
  • The mock channel in test_grpc_client_credentials.py accepts try_to_connect. In token mode the client wraps its channel with grpc.intercept_channel, which passes that keyword to subscribe.
  • The smoke mode of the torch_tune_serve_test.py release test sets RAY_AUTH_TOKEN before ray start --head.
  • The release test images (release/ray_release/byod/byod.Dockerfile and docker/ray-torch/Dockerfile) set RAY_AUTH_MODE=disabled. Anyscale's agent on the head node calls the Ray dashboard API without a token, so the job is never submitted when auth is on. [Core/Auth] Verify Anyscale platform clusters work with token auth on by default #67058 tracks turning auth back on.
  • The KubeRay autoscaling e2e templates set authOptions: {mode: token} and raise rayVersion from 2.46.0 to 2.52.0, the lowest version KubeRay v1.7.0 accepts with authOptions. [KubeRay][Core/Auth] Verify KubeRay clusters work with token auth on by default #67057 tracks whether KubeRay users should need this.
  • The ray up tests check that disabled in the auth_mode key ships no token even from a shell with RAY_AUTH_MODE=token, and that a missing key ships it even from a shell with RAY_AUTH_MODE=disabled.

Related issues

Closes #67055

Additional information

This changes the default for every cluster, so it breaks setups that silently relied on auth being off:

  • ray start --head with no token now fails at once and says to run ray get-auth-token --generate.
  • Nodes and clients on other machines need the head's token copied to them, or every node and client must set RAY_AUTH_MODE=disabled.
  • ray metrics launch-prometheus with no token now fails instead of writing a config without auth.
  • Ray on Spark (ray.util.spark.setup_ray_cluster) can't start a cluster, because its head runs ray start --head and nothing in ray.util.spark creates or ships a token. This PR doesn't fix that.
  • Prometheus servers that scrape Ray's metrics endpoints without the token get a 401 on every target. Add the token to each scrape job, or set RAY_AUTH_SKIP_METRICS=1 on every node to keep the metrics endpoints open.
  • To opt a ray up cluster out, set auth_mode: disabled in the cluster YAML. The RAY_AUTH_MODE of the shell running ray up no longer decides whether the token ships.
  • A RAY_AUTH_MODE other than token or disabled, such as none, off or an empty value, now fails at startup instead of turning auth off.

aws_cluster_launcher_minimal fails on this PR's release run and should pass once the nightly wheel includes this change. Its nodes install the latest nightly wheel, so this PR's ray up ships a token to an older Ray. That older head turns auth on when the token file exists, but a driver that passes an explicit address stays in disabled mode and is rejected.

This needs a release note. The docs update in #67056 has to ship in the same release. #67057 and #67058 check that KubeRay and Anyscale clusters work with this default.

The test fixes above come from premerge runs on this PR. Each failure got its own fix: create_auth_token (Python), auth_token = True (C++), sending the token, or enable_token_auth=False on Cluster(). CI config doesn't set RAY_AUTH_MODE=disabled globally.

@MortalHappiness MortalHappiness added the go add ONLY when ready to merge, run all tests label Oct 28, 2026
@MortalHappiness
MortalHappiness marked this pull request as ready for review October 29, 2026 18:56

@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 in Ray by changing the default AUTH_MODE to "token" and removing the now-redundant auto-enable token authentication helper functions. It updates various tests, Bazel build targets, and scripts to ensure that authentication tokens are correctly generated and propagated. The review comments provide valuable feedback: one suggests prepending http:// to the Cypress request URL in the dashboard tests to prevent routing issues, and another recommends using python3 instead of python in run_ui_tests.sh for better portability.

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

Stale Bugbot comment from a previous run.

Comment thread python/ray/tests/conftest.py Resolved
@ray-gardener ray-gardener Bot added the core Issues that should be addressed in Ray Core label Oct 29, 2026
…7055-default-all-clusters

Signed-off-by: Chi-Sheng Liu <[email protected]>

# Conflicts:
#	python/ray/serve/tests/test_ray_client.py
@rueian

rueian commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

AI reviews:

  1. Ray on Spark stops working. setup_ray_cluster starts its nodes with ray start, but nothing in python/ray/util/spark creates or ships a token. With token as the default, ray start --head aborts. The PR’s list of breaking changes doesn’t mention it.
  2. The ray up opt-out doesn’t reach the nodes. If you run ray up with RAY_AUTH_MODE=disabled set locally, it ships no token. The remote nodes don’t get the setting, so they default to token mode and ray start --head on the head aborts. No end-to-end test covers this disabled case any more.
  3. Missing from the breaking-change list in the PR description: metrics scraping. Existing Prometheus scrape configs without a token start getting 401 on every node, and Ray logs nothing about it.
  4. No test checks that a head started by ray start --head with the new default actually rejects a client without a token.

@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 and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 8c4c937. Configure here.

… start head rejects a tokenless driver

Signed-off-by: Chi-Sheng Liu <[email protected]>
@MortalHappiness

Copy link
Copy Markdown
Member Author

@rueian 1 and 3 are now listed as breaking changes. 2: ray up now reads auth_mode from the cluster YAML and passes it to every node. 4: added test_ray_start_head_rejects_driver_without_token.

Copy link
Copy Markdown
Member

I am preparing a draft alternative for the existing head/worker mismatch, and documenting the difference here before opening it, per AGENTS.md.

A persisted ~/.ray/auth_token can currently make ray start --head turn token authentication on when RAY_AUTH_MODE is unset, while workers started without that variable remain in disabled mode and fail to join with InvalidAuthToken.

The alternative keeps the existing AUTH_MODE=disabled default and requires an explicit RAY_AUTH_MODE=token opt in. It removes token-presence inference from the Python/C++/Java startup paths, local ray.init() discovery, the Ray Client helper, and the Prometheus launcher, while retaining explicit token creation/loading and missing or invalid token checks. This overlaps with the helper removal in this PR, but chooses a materially different default; it does not implement the default-on rollout or change cluster-launcher policy.

The draft will include regression tests for existing token sources, head/worker consistency, all ray.init() address forms, Ray Client, and Prometheus. AI assistance was used for implementation and testing; it will remain a draft pending the submitting human's line-by-line review and local test run.

@elliot-barn
elliot-barn merged commit 8b6e26d into ray-project:master Nov 3, 2026
4 of 6 checks passed
rueian pushed a commit that referenced this pull request Nov 3, 2026
… clusters (#67724)

## Description

Updates the docs for #67523, which makes token authentication the
default for every cluster:

- `ray-security/token-auth.md` and
`core/internals/token-authentication.md`: who creates the token, how
nodes and clients get it, and the `RAY_AUTH_MODE=disabled` opt-out.
- `cluster/metrics.md`: scraping with the token, and
`RAY_AUTH_SKIP_METRICS`.
- VM, on-prem, Slurm, YARN, `starting-ray.md` and Serve `deploy-vm.md`:
create the token before `ray start --head`. The cluster YAML reference
documents the new `auth_mode` key.
- `conf.py`: removes the token-auth banner.

The KubeRay guide is left to #67057.

## Related issues

Closes #67056

---------

Signed-off-by: Chi-Sheng Liu <[email protected]>
Sparks0219 pushed a commit that referenced this pull request Nov 11, 2026
## Why

`test_advanced_9.py::test_redis_wrong_password` has failed both attempts
in every postmerge run of `:ray: core: redis tests` since build 20681
(2026-11-03), 20 of 20 runs (e.g. 20894). It passed in every run before
that.

The test runs `ray start --head --redis-password=1234` and expects the
Redis auth error. Since #67523 made token auth the default, `ray start
--head` exits first because no auth token exists:

```
PANIC scripts.py:1081 -- Token authentication is enabled but no authentication token was found.
```

#67523 added the `create_auth_token` fixture to the sibling
`test_redis_not_available` but not to this test. This test only runs in
the redis job, which premerge runs only when `src/ray/gcs/store_client/`
changes, so it never ran on that PR.

In every other job the test skips itself ("Only valid in redis env"), so
the `test_advanced_9` target looks flaky across jobs. It fails every
time in the redis job.

## Change

Add `create_auth_token` to `test_redis_wrong_password`, the same as
`test_redis_not_available`. The `ray start --head` subprocess then has a
token and fails on the wrong Redis password, as intended.

## Duplicate check

No open or closed issue/PR covers `test_redis_wrong_password` (searched
by test name and "redis wrong password auth token").

## Testing

- `pre-commit run --files python/ray/tests/test_advanced_9.py`: all
hooks pass.
- Not run locally (needs `TEST_EXTERNAL_REDIS=1` and a Redis server).
Opening as draft until the redis tests job passes on this branch;
premerge won't run it automatically because this PR doesn't touch
`src/ray/gcs/store_client/`.

AI assistance (Claude Code) was used for the investigation and the
change.

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

Signed-off-by: Kartica Modi <[email protected]>
Sparks0219 pushed a commit that referenced this pull request Nov 17, 2026
…ad it (#68262)

## Description

Since the Bazel 8 bump (#66483), Windows C++ tests that read the token
from the `auth_token_file` genrule (#67523) crash in setup with
`RAY_AUTH_TOKEN_PATH is set but file cannot be opened or is empty`. The
genrule's output comes from the remote cache and is never downloaded, so
the test's runfiles link points at a missing file. Tagging the genrule
`no-remote` makes every build generate it locally.

| Targets | Before | After |
|---|---|---|
| `open_telemetry_metric_recorder_test`, `object_manager_test`,
`node_manager_test`, `grpc_server_client_test`, `core_worker_test`,
`gcs_client_test` | failed 2/2, [postmerge
21056](https://buildkite.com/ray-project/postmerge/builds/21056) |
passed, [premerge
77225](https://buildkite.com/ray-project/premerge/builds/77225) |
| `global_state_accessor_test` | failed, [premerge
77216](https://buildkite.com/ray-project/premerge/builds/77216) |
passed, [premerge
77227](https://buildkite.com/ray-project/premerge/builds/77227) |

## Related issues

Related to #67047

Signed-off-by: Chi-Sheng Liu <[email protected]>
Kunchd added a commit that referenced this pull request Nov 23, 2026
…de and a readable token

ray up ships an auth token by default since #67523. A cluster YAML whose
image holds an older Ray (such as rayproject/ray:latest before 2.61 is
published) then gets a head that requires the token, because Ray < 2.61's
ray start --head turns on token mode when it finds a token file, while
workers and clients in the containers default to disabled and send none.
This fails every cluster-launcher release test that uses the latest image.

- Set RAY_AUTH_MODE to the YAML's auth_mode (token by default) in every
  container through the Docker run options, which the head's autoscaler
  also uses for worker containers.
- The token is bind mounted with the host SSH user's UID, which can differ
  from the container user's, as on GCP common-cpu images, where the head's
  autoscaler crashes with PermissionError reading it. Take ownership with
  sudo chown when the container user can't read it, as for the bootstrap
  files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: davik <[email protected]>
Sparks0219 pushed a commit that referenced this pull request Nov 23, 2026
## Description
The [post merge kuberay
tests](https://buildkite.com/ray-project/postmerge/builds/21065#01a1ea91-4a88-4d8e-862f-bc611fa93702)
are currently failing due to timeout. Upon, running the tests on master
locally via a kind cluster, we see the kuberay operator failing to bring
pods up due to:
```
PANIC scripts.py:1081 -- Token authentication is enabled but no authentication token was found. Run `ray get-auth-token --generate` to create one, then put that token on every node of the cluster before starting it.
```

This was because #67523 enabled
token authentication across the cluster by default. This meant that
simply starting the cluster with `ray start --head` without a token
present on the cluster will lead to the failure we see above. Instead,
the kuberay operator must create the token and pass it to the cluster.
This PR adds this mechanism to the kuberay post merge tests.

Once kuberay side comes up with a standard way of handling this in
future versions, we can get rid of this fix:
kuberay-project/kuberay#5496.

## Related issues

## Additional information
Kuberay test postmerge run:
https://buildkite.com/ray-project/postmerge/builds/21179

Signed-off-by: davik <[email protected]>
elliot-barn added a commit that referenced this pull request Nov 23, 2026
…ing token" (#68466) onto releases/2.61.0 (#68473)

## Description

Cherry-pick of #68466 (`65a0a1bd40`) onto `releases/2.61.0`. The KubeRay
chaos tests time out because token authentication is now on by default
(#67523) and the cluster starts without a token; this passes one
explicitly.

Clean pick. The two touched files (`ci/k8s/run-chaos-test.sh`,
`python/ray/tests/chaos/prepare_env.sh`) are identical to master after
the pick.

## Testing

Not run locally. The KubeRay tests run in the release branch's postmerge
build.

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

Signed-off-by: davik <[email protected]>
Signed-off-by: elliot-barn <[email protected]>
Co-authored-by: Kunchen (David) Dai <[email protected]>
rueian pushed a commit to kuberay-project/kuberay that referenced this pull request Nov 24, 2026
## Why are these changes needed?

Ray token auth is enabled by default in Ray 2.61
(ray-project/ray#67523). KubeRay assumed token
auth is disabled by default, so no `RAY_AUTH_MODE` is added when
`authOptions` is not set. Users get an auth error when they use Ray 2.61
with the current KubeRay version.


This PR makes the following changes:

1. Always set `RAY_AUTH_MODE` on every Ray container. Set to `token`
when `authOptions.mode` is `token`, otherwise `disabled`. A
user-provided `RAY_AUTH_MODE` is never overridden.
2. Add comments in `config/prometheus/podMonitor.yaml` on how to
configure Prometheus for a RayCluster with token auth enabled, since Ray
2.61 also requires the token on the metrics endpoints
(ray-project/ray#67119).


## Related issue number

Related to ray-project/ray#67057

## Labels

<!-- Please add the appropriate labels to this PR. -->

- [x] If this PR has user-facing changes that require documentation
updates at release time, I have added the `doc-updates-required` label.
    - doc PR: ray-project/ray#67897
- [ ] If this PR contains breaking changes, I have added the
`breaking-change` label.

## AI assistance

Yes, AI assisted coding and test, reviewed by me and all manual tests
run by me manually

## Checks

- [x] I've made sure the tests are passing.
- Testing Strategy
  - [x] Unit tests
  - [x] Manual tests
  - [ ] This PR is not tested :(

<!-- If you selected "Manual tests" above, please fill in the section
below. Otherwise you can remove it. -->

### Manual test instructions

Test results:
#5496 (comment)

Signed-off-by: machichima <[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.

[Core/Auth] Make token auth the default for all clusters, fix the tests it breaks, and remove local-cluster special cases

4 participants