Repository navigation
[Core/Auth] Create the auth token for ray.init() and test cluster heads, and require one for ray start --head - #67258
Conversation
… and require one for ray start --head Signed-off-by: Chi-Sheng Liu <[email protected]>
…from ray start --head Signed-off-by: Chi-Sheng Liu <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request enhances Ray's token authentication setup by introducing a --create-auth-token-if-missing flag for starting head nodes and test clusters, and updates both Python and C++ token loaders to skip leading blank lines when reading token files. The review feedback highlights two important issues: first, accessing e.message on a Python 3 exception in scripts.py will cause an AttributeError and should be replaced with str(e); second, suppressing OSError instead of only FileNotFoundError in authentication_token_setup.py would make the file-reading logic more robust against other file system errors.
Signed-off-by: Chi-Sheng Liu <[email protected]>
…049-create-on-head-start Signed-off-by: Chi-Sheng Liu <[email protected]> # Conflicts: # src/ray/rpc/authentication/authentication_token_loader.h # src/ray/rpc/authentication/tests/authentication_token_loader_test.cc
…f ray start's signature Signed-off-by: Chi-Sheng Liu <[email protected]>
…e hidden ray start flag Signed-off-by: Chi-Sheng Liu <[email protected]>
Signed-off-by: Chi-Sheng Liu <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request refactors Ray's token authentication setup by moving token generation and file creation logic from Python to C++ (AuthenticationTokenLoader::CreateTokenIfMissing). This enables drivers starting their own clusters in Java, C++, or Python to securely generate missing authentication tokens. Feedback on the changes suggests using java.nio.file.Files.createTempDirectory in Java to avoid predictable temporary directory collisions, and converting token_path to std::filesystem::path in C++ to properly support Windows home directories containing non-ASCII characters.
Signed-off-by: Chi-Sheng Liu <[email protected]>
Signed-off-by: Chi-Sheng Liu <[email protected]>
…n request Signed-off-by: Chi-Sheng Liu <[email protected]>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Signed-off-by: Chi-Sheng Liu <[email protected]>
…and unset RAY_AUTH_MODE on any Cluster constructor failure Signed-off-by: Chi-Sheng Liu <[email protected]>
…_AUTH_MODE Signed-off-by: Chi-Sheng Liu <[email protected]>
…049-create-on-head-start
…file with enable_token_auth=False Signed-off-by: Chi-Sheng Liu <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request migrates the authentication token generation and setup logic from Python to C++ (AuthenticationTokenLoader), enabling Java and C++ drivers to automatically generate missing tokens when starting their own clusters under token authentication mode. It also refactors the Python testing utilities (Cluster and AutoscalingCluster) to cleanly manage token authentication states. The review feedback highlights three key portability issues: the POSIX-specific setenv call in metric_example.cc will break Windows compilation, fchmod failures on non-POSIX filesystems (like NFS or FAT) should be gracefully handled rather than crashing token creation, and the hardcoded /tmp/ray/ path in RayNativeRuntime.java should be replaced with a platform-independent temporary directory property.
…tore RAY_AUTH_MODE on failed head starts, and pass the env to test_autoscaler_warn_infeasible's driver Signed-off-by: Chi-Sheng Liu <[email protected]>
…AUTH_MODE Signed-off-by: Chi-Sheng Liu <[email protected]>
…stops Ray, and compare it exactly Signed-off-by: Chi-Sheng Liu <[email protected]>
…en_auth only Signed-off-by: Chi-Sheng Liu <[email protected]>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit af34d30. Configure here.
…d fails Signed-off-by: Chi-Sheng Liu <[email protected]>
… pass auth to dashboard and CLI calls in tests Signed-off-by: Chi-Sheng Liu <[email protected]>
…049-create-on-head-start
…r's Cluster case with enable_token_auth=False Signed-off-by: Chi-Sheng Liu <[email protected]>
| self._previous_mode = os.environ.get(AUTH_MODE_ENV_VAR) | ||
| self._applied = True | ||
| _TestClusterAuthMode.active_count += 1 | ||
| os.environ[AUTH_MODE_ENV_VAR] = mode |
There was a problem hiding this comment.
Should have a follow-up to make this Cluster utility not depend on os.environ at all.
…ds, and require one for ray start --head (ray-project#67258) ## Description Once token auth is the default, every head start needs a token. Only entry points that start a throwaway cluster on this machine create one; `ray start --head` fails instead, because a token made there would not reach the cluster's worker nodes. | Entry point | Missing token | |---|---| | `ray.init()` starting a new cluster | Creates it | | `ray.cluster_utils.Cluster()`, `AutoscalingCluster` | Creates it before the head starts | | `Cluster(enable_token_auth=False)`, `AutoscalingCluster(enable_token_auth=False)` | Not needed: auth is off | | C++ / Java driver that starts its own cluster, with `RAY_AUTH_MODE=token` | Creates it before its `ray start --head` | | `ray get-auth-token --generate` | Creates it | | `ray start --head` | Fails before starting any process | | `ray start --address`, `ray.init(address=...)` | Never creates it | Every creator goes through one function in the C++ token loader, which already owns the token sources and their precedence: ```text AuthenticationTokenLoader::CreateTokenIfMissing() TryLoadToken(ignore_auth_mode=true) # any source has a token -> return mkdir ~/.ray (0700; a failed chmod only warns) write 32 RAND_bytes, hex-encoded, to ~/.ray/auth_token (0600) callers Python create_token_if_missing() # ray.init(), Cluster, AutoscalingCluster, get-auth-token --generate C++ process_helper.cc # driver that starts its own cluster Java nativeCreateTokenIfMissingForOwnCluster # library now loads before startRayHead ``` It replaces the Python `generate_and_save_token` and keeps its file format and mode. It never overwrites a file that holds a token, using the loader's first-non-blank-line rule from ray-project#67128. Starting several creators at the same moment in a fresh HOME is not supported, so there is no locking. `Cluster()` and `AutoscalingCluster` take a new argument, `enable_token_auth`, default `True`. It decides the cluster's mode whatever `RAY_AUTH_MODE` the test process had: ```text start head save RAY_AUTH_MODE; set it to token | disabled in this process reset RayConfig and the token cache token mode -> CreateTokenIfMissing() shutdown(), or a failed constructor / head add_node() / start() restore the saved RAY_AUTH_MODE (or unset it) ``` Because the test process holds the mode, its nodes, its own `ray.init(address=cluster.address)` and the subprocess drivers it starts all agree, so none is rejected for a mode mismatch (ray-project#67052). A `token` that an earlier `ray.init()` left in `RAY_AUTH_MODE` no longer matters. Tests that need auth off pass `enable_token_auth=False`, such as the `setup_cluster_without_token_auth` fixture and `test_kill_raylet_on_auth_disabled_cluster_with_token_file`. `test_autoscaler_warn_infeasible`'s driver now inherits the test process's environment, so it runs in the cluster's mode. - **Before:** `Cluster()` with token auth on and no token built `Node(head=True)`, its GCS crashed on `RAY_CHECK(has_token || ignore_auth_mode)`, and the user saw `Timed out waiting for file .../gcs_server_port_...`. `ray start --head` with no token raised `AuthenticationError`, with fix text telling the reader to copy the token from the head. **After:** `Cluster()` writes `~/.ray/auth_token` and starts in token mode. `ray start --head` with no token stops before starting anything: ```text Error: 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. ``` ## Related issues Closes ray-project#67049 ## Additional information `Cluster()` and `AutoscalingCluster` change their default: they now run with token auth on and write `~/.ray/auth_token` in HOME when no token exists, even while `AUTH_MODE` defaults to `disabled`. A test that builds one of them and starts a driver or `ray start` subprocess with an environment not copied from `os.environ` now fails against the token-mode cluster; pass `enable_token_auth=False` or copy the environment. Reverting this PR restores the old behavior; the token files it leaves in HOME are what a bare `ray.init()` already writes. Other changes while `AUTH_MODE` defaults to `disabled`: - `Cluster()` and `AutoscalingCluster` raise a `RuntimeError` when `_system_config` sets an `AUTH_MODE` other than the mode `enable_token_auth` picks, instead of a GCS timeout or `InvalidAuthToken` later. - With `RAY_AUTH_MODE=token` and no token, `ray start --head` fails with the CLI error above instead of `AuthenticationError`. - `ray get-auth-token --generate` reports a failed write as an error naming the path instead of a traceback; the Java driver throws a `RayException`. - The Java driver loads its native library before it starts the head. - A C++ / Java driver with `RAY_AUTH_MODE` unset still runs with auth off; ray-project#67055 makes token the default. `//cpp:metric_example` runs with `RAY_AUTH_MODE=token` and no token, pointing HOME at `TEST_TMPDIR` because Bazel's test runner leaves HOME unset. `java/test.sh` runs `RayDemo` with an empty HOME and checks the token file is non-empty. Not in this change: `ray up` doesn't call the new creator yet; that comes with shipping the token in ray-project#67050. --------- Signed-off-by: Chi-Sheng Liu <[email protected]>
…na dashboard (#67470) ## Problem - The Data LLM panel queries have no `{global_filters}` placeholder, so no global filter ever reaches the panels. Filters set through `RAY_GRAFANA_DATA_LLM_DASHBOARD_GLOBAL_FILTERS` only reach the model and worker dropdowns. - The dashboard has no `SessionName` or `Cluster` dropdown, unlike the Data, Default and Serve dashboards. - So with Worker ID set to All, every panel mixes vLLM engines from every cluster that Prometheus scrapes. Choosing a cluster does not narrow the panels. ## Change - Add `{global_filters}` to every Data LLM panel selector (38 queries). - Set `standard_global_filters` to the Data dashboard's filters: `SessionName=~"$SessionName"` and `ray_io_cluster=~"$Cluster"`. - Add `SessionName` and `Cluster` dropdowns, and narrow the model and worker dropdowns to the selected session and cluster. ``` before after SessionName ─ (no dropdown) SessionName ─┬─> model & worker dropdowns Cluster ───── (no dropdown) Cluster ─────┤ and every panel selector override ───> model & worker override ────┘ dropdowns only ``` Repro, which prints how many panel queries carry each filter and the dropdown names: ```bash RAY_GRAFANA_DATA_LLM_DASHBOARD_GLOBAL_FILTERS='ClusterId=~"$ClusterId"' python -c ' import json from ray.dashboard.modules.metrics.grafana_dashboard_factory import generate_data_llm_grafana_dashboard d = json.loads(generate_data_llm_grafana_dashboard()[0]) exprs = [t["expr"] for p in d["panels"] for t in p.get("targets", [])] print(len(exprs), sum("ClusterId=~" in e for e in exprs), sum("ray_io_cluster=~" in e for e in exprs)) print([v["name"] for v in d["templating"]["list"]])' ``` | | Before | After | |---|---|---| | Panel queries carrying the override filter | 0 of 38 | 38 of 38 | | Engines in Cache Utilization for one cluster, Worker ID = All (one real job) | 13 (5 from other jobs) | 8 | ### Before / after Cache Utilization on a managed Grafana, with one job's cluster selected and Worker ID = All. Before, engines from another job appear from 14:16; after, only this job's 8 engines appear, from 14:37. **Before:** <img width="1525" height="784" alt="1-cache-utilization-before" src="https://github.com/user-attachments/assets/6dcb3e95-eb82-44ad-9b58-ecb2cf99d000" /> **After:** <img width="1478" height="812" alt="1-cache-utilization-after-session-cluster" src="https://github.com/user-attachments/assets/c9c58477-7793-4d48-a3c6-894b7bcdd1ca" /> ## Decisions to confirm - The `SessionName` dropdown lists sessions from a vLLM metric (`ray_vllm_request_prompt_tokens_sum`) instead of `ray_data_output_bytes`. It then shows only sessions that ran vLLM. - The `SessionName` "All" value is `.*` rather than the Data dashboard's `.+`, so series without the label still show. ## Related - Not a duplicate: no open issue or PR covers this. #64596 (Serve LLM) and #49498 applied the same `Cluster` filter pattern to other dashboards. - Tests: `pytest python/ray/tests/test_metrics_head.py`: 15 passed, with 9 new Data LLM cases. Run on a checkout that matches the latest nightly wheel; on current master, the 4 cluster-start tests need a nightly that includes #67258. - AI assistance: written with Claude Code. I reviewed every line. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Marwan Sarieddine <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
## Description This PR makes the `lint: API param coverage` step a required check by removing `soft_fail: true`. The step was added in #64788 on 2026-08-11. A comment in the step said to remove `soft_fail` "once the false-positive rate is confirmed low." This PR measures that rate from the step's CI history and fixes the four failure patterns the history turned up. While the step only warns, undocumented parameters still land on master. #65633, #66602, and #66950 all merged with the check failing. ### Warn-phase metrics These numbers come from every `premerge` build from 2026-08-11 to 2026-10-29, pulled from the Buildkite API. | | Runs | PRs | |---|--:|--:| | Completed runs of the step | 3,453 | | | Passed | 3,398 | | | Failed | 55 | 23 | | Canceled, which isn't a check outcome | 211 | | Each failure falls into one of three groups: | Failure type | PRs | Runs | Detail | |---|--:|--:|---| | Correct finding | 15 | 42 | A new parameter on a `@PublicAPI` callable has no `Args:` entry. Two of these PRs, #65823 and #65839, were stacked on #65633 before it merged and report its findings again. | | False positive | 3 | 4 | #64399 flagged the `v` argument of a pydantic `@field_validator`. #66255 flagged the private kwarg `_direct_http`. #67258 flagged an option of the `ray start` Click command, which `help=` documents. | | Infrastructure | 5 | 9 | The step printed `could not determine merge-base` and no findings. The branches of #65437 and #65809 forked 520 and 598 master commits before their builds. The step's `git fetch --depth=500` makes the full CI clone shallow, so their merge-base wasn't in the fetched history. | That's 13 spurious failures out of 3,453 runs, about 0.4%, or 13 of 55 failures. Each one would block a PR once the step is required, so this PR fixes all four patterns before removing `soft_fail`. ### Changes - **`_`-prefixed parameters:** `api_param_coverage.py` skips parameters whose names start with `_`. That's Ray's convention for private kwargs, such as `ray.put(_owner=...)`, `tune.run(_remote=...)`, and `Deployment.options(_internal=...)`. On master, 31 public callables have such parameters. - **Pydantic validators and Click commands:** The script skips callables decorated with `field_validator`, `model_validator`, `validator`, `root_validator`, `command`, or `group`. On master, this removes 59 callables from scope. All of them are Click commands, such as `ray start` and `ray job submit`, or pydantic validators on Serve config models. None of them is a Python API whose parameters a docstring documents. - **Property setters:** The script also skips callables decorated with `@<name>.setter`. A setter's `value` is documented on the property's getter, which is the docstring Sphinx renders, not in an `Args:` section of its own. - **Shallow-clone merge-base:** When `git merge-base` fails after the depth-500 fetch, `ci/lint/lint.sh` runs `git fetch --unshallow` and retries. A branch within 500 commits of the base never reaches that path. The Python check still fails closed if the base can't be resolved after that. - **Step definition:** `.buildkite/lint.rayci.yml` drops `soft_fail: true` and the warn-phase comment. The `--blocking` help text in `cmd_check_api_param_coverage.py` no longer describes a warn phase. ## Related issues Follow-up to #64788. ## Additional information ### Testing - `pytest ci/ray_ci/doc/test_api_param_coverage.py`: 40 passed. That's the 28 existing tests plus 12 new cases covering `_` params, each validator spelling, Click command forms, and property setters. The test comments name the real PR that motivated each one. - **Replay against real PRs:** I ran the master and patched versions of the check against the exact commit and base of every failing run in each of the 18 PRs with findings. Master reproduces all 18 failures. The patched check passes #64399, #66255, and #67258, and reports the same findings as master on the other 15. - **Merge-base fix:** In a local repo with 600 commits on `master` and a branch forked at commit 50, `git fetch --depth=500` followed by `git merge-base` fails, which reproduces the CI failure. With the new `lint.sh` block, it resolves the correct fork commit. A branch forked 10 commits back resolves without the fallback. - `pre-commit run` on the changed files passes, including ruff, black, shellcheck, and docstyle. ### Duplicate check `gh pr list --state open --search "param coverage"` and `--search "api_param_coverage"` return no open PR that touches this check. The script hasn't changed since #65391 on 2026-08-14. ### AI assistance I used Claude Code to pull and classify the Buildkite history, draft the changes, and run the replay. I reviewed every changed line and the classification of every failing PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>

Description
Once token auth is the default, every head start needs a token. Only entry points that start a throwaway cluster on this machine create one;
ray start --headfails instead, because a token made there would not reach the cluster's worker nodes.ray.init()starting a new clusterray.cluster_utils.Cluster(),AutoscalingClusterCluster(enable_token_auth=False),AutoscalingCluster(enable_token_auth=False)RAY_AUTH_MODE=tokenray start --headray get-auth-token --generateray start --headray start --address,ray.init(address=...)Every creator goes through one function in the C++ token loader, which already owns the token sources and their precedence:
It replaces the Python
generate_and_save_tokenand keeps its file format and mode. It never overwrites a file that holds a token, using the loader's first-non-blank-line rule from #67128. Starting several creators at the same moment in a fresh HOME is not supported, so there is no locking.Cluster()andAutoscalingClustertake a new argument,enable_token_auth, defaultTrue. It decides the cluster's mode whateverRAY_AUTH_MODEthe test process had:Because the test process holds the mode, its nodes, its own
ray.init(address=cluster.address)and the subprocess drivers it starts all agree, so none is rejected for a mode mismatch (#67052). Atokenthat an earlierray.init()left inRAY_AUTH_MODEno longer matters. Tests that need auth off passenable_token_auth=False, such as thesetup_cluster_without_token_authfixture andtest_kill_raylet_on_auth_disabled_cluster_with_token_file.test_autoscaler_warn_infeasible's driver now inherits the test process's environment, so it runs in the cluster's mode.Before:
Cluster()with token auth on and no token builtNode(head=True), its GCS crashed onRAY_CHECK(has_token || ignore_auth_mode), and the user sawTimed out waiting for file .../gcs_server_port_....ray start --headwith no token raisedAuthenticationError, with fix text telling the reader to copy the token from the head.After:
Cluster()writes~/.ray/auth_tokenand starts in token mode.ray start --headwith no token stops before starting anything:Related issues
Closes #67049
Additional information
Cluster()andAutoscalingClusterchange their default: they now run with token auth on and write~/.ray/auth_tokenin HOME when no token exists, even whileAUTH_MODEdefaults todisabled. A test that builds one of them and starts a driver orray startsubprocess with an environment not copied fromos.environnow fails against the token-mode cluster; passenable_token_auth=Falseor copy the environment. Reverting this PR restores the old behavior; the token files it leaves in HOME are what a bareray.init()already writes.Other changes while
AUTH_MODEdefaults todisabled:Cluster()andAutoscalingClusterraise aRuntimeErrorwhen_system_configsets anAUTH_MODEother than the modeenable_token_authpicks, instead of a GCS timeout orInvalidAuthTokenlater.RAY_AUTH_MODE=tokenand no token,ray start --headfails with the CLI error above instead ofAuthenticationError.ray get-auth-token --generatereports a failed write as an error naming the path instead of a traceback; the Java driver throws aRayException.RAY_AUTH_MODEunset still runs with auth off; [Core/Auth] Make token auth the default for all clusters, fix the tests it breaks, and remove local-cluster special cases #67055 makes token the default.//cpp:metric_exampleruns withRAY_AUTH_MODE=tokenand no token, pointing HOME atTEST_TMPDIRbecause Bazel's test runner leaves HOME unset.java/test.shrunsRayDemowith an empty HOME and checks the token file is non-empty.Not in this change:
ray updoesn't call the new creator yet; that comes with shipping the token in #67050.