Skip to content

Conversation

@sampan-s-nayak
Copy link
Contributor

Verify token presence when using ray start CLI + tests

sampan and others added 30 commits October 16, 2025 08:35
- Created RayAuthTokenLoader singleton class with thread-safe token caching
- Loads tokens from RAY_AUTH_TOKEN env, RAY_AUTH_TOKEN_PATH, or ~/.ray/auth_token
- Support for token generation with UUID (cross-platform)
- Modified GrpcServer to store and pass auth token to ServerCallImpl
- Updated RPC_SERVICE_HANDLER macros to pass auth token
- GCS server now loads token using RayAuthTokenLoader
- Removed auth_token from RayConfig (now loaded via loader)
- Token precedence: env var -> path env var -> default file path

Signed-off-by: sampan <[email protected]>
- Created Python auth_token_loader module with thread-safe token caching
- Loads tokens from same precedence as C++: RAY_AUTH_TOKEN, RAY_AUTH_TOKEN_PATH, ~/.ray/auth_token
- Added enable_token_auth parameter to ray.init() with auto-generation support
- Added --enable-token-auth flag to ray start CLI (fails if no token found)
- Only pass enable_token_auth flag via system_config, not the token
- Each side (C++/Python) loads tokens independently using their own loaders
- ray.init() auto-generates token if not found, ray start fails with helpful error

Signed-off-by: sampan <[email protected]>
- Test token loading from RAY_AUTH_TOKEN environment variable
- Test token loading from RAY_AUTH_TOKEN_PATH file
- Test token loading from default ~/.ray/auth_token path
- Test precedence order (env var > path env var > default file)
- Test token generation with GetToken(true)
- Test token caching behavior
- Test thread safety with concurrent GetToken calls
- Test whitespace trimming from token files
- Test behavior when no token is found

Signed-off-by: sampan <[email protected]>
- Test token loading from RAY_AUTH_TOKEN environment variable
- Test token loading from RAY_AUTH_TOKEN_PATH file
- Test token loading from default ~/.ray/auth_token path
- Test precedence order (env var > path env var > default file)
- Test token generation with generate_if_not_found=True
- Test token caching behavior across multiple calls
- Test has_auth_token() function
- Test thread safety with concurrent loads and generation
- Test whitespace handling and empty values
- Test file permissions on Unix systems (0600)
- Test error handling for permission errors
- Test integration with fixtures and cleanup

Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
@sampan-s-nayak sampan-s-nayak requested a review from a team as a code owner October 29, 2025 06:52
@sampan-s-nayak sampan-s-nayak changed the base branch from master to token_auth_4 October 29, 2025 06:53
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 introduces token-based authentication for Ray, focusing on the ray start CLI and the dashboard. The changes are well-structured, with new modules for authentication setup and utilities. The core logic for token generation, storage, and validation appears correct. The integration with ray.init, ray start, and the dashboard middleware is also well-implemented. The accompanying tests are thorough, covering various success and failure scenarios for both ray.init and ray start, as well as dashboard requests.

I have a few suggestions for improvement, mainly around code simplification and documentation consistency. For example, there's a redundant try...except block and an incorrect docstring in the token setup file. Also, a redundant check in the dashboard authentication middleware can be removed.

Overall, this is a solid contribution that enhances Ray's security posture.

@ray-gardener ray-gardener bot added the core Issues that should be addressed in Ray Core label Oct 29, 2025
@sampan-s-nayak sampan-s-nayak added the go add ONLY when ready to merge, run all tests label Oct 29, 2025
@edoakes edoakes changed the base branch from token_auth_4 to master October 30, 2025 14:21
@edoakes edoakes changed the base branch from master to token_auth_4 October 30, 2025 14:21
Base automatically changed from token_auth_4 to master October 30, 2025 21:25
@edoakes edoakes enabled auto-merge (squash) October 30, 2025 22:21
@github-actions github-actions bot disabled auto-merge October 31, 2025 03:18
@edoakes edoakes merged commit 0e9a15a into master Oct 31, 2025
6 checks passed
@edoakes edoakes deleted the token_auth_5 branch October 31, 2025 12:48
YoussefEssDS pushed a commit to YoussefEssDS/ray that referenced this pull request Nov 8, 2025
)

Verify token presence when using ray start CLI  + tests

---------

Signed-off-by: sampan <[email protected]>
Signed-off-by: Sampan S Nayak <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Co-authored-by: sampan <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
landscapepainter pushed a commit to landscapepainter/ray that referenced this pull request Nov 17, 2025
)

Verify token presence when using ray start CLI  + tests

---------

Signed-off-by: sampan <[email protected]>
Signed-off-by: Sampan S Nayak <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Co-authored-by: sampan <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Aydin-ab pushed a commit to Aydin-ab/ray-aydin that referenced this pull request Nov 19, 2025
)

Verify token presence when using ray start CLI  + tests

---------

Signed-off-by: sampan <[email protected]>
Signed-off-by: Sampan S Nayak <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Co-authored-by: sampan <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: Aydin Abiar <[email protected]>
SheldonTsen pushed a commit to SheldonTsen/ray that referenced this pull request Dec 1, 2025
)

Verify token presence when using ray start CLI  + tests

---------

Signed-off-by: sampan <[email protected]>
Signed-off-by: Sampan S Nayak <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Co-authored-by: sampan <[email protected]>
Co-authored-by: Edward Oakes <[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