-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
listeners: add unified matcher for filter chains #20110
Changes from all commits
6a37223
8aa165f
cfdb93a
a13ed92
621fcbf
2228fef
b610420
f45bc06
bada313
3f8f8e4
937f7a8
9fd0f34
595eb18
7d7909a
9a56f14
262d084
76e5040
3b92ec5
03fbfc6
ddeeaf9
be4636d
72b978e
e981df6
a9b056a
987a2fd
0185225
d1c8f75
a4dcf21
2cd4931
e896186
d5feb5f
d0f78a4
0831118
559341f
bf77d77
2451c0a
7b2bbe6
15ae545
65143c5
98619c8
d661a00
2e640a2
9bac339
98e15d8
2d24544
5a57b4d
eb3da3c
2015ccf
5ab50c6
efbe36a
b32362e
45a8482
7b97140
468d702
e436cdf
74c2f58
c611e2d
8ac6a1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
static_resources: | ||
listeners: | ||
- name: outbound | ||
address: | ||
socket_address: | ||
protocol: TCP | ||
address: 0.0.0.0 | ||
port_value: 15000 | ||
listener_filters: | ||
- name: original_dst | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.filters.listener.original_dst.v3.OriginalDst | ||
traffic_direction: OUTBOUND | ||
filter_chains: | ||
- name: http | ||
filters: | ||
- name: http_connection_manager | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager | ||
stat_prefix: ingress_http | ||
route_config: | ||
name: local_route | ||
virtual_hosts: | ||
- name: local_service | ||
domains: ["*"] | ||
routes: | ||
- match: | ||
prefix: "/" | ||
route: | ||
cluster: some_service | ||
http_filters: | ||
- name: router | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router | ||
- name: internal | ||
filters: | ||
- name: tcp_proxy | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy | ||
stat_prefix: internal | ||
cluster: some_service | ||
- name: tls | ||
transport_socket: | ||
name: tls | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext | ||
common_tls_context: | ||
tls_certificates: | ||
- certificate_chain: {filename: "certs/servercert.pem"} | ||
private_key: {filename: "certs/serverkey.pem"} | ||
filters: | ||
- name: tcp_proxy | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy | ||
stat_prefix: tls | ||
cluster: some_service | ||
# Snippet: 58-102 | ||
filter_chain_matcher: | ||
matcher_tree: | ||
input: | ||
name: port | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.matching.common_inputs.network.v3.DestinationPortInput | ||
exact_match_map: | ||
map: | ||
"80": | ||
action: | ||
name: http | ||
typed_config: | ||
"@type": type.googleapis.com/google.protobuf.StringValue | ||
value: http | ||
"443": | ||
matcher: | ||
matcher_tree: | ||
input: | ||
name: ip | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.matching.common_inputs.network.v3.SourceIPInput | ||
htuch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
custom_match: | ||
name: ip-matcher | ||
typed_config: | ||
"@type": type.googleapis.com/xds.type.matcher.v3.IPMatcher | ||
range_matchers: | ||
- ranges: | ||
- address_prefix: 192.0.0.0 | ||
prefix_len: 2 | ||
- address_prefix: 10.0.0.0 | ||
prefix_len: 24 | ||
on_match: | ||
action: | ||
name: internal | ||
typed_config: | ||
"@type": type.googleapis.com/google.protobuf.StringValue | ||
value: internal | ||
- ranges: | ||
- address_prefix: 0.0.0.0 | ||
on_match: | ||
action: | ||
name: tls | ||
typed_config: | ||
"@type": type.googleapis.com/google.protobuf.StringValue | ||
value: tls | ||
|
||
clusters: | ||
- name: some_service | ||
load_assignment: | ||
cluster_name: some_service | ||
endpoints: | ||
- lb_endpoints: | ||
- endpoint: | ||
address: | ||
socket_address: | ||
address: 10.1.2.10 | ||
port_value: 10002 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
static_resources: | ||
listeners: | ||
- name: outbound | ||
address: | ||
socket_address: | ||
protocol: TCP | ||
address: 0.0.0.0 | ||
port_value: 8443 | ||
listener_filters: | ||
- name: tls_inspector | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.filters.listener.tls_inspector.v3.TlsInspector | ||
filter_chains: | ||
- name: tls | ||
transport_socket: | ||
name: tls | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext | ||
common_tls_context: | ||
tls_certificates: | ||
- certificate_chain: {filename: "certs/servercert.pem"} | ||
private_key: {filename: "certs/serverkey.pem"} | ||
filters: | ||
- name: tcp_proxy | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy | ||
stat_prefix: tls | ||
cluster: some_service | ||
- name: plaintext | ||
filters: | ||
- name: tcp_proxy | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy | ||
stat_prefix: plaintext | ||
cluster: some_service | ||
# Snippet: 37-56 | ||
filter_chain_matcher: | ||
matcher_tree: | ||
input: | ||
name: transport | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.matching.common_inputs.network.v3.TransportProtocolInput | ||
exact_match_map: | ||
map: | ||
"tls": | ||
action: | ||
name: tls | ||
typed_config: | ||
"@type": type.googleapis.com/google.protobuf.StringValue | ||
value: tls | ||
Comment on lines
+46
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I am missing some context, but could this be simplified to just have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a proposal cncf/xds#28. |
||
on_no_match: | ||
action: | ||
name: plaintext | ||
typed_config: | ||
"@type": type.googleapis.com/google.protobuf.StringValue | ||
value: plaintext | ||
|
||
clusters: | ||
- name: some_service | ||
load_assignment: | ||
cluster_name: some_service | ||
endpoints: | ||
- lb_endpoints: | ||
- endpoint: | ||
address: | ||
socket_address: | ||
address: 10.1.2.10 | ||
port_value: 10002 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
static_resources: | ||
listeners: | ||
- name: outbound | ||
address: | ||
socket_address: | ||
protocol: TCP | ||
address: 0.0.0.0 | ||
port_value: 15000 | ||
listener_filters: | ||
- name: proxy_protocol | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.filters.listener.proxy_protocol.v3.ProxyProtocol | ||
filter_chains: | ||
- name: vip | ||
filters: | ||
- name: tcp_proxy | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy | ||
stat_prefix: vip | ||
cluster: original_dst | ||
- name: default | ||
filters: | ||
- name: tcp_proxy | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy | ||
stat_prefix: default | ||
cluster: original_dst | ||
# Snippet: 29-48 | ||
filter_chain_matcher: | ||
matcher_tree: | ||
input: | ||
name: destination_ip | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.matching.common_inputs.network.v3.DestinationIPInput | ||
prefix_match_map: | ||
map: | ||
"10.0.0.": | ||
action: | ||
name: vip | ||
typed_config: | ||
"@type": type.googleapis.com/google.protobuf.StringValue | ||
value: vip | ||
on_no_match: | ||
action: | ||
name: default | ||
typed_config: | ||
"@type": type.googleapis.com/google.protobuf.StringValue | ||
value: default | ||
|
||
clusters: | ||
- name: original_dst | ||
type: ORIGINAL_DST | ||
lb_policy: CLUSTER_PROVIDED |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ Generic Matching | |
:maxdepth: 2 | ||
|
||
matching_api | ||
matching_listener |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
.. _arch_overview_matching_listener: | ||
|
||
Matching Filter Chains in Listeners | ||
=================================== | ||
|
||
Envoy listeners implement the :ref:`matching API <envoy_v3_api_msg_.xds.type.matcher.v3.Matcher>` for selecting a filter | ||
chain based on a collection of :ref:`network inputs <extension_category_envoy.matching.network.input>`. Matching is done | ||
once per connection. Connections are drained when the associated named filter chain configuration changes, but not when | ||
the filter chain matcher is the only updated field in a listener. | ||
|
||
The action in the matcher API must be a string value corresponding to the name of the filter chain. If there is no | ||
filter chain with the given name, the match fails, and the :ref:`default filter chain | ||
<envoy_v3_api_field_config.listener.v3.Listener.default_filter_chain>` is used if specified, or the connection is | ||
rejected. Filter chain matcher requires that all filter chains in a listener are uniquely named. | ||
|
||
The matcher API replaces the existing filter :ref:`filter_chain_match | ||
<envoy_v3_api_field_config.listener.v3.FilterChain.filter_chain_match>` field. When using the matcher API, the filter | ||
chain match field is ignored and should not be set. | ||
Comment on lines
+16
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be exposed to the user in some way? ie fail the config or at the very least log something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a debug log. Failing might complicate migration IMHO, so just ignoring the field seems reasonable as it is an opt-in feature. |
||
|
||
Examples | ||
######## | ||
|
||
Detect TLS traffic | ||
****************** | ||
|
||
The following examples uses :ref:`tls_inspector <config_listener_filters_tls_inspector>` listener filter to detect | ||
whether the transport appears to be TLS, in which case the matcher in the listener selects the filter chain ``tls``. | ||
Otherwise, the filter chain ``plaintext`` is used. | ||
|
||
.. literalinclude:: _include/listener_tls.yaml | ||
:language: yaml | ||
:lines: 37-56 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we are going to include it would also be good to include a caption so users can get the entire file:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same below There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. I removed the line numbers, don't seem essential. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think they are a helpful guide to the user - both visually that there is a full file that the snippet is taken from and for quickly finding the snippet in the config i wont block on it tho as usage is inconsistent elsewhere |
||
:caption: :download:`listener_tls.yaml <_include/listener_tls.yaml>` | ||
|
||
Match Against the Destination IP | ||
******************************** | ||
|
||
The following example assumes :ref:`PROXY protocol <config_listener_filters_proxy_protocol>` is used for incoming | ||
traffic. If the recovered destination IP is in CIDR ``10.0.0.0/24``, then the filter chain ``vip`` is used. Otherwise, | ||
the filter chain ``default`` is used. | ||
|
||
.. literalinclude:: _include/listener_vip.yaml | ||
:language: yaml | ||
:lines: 29-48 | ||
:caption: :download:`listener_vip.yaml <_include/listener_vip.yaml>` | ||
|
||
Match Against the Destination Port and the Source IP | ||
**************************************************** | ||
|
||
The following example uses :ref:`original_dst <config_listener_filters_original_dst>` listener filter to recover the | ||
original destination port. The matcher in the listener selects one of the three filter chains ``http``, ``internal``, | ||
and ``tls`` as follows: | ||
|
||
* If the destination port is ``80``, then the filter chain ``http`` accepts the connection. | ||
* If the destination port is ``443`` and the source IP is in the range ``192.0.0.0/2`` or ``10.0.0.0/24``, then the | ||
filter chain ``internal`` accepts the connection. If the source IP is not in the ranges then the filter chain ``tls`` | ||
accepts the connection. | ||
* Otherwise, the connection is rejected, because there is no default filter chain. | ||
|
||
.. literalinclude:: _include/listener_complicated.yaml | ||
:language: yaml | ||
:lines: 58-102 | ||
:caption: :download:`listener_complicated.yaml <_include/listener_complicated.yaml>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if both are defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filter chain match is ignored when listener matcher is defined. I added a debug log to warn on listener construction.