Repository navigation
feat: Add --headers/--verify to Ray State CLI and document State REST API - #61958
Anarion-zuo wants to merge 8 commits into
Conversation
… API Signed-off-by: aaronzuo <[email protected]>
7243d9d to
0af48e9
Compare
There was a problem hiding this comment.
Code Review
This pull request adds authentication support to the Ray State CLI via --headers and --verify flags, and also documents the State REST API. The changes are well-implemented, with corresponding updates to documentation and new unit tests. I've identified a couple of minor opportunities for refactoring to reduce code duplication, which would improve maintainability. Overall, this is a solid contribution that enhances the usability of Ray in secure environments.
| request_headers: Dict[str, Any] = {} | ||
| if headers: | ||
| request_headers.update(headers) | ||
| request_headers.update(get_auth_headers_if_auth_enabled(request_headers)) |
There was a problem hiding this comment.
This logic for preparing request headers is duplicated in list_logs (lines 1369-1372). To improve maintainability and avoid code duplication, consider extracting this logic into a private helper function.
For example, you could add:
def _prepare_request_headers(headers: Optional[Dict[str, Any]]) -> Dict[str, Any]:
"""Prepares request headers by adding auth headers if not present."""
request_headers = headers.copy() if headers else {}
auth_headers = get_auth_headers_if_auth_enabled(request_headers)
request_headers.update(auth_headers)
return request_headersAnd then call request_headers = _prepare_request_headers(headers) in both get_log and list_logs.
| headers=_handle_headers(headers), | ||
| verify=verify, |
There was a problem hiding this comment.
The _handle_headers function is called here and again on line 1133 when calling _print_log. This is slightly inefficient as it involves parsing the JSON string twice.
Consider calling _handle_headers once at the beginning of the log_cluster function and reusing the result:
def log_cluster(
ctx,
glob_filter: str,
address: Optional[str],
headers: Optional[str],
...
):
parsed_headers = _handle_headers(headers)
if node_id is None and node_ip is None:
node_ip = _get_head_node_ip(address)
logs = list_logs(
...,
headers=parsed_headers,
...
)
...
_print_log(
...,
headers=parsed_headers,
...
)Signed-off-by: aaronzuo <[email protected]>
Signed-off-by: aaronzuo <[email protected]>
Signed-off-by: aaronzuo <[email protected]>
edoakes
left a comment
There was a problem hiding this comment.
Look good. I don't love the --verify type overloading, but given it matches the job CLI no reason to revisit it here.
Can you also add one full integration test for the CLI running against an actual HTTP server? Either the real state API or a small fake one
|
|
||
|
|
||
| def test_state_cli_list_supports_headers_and_verify(monkeypatch): | ||
| import ray.util.state.state_cli as state_cli |
There was a problem hiding this comment.
should be no need for lazy import
| class DummyStateApiClient: | ||
| def __init__(self, address=None, headers=None, verify=True, **kwargs): | ||
| captured["address"] = address | ||
| captured["headers"] = headers | ||
| captured["verify"] = verify | ||
|
|
||
| def list(self, *args, **kwargs): | ||
| return [] |
There was a problem hiding this comment.
no need to duplicate this in each test, use one shared FakeStateApiClient that can be reused and evolved over time
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
Signed-off-by: aaronzuo <[email protected]>
|
@edoakes Resolved issues you mentioned.
To run the targeted tests: |
|
@Anarion-zuo I don't think we're willing to support the state API as a public REST API at the moment. Could you please remove that from this PR and I can merge the other changes? It makes sense in general, but I'd want to do a round of auditing the APIs before we advertise them. |
Signed-off-by: aaronzuo <[email protected]>
| If your cluster requires authentication, pass HTTP headers such as an | ||
| ``Authorization`` token to these endpoints. When using the State CLI, you can | ||
| use ``--headers`` for custom headers and ``--verify`` to control TLS verification. | ||
|
|
There was a problem hiding this comment.
REST API docs still present despite reviewer requesting removal
Low Severity
The "State REST API" documentation section (endpoints, query parameters, authentication notes) remains in this PR despite the reviewer explicitly requesting its removal with: "I don't think we're willing to support the state API as a public REST API at the moment. Could you please remove that from this PR and I can merge the other changes?" Publishing undocumented/unaudited API endpoints as official documentation could mislead users into depending on unstable interfaces.
Reviewed by Cursor Bugbot for commit 2ec51cb. Configure here.
Signed-off-by: aaronzuo <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Reviewed by Cursor Bugbot for commit f725488. Configure here.
Signed-off-by: aaronzuo <[email protected]>
|
@edoakes did as you commented |
|
There are many test failures, looks like an issue in the node startup path: https://buildkite.com/ray-project/premerge/builds/64702#019da541-3f0d-4e58-8da3-772dd3c92cf5/L20717 |
|
closing as stale, please re-open if you are still interested in contributing |


Summary
This PR makes Ray’s State CLI usable on authenticated / TLS-secured clusters by adding
--headersand--verifyflags (similar toray job), and documents the State REST API endpoints and query parameters.Resolved issue #50256.
Changes
--headersand--verifyto:ray list,ray get,ray summary (tasks|actors|objects), andray logs (...)RAY_STATE_HEADERSenv var as a default for--headersStateApiClient(..., headers=..., verify=...)get_log()/list_logs()acceptheadersandverifyTests
--headersparsing and propagationRAY_STATE_HEADERSenv var behaviorRun:
python -m pytest -q python/ray/tests/test_state_api.py -k "test_state_cli_"Usage example