| 1 |
// Copyright 2021 gRPC authors. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
#ifndef GRPC_CORE_LIB_SECURITY_AUTHORIZATION_EVALUATE_ARGS_H |
| 16 |
#define GRPC_CORE_LIB_SECURITY_AUTHORIZATION_EVALUATE_ARGS_H |
| 17 |
|
| 18 |
#include <grpc/support/port_platform.h> |
| 19 |
|
| 20 |
#include <string> |
| 21 |
#include <vector> |
| 22 |
|
| 23 |
#include "absl/strings/string_view.h" |
| 24 |
#include "absl/types/optional.h" |
| 25 |
|
| 26 |
#include <grpc/grpc_security.h> |
| 27 |
|
| 28 |
#include "src/core/lib/iomgr/endpoint.h" |
| 29 |
#include "src/core/lib/iomgr/resolved_address.h" |
| 30 |
#include "src/core/lib/transport/metadata_batch.h" |
| 31 |
|
| 32 |
namespace grpc_core { |
| 33 |
|
| 34 |
class EvaluateArgs { |
| 35 |
public: |
| 36 |
// Caller is responsible for ensuring auth_context outlives PerChannelArgs |
| 37 |
// struct. |
| 38 |
struct PerChannelArgs { |
| 39 |
struct Address { |
| 40 |
// The address in sockaddr form. |
| 41 |
grpc_resolved_address address; |
| 42 |
// The same address with only the host part. |
| 43 |
std::string address_str; |
| 44 |
int port = 0; |
| 45 |
}; |
| 46 |
|
| 47 |
PerChannelArgs(grpc_auth_context* auth_context, grpc_endpoint* endpoint); |
| 48 |
|
| 49 |
absl::string_view transport_security_type; |
| 50 |
absl::string_view spiffe_id; |
| 51 |
std::vector<absl::string_view> uri_sans; |
| 52 |
std::vector<absl::string_view> dns_sans; |
| 53 |
absl::string_view common_name; |
| 54 |
absl::string_view subject; |
| 55 |
Address local_address; |
| 56 |
Address peer_address; |
| 57 |
}; |
| 58 |
|
| 59 |
EvaluateArgs(grpc_metadata_batch* metadata, PerChannelArgs* channel_args) |
| 60 |
: metadata_(metadata), channel_args_(channel_args) {} |
| 61 |
|
| 62 |
absl::string_view GetPath() const; |
| 63 |
absl::string_view GetAuthority() const; |
| 64 |
absl::string_view GetMethod() const; |
| 65 |
// Returns metadata value(s) for the specified key. |
| 66 |
// If the key is not present in the batch, returns absl::nullopt. |
| 67 |
// If the key is present exactly once in the batch, returns a string_view of |
| 68 |
// that value. |
| 69 |
// If the key is present more than once in the batch, constructs a |
| 70 |
// comma-concatenated string of all values in concatenated_value and returns a |
| 71 |
// string_view of that string. |
| 72 |
absl::optional<absl::string_view> GetHeaderValue( |
| 73 |
absl::string_view key, std::string* concatenated_value) const; |
| 74 |
|
| 75 |
grpc_resolved_address GetLocalAddress() const; |
| 76 |
absl::string_view GetLocalAddressString() const; |
| 77 |
int GetLocalPort() const; |
| 78 |
grpc_resolved_address GetPeerAddress() const; |
| 79 |
absl::string_view GetPeerAddressString() const; |
| 80 |
int GetPeerPort() const; |
| 81 |
absl::string_view GetTransportSecurityType() const; |
| 82 |
absl::string_view GetSpiffeId() const; |
| 83 |
std::vector<absl::string_view> GetUriSans() const; |
| 84 |
std::vector<absl::string_view> GetDnsSans() const; |
| 85 |
absl::string_view GetCommonName() const; |
| 86 |
absl::string_view GetSubject() const; |
| 87 |
|
| 88 |
private: |
| 89 |
grpc_metadata_batch* metadata_; |
| 90 |
PerChannelArgs* channel_args_; |
| 91 |
}; |
| 92 |
|
| 93 |
} // namespace grpc_core |
| 94 |
|
| 95 |
#endif // GRPC_CORE_LIB_SECURITY_AUTHORIZATION_EVALUATE_ARGS_H |