-
Notifications
You must be signed in to change notification settings - Fork 7k
[Core] Token Auth minor UX Improvements #58998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -942,12 +942,7 @@ def start( | |
| ) | ||
|
|
||
| # Ensure auth token is available if authentication mode is token | ||
| try: | ||
| ensure_token_if_auth_enabled(system_config, create_token_if_missing=False) | ||
| except ray.exceptions.AuthenticationError: | ||
| raise RuntimeError( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @edoakes I removed this as this was throwing a nested stack trace: I feel exposing the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have included the message from the runtime error in the |
||
| "Failed to load authentication token. To generate a token for local development, use `ray get-auth-token --generate`. For remote clusters, ensure that the token is propagated to all nodes of the cluster when token authentication is enabled." | ||
| ) | ||
| ensure_token_if_auth_enabled(system_config, create_token_if_missing=False) | ||
|
|
||
| node = ray._private.node.Node( | ||
| ray_params, head=True, shutdown_at_exit=block, spawn_reaper=block | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,68 @@ | ||
| """Tests for Ray exceptions.""" | ||
| import sys | ||
| from enum import Enum | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest | ||
|
|
||
| from ray.exceptions import AuthenticationError, RayError | ||
|
|
||
|
|
||
| class FakeAuthMode(Enum): | ||
| DISABLED = 0 | ||
| TOKEN = 1 | ||
| K8S = 2 | ||
|
|
||
|
|
||
| class TestAuthenticationError: | ||
| """Tests for AuthenticationError exception.""" | ||
|
|
||
| auth_doc_url = "https://docs.ray.io/en/latest/ray-security/auth.html" | ||
|
|
||
| def test_basic_creation(self): | ||
| """Test basic AuthenticationError creation.""" | ||
| """Test basic AuthenticationError creation and message format.""" | ||
| error = AuthenticationError("Token is missing") | ||
| error_str = str(error) | ||
|
|
||
| # Original message preserved | ||
| assert "Token is missing" in error_str | ||
| # Doc URL included | ||
| assert self.auth_doc_url in error_str | ||
|
|
||
| def test_is_ray_error_subclass(self): | ||
| """Test that AuthenticationError is a RayError subclass.""" | ||
| error = AuthenticationError("Test") | ||
| assert isinstance(error, RayError) | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "auth_mode,expected_note", | ||
| [ | ||
| (FakeAuthMode.DISABLED, "RAY_AUTH_MODE is currently 'disabled'"), | ||
| (FakeAuthMode.K8S, "RAY_AUTH_MODE is currently 'k8s'"), | ||
| (FakeAuthMode.TOKEN, None), | ||
| ], | ||
| ids=["disabled", "k8s", "token"], | ||
| ) | ||
| def test_auth_mode_note_in_message(self, auth_mode, expected_note): | ||
| """Test that error message includes auth mode note when not in token mode.""" | ||
| with patch.dict( | ||
| "sys.modules", | ||
| { | ||
| "ray._raylet": MagicMock( | ||
| AuthenticationMode=FakeAuthMode, | ||
| get_authentication_mode=lambda: auth_mode, | ||
| ) | ||
| }, | ||
| ): | ||
| error = AuthenticationError("Token is missing") | ||
| error_str = str(error) | ||
|
|
||
| assert "Token is missing" in error_str | ||
| if expected_note: | ||
| assert expected_note in error_str | ||
| else: | ||
| assert "RAY_AUTH_MODE is currently" not in error_str | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(pytest.main(["-v", __file__])) |
Uh oh!
There was an error while loading. Please reload this page.