cel_authorization_engine.h
Go to the documentation of this file.
1 
2 // Copyright 2020 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef GRPC_CORE_LIB_SECURITY_AUTHORIZATION_CEL_AUTHORIZATION_ENGINE_H
17 #define GRPC_CORE_LIB_SECURITY_AUTHORIZATION_CEL_AUTHORIZATION_ENGINE_H
18 
20 
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include "absl/container/flat_hash_set.h"
29 #include "upb/upb.hpp"
30 
34 
35 namespace grpc_core {
36 
37 // CelAuthorizationEngine makes an AuthorizationDecision to ALLOW or DENY the
38 // current action based on the condition fields in provided RBAC policies.
39 // The engine may be constructed with one or two policies. If two polcies,
40 // the first policy is deny-if-matched and the second is allow-if-matched.
41 // The engine returns UNDECIDED decision if it fails to find a match in any
42 // policy. This engine ignores the principal and permission fields in RBAC
43 // policies. It is the caller's responsibility to provide RBAC policies that
44 // are compatible with this engine.
45 //
46 // Example:
47 // CelAuthorizationEngine* engine =
48 // CelAuthorizationEngine::CreateCelAuthorizationEngine(rbac_policies);
49 // engine->Evaluate(evaluate_args); // returns authorization decision.
51  public:
52  // rbac_policies must be a vector containing either a single policy of any
53  // kind, or one deny policy and one allow policy, in that order.
54  static std::unique_ptr<CelAuthorizationEngine> CreateCelAuthorizationEngine(
55  const std::vector<envoy_config_rbac_v3_RBAC*>& rbac_policies);
56 
57  // Users should use the CreateCelAuthorizationEngine factory function
58  // instead of calling the CelAuthorizationEngine constructor directly.
59  explicit CelAuthorizationEngine(
60  const std::vector<envoy_config_rbac_v3_RBAC*>& rbac_policies);
61  // TODO(mywang@google.com): add an Evaluate member function.
62 
63  private:
64  enum Action {
67  };
68 
69  std::unique_ptr<mock_cel::Activation> CreateActivation(
70  const EvaluateArgs& args);
71 
72  std::map<const std::string, const google_api_expr_v1alpha1_Expr*>
74  std::map<const std::string, const google_api_expr_v1alpha1_Expr*>
79  std::unique_ptr<mock_cel::CelMap> headers_;
80 };
81 
82 } // namespace grpc_core
83 
84 #endif /* GRPC_CORE_LIB_SECURITY_AUTHORIZATION_CEL_AUTHORIZATION_ENGINE_H */
rbac.upb.h
grpc_core::EvaluateArgs
Definition: evaluate_args.h:34
syntax.upb.h
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::CelAuthorizationEngine::Action
Action
Definition: cel_authorization_engine.h:64
grpc_core::CelAuthorizationEngine::kAllow
@ kAllow
Definition: cel_authorization_engine.h:65
grpc_core::CelAuthorizationEngine::allow_if_matched_
std::map< const std::string, const google_api_expr_v1alpha1_Expr * > allow_if_matched_
Definition: cel_authorization_engine.h:75
evaluate_args.h
grpc_core::CelAuthorizationEngine::CreateActivation
std::unique_ptr< mock_cel::Activation > CreateActivation(const EvaluateArgs &args)
Definition: cel_authorization_engine.cc:104
grpc_core::CelAuthorizationEngine::CelAuthorizationEngine
CelAuthorizationEngine(const std::vector< envoy_config_rbac_v3_RBAC * > &rbac_policies)
Definition: cel_authorization_engine.cc:70
grpc_core::CelAuthorizationEngine::kDeny
@ kDeny
Definition: cel_authorization_engine.h:66
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
activation.h
absl::flat_hash_set< std::string >
grpc_core::CelAuthorizationEngine::arena_
upb::Arena arena_
Definition: cel_authorization_engine.h:76
grpc_core::CelAuthorizationEngine
Definition: cel_authorization_engine.h:50
grpc_core::CelAuthorizationEngine::envoy_attributes_
absl::flat_hash_set< std::string > envoy_attributes_
Definition: cel_authorization_engine.h:77
upb::Arena
Definition: upb.hpp:68
grpc_core::CelAuthorizationEngine::header_keys_
absl::flat_hash_set< std::string > header_keys_
Definition: cel_authorization_engine.h:78
upb.hpp
grpc_core::CelAuthorizationEngine::deny_if_matched_
std::map< const std::string, const google_api_expr_v1alpha1_Expr * > deny_if_matched_
Definition: cel_authorization_engine.h:73
grpc_core::CelAuthorizationEngine::CreateCelAuthorizationEngine
static std::unique_ptr< CelAuthorizationEngine > CreateCelAuthorizationEngine(const std::vector< envoy_config_rbac_v3_RBAC * > &rbac_policies)
Definition: cel_authorization_engine.cc:51
cel_value.h
port_platform.h
grpc_core::CelAuthorizationEngine::headers_
std::unique_ptr< mock_cel::CelMap > headers_
Definition: cel_authorization_engine.h:79


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:43