-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-10487 [FlightRPC][C++] Header-based auth in clients #8724
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
Closed
lyndonbauto
wants to merge
33
commits into
apache:master
from
jduo:jduo/lyndon/flight-auth-cpp-redesign-client
Closed
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
c2ba2c7
[1] Initial commit to support client header authentication in C++
lyndonbauto ab7d6a3
[1] Added integration test for client header authentication in C++ an…
lyndonbauto ecb533f
Merge branch 'lyndon/flight-auth-redesign-cpp' of https://github.com/…
lyndonbauto 73be3e7
[1] Updates for linting
lyndonbauto 74ef8ea
[1] Adding missed file.
lyndonbauto 29a3192
[1] Adding fix for Java lint errors.
lyndonbauto fac0bd0
[1] Added a couple comments
lyndonbauto 7fd1279
[1] Minor comment fixes
lyndonbauto 0b5a08e
[1] Addressed pull request comments, still need to address comments a…
lyndonbauto 6861cf0
[1] Added unit test.
lyndonbauto 01a134b
[1] Fixed linting issues
lyndonbauto de78c6b
[1] Fixing linting issues
lyndonbauto c44698f
[1] Removed some extra spaces at the end of some lines.
lyndonbauto e975fd8
[1] Correcting linting issues.
lyndonbauto 37889fa
[1] Minor cmake fix
lyndonbauto e7ac27c
[1] Trying different cmake spacing.
lyndonbauto ba7cb9f
[1] Trying different cmake
lyndonbauto 1426252
[1] Addressed code review comments.
lyndonbauto 516d993
[1] Removing integration test and reverting some cmake changes.
lyndonbauto 3000ecb
[1] Removed some no longer used functionality.
lyndonbauto 1de10fa
[1] Added improved testing and fixed linting.
lyndonbauto 065af4a
[1] Fixed lint issue
lyndonbauto d4da03b
Merge branch 'master' of https://github.com/apache/arrow into jduo/ly…
lyndonbauto 911fcc7
[1] Updating submodule
lyndonbauto f41edce
[1] Minor documentation fixes.
lyndonbauto 6b6fbbe
[1] Fixed casting issue on some builds
lyndonbauto 199b655
[1] Added missing parameter for documentation
lyndonbauto 47aa581
[1] Fixing cast.
lyndonbauto 477d865
[1] Moving std:: from toupper call because it causes break in some bu…
lyndonbauto 1cc3fdb
[1] Adding missed std remove
lyndonbauto d27465d
[1] Fixed linting issue.
lyndonbauto d21006f
[1] Updated test return error properly and to check for error
lyndonbauto 6cd8a45
[1] Fixed linting issue.
lyndonbauto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| // Interfaces for defining middleware for Flight clients. Currently | ||
| // experimental. | ||
|
|
||
| #include "arrow/flight/client_header_internal.h" | ||
| #include "arrow/flight/client.h" | ||
| #include "arrow/flight/client_auth.h" | ||
| #include "arrow/util/base64.h" | ||
| #include "arrow/util/make_unique.h" | ||
|
|
||
| #include <algorithm> | ||
| #include <cctype> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| const char kAuthHeader[] = "authorization"; | ||
| const char kBearerPrefix[] = "Bearer "; | ||
| const char kBasicPrefix[] = "Basic "; | ||
|
|
||
| namespace arrow { | ||
| namespace flight { | ||
| namespace internal { | ||
|
|
||
| // Add base64 encoded credentials to the outbound headers. | ||
| // | ||
| // @param context Context object to add the headers to. | ||
| // @param username Username to format and encode. | ||
| // @param password Password to format and encode. | ||
| void AddBasicAuthHeaders(grpc::ClientContext* context, const std::string& username, | ||
| const std::string& password) { | ||
| const std::string credentials = username + ":" + password; | ||
| context->AddMetadata( | ||
| kAuthHeader, | ||
| kBasicPrefix + arrow::util::base64_encode( | ||
| reinterpret_cast<const unsigned char*>(credentials.c_str()), | ||
| static_cast<unsigned int>(credentials.size()))); | ||
| } | ||
|
|
||
| // Get bearer token from inbound headers. | ||
| // | ||
| // @param context Incoming ClientContext that contains headers. | ||
| // @param bearer_token[out] Bearer token pointer to set. | ||
| void GetBearerTokenHeader(grpc::ClientContext& context, | ||
| std::pair<std::string, std::string>* bearer_token) { | ||
| // Lambda function to compare characters without case sensitivity. | ||
| auto char_compare = [](const char& char1, const char& char2) { | ||
| return (::toupper(char1) == ::toupper(char2)); | ||
| }; | ||
|
|
||
| // Get the auth token if it exists, this can be in the initial or the trailing metadata. | ||
| auto trailing_headers = context.GetServerTrailingMetadata(); | ||
| auto initial_headers = context.GetServerInitialMetadata(); | ||
| auto bearer_iter = trailing_headers.find(kAuthHeader); | ||
| if (bearer_iter == trailing_headers.end()) { | ||
| bearer_iter = initial_headers.find(kAuthHeader); | ||
| if (bearer_iter == initial_headers.end()) { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| // Check if the value of the auth token starts with the bearer prefix and latch it. | ||
| std::string bearer_val(bearer_iter->second.data(), bearer_iter->second.size()); | ||
| if (bearer_val.size() > strlen(kBearerPrefix)) { | ||
| if (std::equal(bearer_val.begin(), bearer_val.begin() + strlen(kBearerPrefix), | ||
| kBearerPrefix, char_compare)) { | ||
| *bearer_token = std::make_pair(kAuthHeader, bearer_val); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } // namespace internal | ||
| } // namespace flight | ||
| } // namespace arrow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| // Interfaces for defining middleware for Flight clients. Currently | ||
| // experimental. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "arrow/flight/client_middleware.h" | ||
|
|
||
| #ifdef GRPCPP_PP_INCLUDE | ||
| #include <grpcpp/grpcpp.h> | ||
| #if defined(GRPC_NAMESPACE_FOR_TLS_CREDENTIALS_OPTIONS) | ||
| #include <grpcpp/security/tls_credentials_options.h> | ||
| #endif | ||
| #else | ||
| #include <grpc++/grpc++.h> | ||
| #endif | ||
|
|
||
| namespace arrow { | ||
| namespace flight { | ||
| namespace internal { | ||
|
|
||
| /// \brief Add basic authentication header key value pair to context. | ||
| /// | ||
| /// \param context grpc context variable to add header to. | ||
| /// \param username username to encode into header. | ||
| /// \param password password to to encode into header. | ||
| void ARROW_FLIGHT_EXPORT AddBasicAuthHeaders(grpc::ClientContext* context, | ||
| const std::string& username, | ||
| const std::string& password); | ||
|
|
||
| /// \brief Get bearer token from incoming headers. | ||
| /// | ||
| /// \param context context that contains headers which hold the bearer token. | ||
| /// \param[out] bearer_token pointer to a std::pair of std::strings that the factory | ||
| /// will populate with the bearer token that is received from the server. | ||
| void ARROW_FLIGHT_EXPORT GetBearerTokenHeader( | ||
| grpc::ClientContext& context, std::pair<std::string, std::string>* bearer_token); | ||
|
|
||
| } // namespace internal | ||
| } // namespace flight | ||
| } // namespace arrow |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make this
arrow::Result<std::pair<>>?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I will make this change.