Skip to content

[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

Merged
elliot-barn merged 1 commit into
releases/2.59.0from
cherry-pick-66467-2.59.0
Sep 29, 2026
Merged

elliot-barn merged 1 commit into
releases/2.59.0from
cherry-pick-66467-2.59.0

Conversation

@elliot-barn

Copy link
Copy Markdown
Collaborator

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

… 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]>
@elliot-barn
elliot-barn requested review from a team as code owners September 29, 2026 22:29
@elliot-barn
elliot-barn merged commit 3a22cdb into releases/2.59.0 Sep 29, 2026
3 of 5 checks passed
@elliot-barn
elliot-barn deleted the cherry-pick-66467-2.59.0 branch September 29, 2026 22:30

@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 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"])

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.

high

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.

Suggested change
container_command.extend(["-v", f"{token_path}:{token_path}:ro"])
import shlex
container_command.extend(["-v", shlex.quote(f"{token_path}:{token_path}:ro")])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants