24 #include "absl/memory/memory.h"
25 #include "absl/strings/string_view.h"
26 #include "absl/types/optional.h"
27 #include "absl/types/span.h"
37 constexpr
char kUrlPath[] =
"url_path";
38 constexpr
char kHost[] =
"host";
39 constexpr
char kMethod[] =
"method";
40 constexpr
char kHeaders[] =
"headers";
41 constexpr
char kSourceAddress[] =
"source_address";
42 constexpr
char kSourcePort[] =
"source_port";
43 constexpr
char kDestinationAddress[] =
"destination_address";
44 constexpr
char kDestinationPort[] =
"destination_port";
45 constexpr
char kSpiffeId[] =
"spiffe_id";
46 constexpr
char kCertServerName[] =
"cert_server_name";
50 std::unique_ptr<CelAuthorizationEngine>
52 const std::vector<envoy_config_rbac_v3_RBAC*>& rbac_policies) {
53 if (rbac_policies.empty() || rbac_policies.size() > 2) {
55 "Invalid rbac policies vector. Must contain either one or two rbac "
58 }
else if (rbac_policies.size() == 2 &&
62 "Invalid rbac policies vector. Must contain one deny \
63 policy and one allow policy, in that order.");
66 return absl::make_unique<CelAuthorizationEngine>(rbac_policies);
71 const std::vector<envoy_config_rbac_v3_RBAC*>& rbac_policies) {
72 for (
const auto& rbac_policy : rbac_policies) {
79 rbac_policy, &policy_num)) !=
nullptr) {
83 policy_name_strview.
size);
91 condition, temp_arena.
ptr(), &serial_len);
106 std::unique_ptr<mock_cel::Activation> activation;
108 if (
elem == kUrlPath) {
110 if (!url_path.
empty()) {
111 activation->InsertValue(kUrlPath,
114 }
else if (
elem == kHost) {
117 activation->InsertValue(kHost,
120 }
else if (
elem == kMethod) {
123 activation->InsertValue(kMethod,
126 }
else if (
elem == kHeaders) {
127 std::vector<std::pair<mock_cel::CelValue, mock_cel::CelValue>>
132 args.GetHeaderValue(header_key, &temp_value);
134 header_items.push_back(
135 std::pair<mock_cel::CelValue, mock_cel::CelValue>(
141 absl::Span<std::pair<mock_cel::CelValue, mock_cel::CelValue>>(
143 activation->InsertValue(kHeaders,
145 }
else if (
elem == kSourceAddress) {
147 if (!source_address.
empty()) {
148 activation->InsertValue(
152 }
else if (
elem == kSourcePort) {
153 activation->InsertValue(
155 }
else if (
elem == kDestinationAddress) {
157 if (!destination_address.
empty()) {
158 activation->InsertValue(
162 }
else if (
elem == kDestinationPort) {
164 args.GetLocalPort()));
165 }
else if (
elem == kSpiffeId) {
167 if (!spiffe_id.
empty()) {
168 activation->InsertValue(
171 }
else if (
elem == kCertServerName) {
173 if (!cert_server_name.
empty()) {
174 activation->InsertValue(
180 "Error: Authorization engine does not support evaluating "