Skip to content

Commit df636a9

Browse files
committed
consolidate token validation logic
Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
1 parent 115c7f8 commit df636a9

File tree

2 files changed

+11
-27
lines changed

2 files changed

+11
-27
lines changed

src/ray/rpc/authentication/authentication_token_loader.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ bool AuthenticationTokenLoader::ValidateToken(const AuthenticationToken &provide
9090
return is_allowed;
9191
}
9292

93-
return false;
93+
return true;
9494
}
9595

9696
std::optional<AuthenticationToken> AuthenticationTokenLoader::GetToken() {

src/ray/rpc/server_call.h

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -346,43 +346,27 @@ class ServerCallImpl : public ServerCall {
346346
bool ValidateAuthenticationToken() {
347347
AuthenticationMode auth_mode = GetAuthenticationMode();
348348

349+
if (auth_mode == AuthenticationMode::DISABLED) {
350+
return true;
351+
}
352+
349353
const auto &metadata = context_.client_metadata();
350354
auto it = metadata.find(kAuthTokenKey);
351355

352356
if (auth_mode == AuthenticationMode::TOKEN) {
353357
if (!auth_token_.has_value() || auth_token_->empty()) {
354358
return true; // No auth required on server side
355359
}
356-
if (it == metadata.end()) {
357-
RAY_LOG(WARNING)
358-
<< "Missing authorization header in request for token auth mode!";
359-
return false;
360-
}
361-
const std::string_view header(it->second.data(), it->second.length());
362-
AuthenticationToken provided_token = AuthenticationToken::FromMetadata(header);
363-
if (!auth_token_->Equals(provided_token)) {
364-
RAY_LOG(WARNING) << "Invalid bearer token in request!";
365-
return false;
366-
}
367-
return true;
368360
}
369361

370-
if (auth_mode == AuthenticationMode::K8S) {
371-
if (it == metadata.end()) {
372-
RAY_LOG(WARNING) << "Missing authorization header in request for k8s auth mode!";
373-
return false;
374-
}
375-
const std::string_view header(it->second.data(), it->second.length());
376-
AuthenticationToken provided_token = AuthenticationToken::FromMetadata(header);
377-
if (provided_token.empty()) {
378-
RAY_LOG(WARNING) << "Empty bearer token in request for k8s auth mode!";
379-
return false;
380-
}
381-
return ray::rpc::AuthenticationTokenLoader::instance().ValidateToken(
382-
provided_token);
362+
if (it == metadata.end()) {
363+
RAY_LOG(WARNING) << "Missing authorization header in request for token auth mode!";
364+
return false;
383365
}
384366

385-
return true;
367+
const std::string_view header(it->second.data(), it->second.length());
368+
AuthenticationToken provided_token = AuthenticationToken::FromMetadata(header);
369+
return ray::rpc::AuthenticationTokenLoader::instance().ValidateToken(provided_token);
386370
}
387371

388372
/// Log the duration this query used

0 commit comments

Comments
 (0)