Repository navigation
[cherry-pick][2.59.0][Fix][Core/Auth] Pass auth token to image_uri containers and reuse it when ray.init() finds a local cluster (#66467) - #66582
Conversation
… 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]> (cherry picked from commit 5853ff1) Signed-off-by: elliot-barn <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request updates Ray's token authentication mechanism to automatically enable token authentication when ray.init() connects to a local cluster and a token is available. It also improves security by mounting the token file read-only into runtime environment containers instead of passing the token via environment variables. The review feedback highlights a potential issue where paths containing spaces could break the container volume mount argument, suggesting the use of shlex.quote to safely escape the path.
| env_vars.get("RAY_AUTH_TOKEN_PATH") or _get_default_token_path() | ||
| ) | ||
| if os.path.isfile(token_path): | ||
| container_command.extend(["-v", f"{token_path}:{token_path}:ro"]) |
There was a problem hiding this comment.
If the token_path contains spaces (which is common in user home directories on macOS and Windows, e.g., /Users/John Doe), joining the container_command list with spaces will cause the volume mount argument to be split incorrectly when executed by the shell. This will lead to container startup failures. Wrapping the volume mount argument with shlex.quote ensures that paths with spaces or special characters are safely escaped.
| container_command.extend(["-v", f"{token_path}:{token_path}:ro"]) | |
| import shlex | |
| container_command.extend(["-v", shlex.quote(f"{token_path}:{token_path}:ro")]) |
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:
image_uri/containerworkers getRAY_AUTH_MODE=tokenbut not the token file, so they crash on startup. Fix: mount the token file read-only and setRAY_AUTH_TOKEN_PATH.ray.init()can't connect to a local cluster started viaray start --headwith token auth whenRAY_AUTH_MODEis unset. Fix: reuse the existing token (and warn) when connecting to a running local cluster.Cherry-picked cleanly with
git cherry-pick -xfrom merge commit 5853ff1; the diff is identical to the upstream commit.Not a duplicate: no existing PR against
releases/2.59.0references #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