-
Notifications
You must be signed in to change notification settings - Fork 7k
[Core] Support token auth in ray_syncer #58176
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
ce73705
341b108
c821c21
a14dc69
7834733
4801ed7
65c3ded
d24f23c
d801db6
f6017a0
b8bec0c
1ca6f2f
e9cc57f
f8c08e0
b128e4e
c8cff1d
a7a8efa
5a91771
5910ecf
d36e22f
4063d74
babc20f
63273bd
12c7c04
ae9345b
9ac5eff
1a571ed
10eb3b0
312522b
e3b8c3f
cd0f933
199d18e
537e90a
b5f2143
17601c8
3bc34f2
e5b90ba
acd95ac
c5be15f
f7f4ba2
2698b8d
8572c01
d47ae2b
d054131
2ee5555
ee6e775
06d1773
cc69ae3
06a71b4
8b4fc91
9f0a563
15aa5e2
47bb5b0
1c600e6
f23ea2e
4646909
1274e74
fe6bab4
75d19b7
78f8431
4e484ac
a2584d4
82d0b7c
b64bd44
f27a39a
b8f2d63
6d1a9c6
80c7743
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 |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |
| #include <string> | ||
| #include <utility> | ||
|
|
||
| #include "ray/common/constants.h" | ||
|
|
||
| namespace ray::syncer { | ||
|
|
||
| namespace { | ||
|
|
@@ -35,13 +37,39 @@ RayServerBidiReactor::RayServerBidiReactor( | |
| instrumented_io_context &io_context, | ||
| const std::string &local_node_id, | ||
| std::function<void(std::shared_ptr<const RaySyncMessage>)> message_processor, | ||
| std::function<void(RaySyncerBidiReactor *, bool)> cleanup_cb) | ||
| std::function<void(RaySyncerBidiReactor *, bool)> cleanup_cb, | ||
| const std::optional<ray::rpc::AuthenticationToken> &auth_token) | ||
| : RaySyncerBidiReactorBase<ServerBidiReactor>( | ||
| io_context, | ||
| GetNodeIDFromServerContext(server_context), | ||
| std::move(message_processor)), | ||
| cleanup_cb_(std::move(cleanup_cb)), | ||
| server_context_(server_context) { | ||
| server_context_(server_context), | ||
| auth_token_(auth_token) { | ||
| if (auth_token_.has_value() && !auth_token_->empty()) { | ||
|
Collaborator
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. hm why do we check both
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. this is to handle the case where AuthToken is present but it is an empty string (auth token loader should catch and throw an error in this scenario but added this extra check here just in case)
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. this can also be used as a way to disable token auth for a specific service without disabling for all. if we pass an AuthToken obj with empty string then we skip token auth within that service (this is the same behaviour for both raySyncer and grpcServer base class) |
||
| // Validate authentication token | ||
| const auto &metadata = server_context->client_metadata(); | ||
| auto it = metadata.find(kAuthTokenKey); | ||
| if (it == metadata.end()) { | ||
| RAY_LOG(WARNING) << "Missing authorization header in syncer connection from node " | ||
| << NodeID::FromBinary(GetRemoteNodeID()); | ||
| Finish(grpc::Status(grpc::StatusCode::UNAUTHENTICATED, | ||
| "Missing authorization header")); | ||
| return; | ||
| } | ||
|
|
||
| const std::string_view header(it->second.data(), it->second.length()); | ||
| ray::rpc::AuthenticationToken provided_token = | ||
| ray::rpc::AuthenticationToken::FromMetadata(header); | ||
|
|
||
| if (!auth_token_->Equals(provided_token)) { | ||
| RAY_LOG(WARNING) << "Invalid bearer token in syncer connection from node " | ||
| << NodeID::FromBinary(GetRemoteNodeID()); | ||
| Finish(grpc::Status(grpc::StatusCode::UNAUTHENTICATED, "Invalid bearer token")); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| // Send the local node id to the remote | ||
| server_context_->AddInitialMetadata("node_id", NodeID::FromBinary(local_node_id).Hex()); | ||
| StartSendInitialMetadata(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.