forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
matcher: Implement CEL matcher (envoyproxy#27527)
Signed-off-by: tyxia <[email protected]>
- Loading branch information
Showing
21 changed files
with
1,401 additions
and
29 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains 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 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 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 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 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 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 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 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 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,25 @@ | ||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_extension", | ||
"envoy_extension_package", | ||
) | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
envoy_extension_package() | ||
|
||
envoy_cc_extension( | ||
name = "cel_input_lib", | ||
srcs = ["cel_input.cc"], | ||
hdrs = ["cel_input.h"], | ||
extra_visibility = [ | ||
], | ||
deps = [ | ||
"//envoy/http:filter_interface", | ||
"//envoy/http:header_map_interface", | ||
"//source/common/http:header_utility_lib", | ||
"//source/common/http:utility_lib", | ||
"//source/extensions/filters/common/expr:evaluator_lib", | ||
"@envoy_api//envoy/type/matcher/v3:pkg_cc_proto", | ||
], | ||
) |
This file contains 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,18 @@ | ||
#include "source/extensions/matching/http/cel_input/cel_input.h" | ||
|
||
#include "envoy/registry/registry.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Matching { | ||
namespace Http { | ||
namespace CelInput { | ||
|
||
REGISTER_FACTORY(HttpCelDataInputFactory, | ||
Matcher::DataInputFactory<::Envoy::Http::HttpMatchingData>); | ||
|
||
} // namespace CelInput | ||
} // namespace Http | ||
} // namespace Matching | ||
} // namespace Extensions | ||
} // namespace Envoy |
This file contains 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,82 @@ | ||
#pragma once | ||
|
||
#include "envoy/http/filter.h" | ||
#include "envoy/matcher/matcher.h" | ||
#include "envoy/server/factory_context.h" | ||
#include "envoy/type/matcher/v3/http_inputs.pb.h" | ||
#include "envoy/type/matcher/v3/http_inputs.pb.validate.h" | ||
|
||
#include "source/common/http/header_utility.h" | ||
#include "source/common/http/utility.h" | ||
#include "source/extensions/filters/common/expr/evaluator.h" | ||
|
||
#include "xds/type/matcher/v3/http_inputs.pb.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Matching { | ||
namespace Http { | ||
namespace CelInput { | ||
|
||
using ::Envoy::Http::RequestHeaderMapOptConstRef; | ||
using ::Envoy::Http::ResponseHeaderMapOptConstRef; | ||
using ::Envoy::Http::ResponseTrailerMapOptConstRef; | ||
|
||
using BaseActivationPtr = std::unique_ptr<google::api::expr::runtime::BaseActivation>; | ||
|
||
// CEL matcher specific matching data | ||
class CelMatchData : public ::Envoy::Matcher::CustomMatchData { | ||
public: | ||
explicit CelMatchData(BaseActivationPtr activation) : activation_(std::move(activation)) {} | ||
BaseActivationPtr activation_; | ||
}; | ||
|
||
class HttpCelDataInput : public Matcher::DataInput<Envoy::Http::HttpMatchingData> { | ||
public: | ||
HttpCelDataInput() = default; | ||
Matcher::DataInputGetResult get(const Envoy::Http::HttpMatchingData& data) const override { | ||
RequestHeaderMapOptConstRef maybe_request_headers = data.requestHeaders(); | ||
ResponseHeaderMapOptConstRef maybe_response_headers = data.responseHeaders(); | ||
ResponseTrailerMapOptConstRef maybe_response_trailers = data.responseTrailers(); | ||
|
||
// Returns NotAvailable state when all of three below are empty. | ||
if (!maybe_request_headers && !maybe_response_headers && !maybe_response_trailers) { | ||
return {Matcher::DataInputGetResult::DataAvailability::NotAvailable, absl::monostate()}; | ||
} | ||
|
||
// CEL library supports mixed matching condition of request headers, response headers and | ||
// response trailers. | ||
std::unique_ptr<google::api::expr::runtime::BaseActivation> activation = | ||
Extensions::Filters::Common::Expr::createActivation( | ||
data.streamInfo(), maybe_request_headers.ptr(), maybe_response_headers.ptr(), | ||
maybe_response_trailers.ptr()); | ||
|
||
return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, | ||
std::make_unique<CelMatchData>(std::move(activation))}; | ||
} | ||
|
||
absl::string_view dataInputType() const override { return "cel_data_input"; } | ||
}; | ||
|
||
class HttpCelDataInputFactory : public Matcher::DataInputFactory<Envoy::Http::HttpMatchingData> { | ||
public: | ||
HttpCelDataInputFactory() = default; | ||
std::string name() const override { return "envoy.matching.inputs.cel_data_input"; } | ||
|
||
Matcher::DataInputFactoryCb<Envoy::Http::HttpMatchingData> | ||
createDataInputFactoryCb(const Protobuf::Message&, ProtobufMessage::ValidationVisitor&) override { | ||
return [] { return std::make_unique<HttpCelDataInput>(); }; | ||
} | ||
|
||
ProtobufTypes::MessagePtr createEmptyConfigProto() override { | ||
return std::make_unique<xds::type::matcher::v3::HttpAttributesCelMatchInput>(); | ||
} | ||
}; | ||
|
||
DECLARE_FACTORY(HttpCelDataInputFactory); | ||
|
||
} // namespace CelInput | ||
} // namespace Http | ||
} // namespace Matching | ||
} // namespace Extensions | ||
} // namespace Envoy |
Oops, something went wrong.