-
Notifications
You must be signed in to change notification settings - Fork 5.5k
matchers: add input types for network streams #19493
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
aea58eb
add matching types for network streams
kyessenov f4ed5de
quoted
kyessenov 41e60d6
docs
kyessenov 89eaf62
tests
kyessenov ebb0634
coverage
kyessenov b8b15f8
Merge remote-tracking branch 'upstream/main' into tcp_data_inputs
kyessenov 7427533
coverage
kyessenov 35850bb
limit listener language
kyessenov eba5305
Merge remote-tracking branch 'upstream/main' into tcp_data_inputs
kyessenov 2eeae31
Merge remote-tracking branch 'upstream/main' into tcp_data_inputs
kyessenov eeef2bf
review
kyessenov 8da956e
Merge remote-tracking branch 'upstream/main' into tcp_data_inputs
kyessenov 93fd7fb
fix docs
kyessenov bc14d3e
Merge remote-tracking branch 'upstream/main' into tcp_data_inputs
kyessenov a35a28a
review
kyessenov 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py. | ||
|
|
||
| load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| api_proto_package( | ||
| deps = ["@com_github_cncf_udpa//udpa/annotations:pkg"], | ||
| ) |
88 changes: 88 additions & 0 deletions
88
api/envoy/extensions/matching/common_inputs/network/v3/network_inputs.proto
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,88 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.extensions.matching.common_inputs.network.v3; | ||
|
|
||
| import "udpa/annotations/status.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.extensions.matching.common_inputs.network.v3"; | ||
| option java_outer_classname = "NetworkInputsProto"; | ||
| option java_multiple_files = true; | ||
| option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/matching/common_inputs/network/v3;networkv3"; | ||
| option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
|
||
| // [#protodoc-title: Common Network Matching Inputs] | ||
|
|
||
| // Specifies that matching should be performed by the destination IP address. | ||
| message DestinationIPInput { | ||
| } | ||
|
|
||
| // Specifies that matching should be performed by the destination port. | ||
| message DestinationPortInput { | ||
| } | ||
|
|
||
| // Specifies that matching should be performed by the source IP address. | ||
| message SourceIPInput { | ||
| } | ||
|
|
||
| // Specifies that matching should be performed by the source port. | ||
| message SourcePortInput { | ||
| } | ||
|
|
||
| // Input that matches by the directly connected source IP address (this | ||
| // will only be different from the source IP address when using a listener | ||
| // filter that overrides the source address, such as the :ref:`Proxy Protocol | ||
| // listener filter <config_listener_filters_proxy_protocol>`). | ||
| message DirectSourceIPInput { | ||
| } | ||
|
|
||
| // Input that matches by the source IP type. | ||
| // Specifies the source IP match type. The values include: | ||
| // | ||
| // * ``local`` - matches a connection originating from the same host, | ||
| message SourceTypeInput { | ||
| } | ||
|
|
||
| // Input that matches by the requested server name (e.g. SNI in TLS). | ||
| // | ||
| // :ref:`TLS Inspector <config_listener_filters_tls_inspector>` provides the requested server name based on SNI, | ||
| // when TLS protocol is detected. | ||
| message ServerNameInput { | ||
| } | ||
|
|
||
| // Input that matches by the transport protocol. | ||
| // | ||
| // Suggested values include: | ||
| // | ||
| // * ``raw_buffer`` - default, used when no transport protocol is detected, | ||
| // * ``tls`` - set by :ref:`envoy.filters.listener.tls_inspector <config_listener_filters_tls_inspector>` | ||
| // when TLS protocol is detected. | ||
| message TransportProtocolInput { | ||
| } | ||
|
|
||
| // List of quoted and comma-separated requested application protocols. The list consists of a | ||
| // single negotiated application protocol once the network stream is established. | ||
| // | ||
| // Examples: | ||
| // | ||
| // * ``'h2','http/1.1'`` | ||
| // * ``'h2c'``` | ||
| // | ||
| // Suggested values in the list include: | ||
| // | ||
| // * ``http/1.1`` - set by :ref:`envoy.filters.listener.tls_inspector | ||
| // <config_listener_filters_tls_inspector>` and :ref:`envoy.filters.listener.http_inspector | ||
| // <config_listener_filters_http_inspector>`, | ||
| // * ``h2`` - set by :ref:`envoy.filters.listener.tls_inspector <config_listener_filters_tls_inspector>` | ||
| // * ``h2c`` - set by :ref:`envoy.filters.listener.http_inspector <config_listener_filters_http_inspector>` | ||
| // | ||
| // .. attention:: | ||
| // | ||
| // Currently, :ref:`TLS Inspector <config_listener_filters_tls_inspector>` provides | ||
| // application protocol detection based on the requested | ||
| // `ALPN <https://en.wikipedia.org/wiki/Application-Layer_Protocol_Negotiation>`_ values. | ||
| // | ||
| // However, the use of ALPN is pretty much limited to the HTTP/2 traffic on the Internet, | ||
| // and matching on values other than ``h2`` is going to lead to a lot of false negatives, | ||
| // unless all connecting clients are known to use ALPN. | ||
| message ApplicationProtocolInput { | ||
| } |
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,30 @@ | ||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_package", | ||
| ) | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "data_impl_lib", | ||
| hdrs = ["data_impl.h"], | ||
| deps = [ | ||
| "//envoy/network:filter_interface", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "inputs_lib", | ||
| srcs = ["inputs.cc"], | ||
| hdrs = ["inputs.h"], | ||
| deps = [ | ||
| "//envoy/matcher:matcher_interface", | ||
| "//envoy/network:filter_interface", | ||
| "//envoy/registry", | ||
| "//source/common/network:utility_lib", | ||
| "@envoy_api//envoy/extensions/matching/common_inputs/network/v3:pkg_cc_proto", | ||
| ], | ||
| ) |
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,24 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/network/filter.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Network { | ||
| namespace Matching { | ||
|
|
||
| /** | ||
| * Implementation of Network::MatchingData, providing connection-level data to | ||
| * the match tree. | ||
| */ | ||
| class MatchingDataImpl : public MatchingData { | ||
| public: | ||
| MatchingDataImpl(const ConnectionSocket& socket) : socket_(socket) {} | ||
| const ConnectionSocket& socket() const override { return socket_; } | ||
|
|
||
| private: | ||
| const ConnectionSocket& socket_; | ||
| }; | ||
|
|
||
| } // namespace Matching | ||
| } // namespace Network | ||
| } // namespace Envoy | ||
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,105 @@ | ||
| #include "source/common/network/matching/inputs.h" | ||
|
|
||
| #include "envoy/registry/registry.h" | ||
|
|
||
| #include "source/common/network/utility.h" | ||
|
|
||
| #include "absl/strings/str_cat.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Network { | ||
| namespace Matching { | ||
|
|
||
| Matcher::DataInputGetResult DestinationIPInput::get(const MatchingData& data) const { | ||
| const auto& address = data.socket().connectionInfoProvider().localAddress(); | ||
| if (address->type() != Network::Address::Type::Ip) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::nullopt}; | ||
| } | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, | ||
| address->ip()->addressAsString()}; | ||
| } | ||
|
|
||
| Matcher::DataInputGetResult DestinationPortInput::get(const MatchingData& data) const { | ||
| const auto& address = data.socket().connectionInfoProvider().localAddress(); | ||
| if (address->type() != Network::Address::Type::Ip) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::nullopt}; | ||
| } | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, | ||
| absl::StrCat(address->ip()->port())}; | ||
| } | ||
|
|
||
| Matcher::DataInputGetResult SourceIPInput::get(const MatchingData& data) const { | ||
| const auto& address = data.socket().connectionInfoProvider().remoteAddress(); | ||
| if (address->type() != Network::Address::Type::Ip) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::nullopt}; | ||
| } | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, | ||
| address->ip()->addressAsString()}; | ||
| } | ||
|
|
||
| Matcher::DataInputGetResult SourcePortInput::get(const MatchingData& data) const { | ||
| const auto& address = data.socket().connectionInfoProvider().remoteAddress(); | ||
| if (address->type() != Network::Address::Type::Ip) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::nullopt}; | ||
| } | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, | ||
| absl::StrCat(address->ip()->port())}; | ||
| } | ||
|
|
||
| Matcher::DataInputGetResult DirectSourceIPInput::get(const MatchingData& data) const { | ||
| const auto& address = data.socket().connectionInfoProvider().directRemoteAddress(); | ||
| if (address->type() != Network::Address::Type::Ip) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::nullopt}; | ||
| } | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, | ||
| address->ip()->addressAsString()}; | ||
| } | ||
|
|
||
| Matcher::DataInputGetResult SourceTypeInput::get(const MatchingData& data) const { | ||
| const bool is_local_connection = Network::Utility::isSameIpOrLoopback(data.socket()); | ||
| if (is_local_connection) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, "local"}; | ||
| } | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::nullopt}; | ||
| } | ||
|
|
||
| Matcher::DataInputGetResult ServerNameInput::get(const MatchingData& data) const { | ||
| const auto server_name = data.socket().requestedServerName(); | ||
| if (!server_name.empty()) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, | ||
| std::string(server_name)}; | ||
| } | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::nullopt}; | ||
| } | ||
|
|
||
| Matcher::DataInputGetResult TransportProtocolInput::get(const MatchingData& data) const { | ||
| const auto transport_protocol = data.socket().detectedTransportProtocol(); | ||
| if (!transport_protocol.empty()) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, | ||
| std::string(transport_protocol)}; | ||
| } | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::nullopt}; | ||
| } | ||
|
|
||
| Matcher::DataInputGetResult ApplicationProtocolInput::get(const MatchingData& data) const { | ||
| const auto& protocols = data.socket().requestedApplicationProtocols(); | ||
| if (!protocols.empty()) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, | ||
| absl::StrCat("'", absl::StrJoin(protocols, "','"), "'")}; | ||
| } | ||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::nullopt}; | ||
| } | ||
|
|
||
| REGISTER_FACTORY(DestinationIPInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(DestinationPortInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(SourceIPInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(SourcePortInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(DirectSourceIPInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(SourceTypeInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(ServerNameInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(TransportProtocolInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
| REGISTER_FACTORY(ApplicationProtocolInputFactory, Matcher::DataInputFactory<MatchingData>); | ||
|
|
||
| } // namespace Matching | ||
| } // namespace Network | ||
| } // namespace Envoy |
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.
Uh oh!
There was an error while loading. Please reload this page.