-
Notifications
You must be signed in to change notification settings - Fork 5.3k
filters: http original src filter #6790
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 all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
c4de56e
refactor original_src_socket_option into common
klarose 03100a4
refactor creation of socket options to helper
klarose d13f905
finish up skeleton of original source filter
klarose ae0a630
add upstreamSocketOptions
klarose 78cb8e8
finish up http original src filter
klarose 3ce2987
fixup rebase previous original_src_filter
klarose 682536d
hook upstreamSocketOptions into httpConnPool
klarose 818e307
Move upstream options to ActiveStream
klarose 1be9292
document original_src http filter
klarose 9822df4
Merge branch 'master' into http_original_src_filter
klarose 918a5c6
Various fixes
klarose 04480a0
add release note
klarose b289bb6
fix compile issue not found by gcc
klarose 81a54e4
Merge branch 'master' into http_original_src_filter
klarose 0c294dd
review fixes
klarose 2df6143
fix spelling
klarose 9766731
Merge branch 'master' into http_original_src_filter
klarose b48b79a
fix failing coverage test
klarose cecf5e3
code review fixes
klarose db489b3
add snowp as the original_src sponsor.
klarose af1c9bc
Code review fixes
klarose 9f93270
Merge branch 'master' into http_original_src_filter
klarose 594edef
Merge branch 'master' into http_original_src_filter
klarose befc157
Rework UT a bit
klarose b69c87f
Merge branch 'master' into http_original_src_filter
klarose 6a7ed5e
Merge branch 'master' into http_original_src_filter
klarose 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
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,8 @@ | ||
| load("@envoy_api//bazel:api_build_system.bzl", "api_proto_library_internal") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| api_proto_library_internal( | ||
| name = "original_src", | ||
| srcs = ["original_src.proto"], | ||
| ) |
26 changes: 26 additions & 0 deletions
26
api/envoy/config/filter/http/original_src/v2alpha1/original_src.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,26 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.config.filter.http.original_src.v2alpha1; | ||
|
|
||
| option java_outer_classname = "OriginalSrcProto"; | ||
| option java_multiple_files = true; | ||
| option java_package = "io.envoyproxy.envoy.config.filter.http.original_src.v2alpha1"; | ||
|
|
||
| option go_package = "v2alpha1"; | ||
|
|
||
| import "validate/validate.proto"; | ||
|
|
||
| // [#protodoc-title: Original Src Filter] | ||
| // Use the Original source address on upstream connections. | ||
|
|
||
| // The Original Src filter binds upstream connections to the original source address determined | ||
| // for the request. This address could come from something like the Proxy Protocol filter, or it | ||
| // could come from trusted http headers. | ||
| message OriginalSrc { | ||
|
|
||
| // Sets the SO_MARK option on the upstream connection's socket to the provided value. Used to | ||
| // ensure that non-local addresses may be routed back through envoy when binding to the original | ||
| // source address. The option will not be applied if the mark is 0. | ||
| // [#proto-status: experimental] | ||
| uint32 mark = 1; | ||
| } |
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 |
|---|---|---|
|
|
@@ -7,3 +7,4 @@ HTTP filters | |
|
|
||
| */v2/* | ||
| */v2alpha/* | ||
| */v2alpha1/* | ||
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
71 changes: 71 additions & 0 deletions
71
docs/root/configuration/http_filters/original_src_filter.rst
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,71 @@ | ||
| .. _config_http_filters_original_src: | ||
|
|
||
| Original Source | ||
| =============== | ||
|
|
||
| * :ref:`HTTP filter v2 API reference <envoy_api_msg_config.filter.http.original_src.v2alpha1.OriginalSrc>` | ||
| * This filter should be configured with the name *envoy.filters.http.original_src*. | ||
|
|
||
| The original source http filter replicates the downstream remote address of the connection on | ||
| the upstream side of Envoy. For example, if a downstream connection connects to Envoy with IP | ||
| address ``10.1.2.3``, then Envoy will connect to the upstream with source IP ``10.1.2.3``. The | ||
| downstream remote address is determined based on the logic for the "trusted client address" | ||
| outlined in :ref:`XFF <config_http_conn_man_headers_x-forwarded-for>`. | ||
|
|
||
|
|
||
| Note that the filter is intended to be used in conjunction with the | ||
| :ref:`Router <config_http_filters_router>` filter. In particular, it must run prior to the router | ||
| filter so that it may add the desired source IP to the state of the filter chain. | ||
|
|
||
| IP Version Support | ||
| ------------------ | ||
| The filter supports both IPv4 and IPv6 as addresses. Note that the upstream connection must support | ||
| the version used. | ||
|
|
||
| Extra Setup | ||
| ----------- | ||
|
|
||
| The downstream remote address used will likely be globally routable. By default, packets returning | ||
| from the upstream host to that address will not route through Envoy. The network must be configured | ||
| to forcefully route any traffic whose IP was replicated by Envoy back through the Envoy host. | ||
|
|
||
| If Envoy and the upstream are on the same host -- e.g. in an sidecar deployment --, then iptables | ||
| and routing rules can be used to ensure correct behaviour. The filter has an unsigned integer | ||
| configuration, | ||
| :ref:`mark <envoy_api_field_config.filter.http.original_src.v2alpha1.OriginalSrc.mark>`. Setting | ||
| this to *X* causes Envoy to *mark* all upstream packets originating from this http with value | ||
| *X*. Note that if | ||
| :ref:`mark <envoy_api_field_config.filter.http.original_src.v2alpha1.OriginalSrc.mark>` is set | ||
| to 0, Envoy will not mark upstream packets. | ||
|
|
||
| We can use the following set of commands to ensure that all ipv4 and ipv6 traffic marked with *X* | ||
| (assumed to be 123 in the example) routes correctly. Note that this example assumes that *eth0* is | ||
| the default outbound interface. | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| iptables -t mangle -I PREROUTING -m mark --mark 123 -j CONNMARK --save-mark | ||
| iptables -t mangle -I OUTPUT -m connmark --mark 123 -j CONNMARK --restore-mark | ||
| ip6tables -t mangle -I PREROUTING -m mark --mark 123 -j CONNMARK --save-mark | ||
| ip6tables -t mangle -I OUTPUT -m connmark --mark 123 -j CONNMARK --restore-mark | ||
| ip rule add fwmark 123 lookup 100 | ||
| ip route add local 0.0.0.0/0 dev lo table 100 | ||
| ip -6 rule add fwmark 123 lookup 100 | ||
| ip -6 route add local ::/0 dev lo table 100 | ||
| echo 1 > /proc/sys/net/ipv4/conf/eth0/route_localnet | ||
|
|
||
|
|
||
| Example HTTP configuration | ||
| ------------------------------ | ||
|
|
||
| The following example configures Envoy to use the original source for all connections made on port | ||
| 8888. All upstream packets are marked with 123. | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| http_filters: | ||
| - name: envoy.filters.http.original_src | ||
| config: | ||
| mark: 123 | ||
| - name: envoy.router | ||
| config: {} | ||
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,37 @@ | ||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| # Helprs for filters for mirroring the downstream remote address on the upstream's source. | ||
|
|
||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_package", | ||
| ) | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "original_src_socket_option_lib", | ||
| srcs = ["original_src_socket_option.cc"], | ||
| hdrs = ["original_src_socket_option.h"], | ||
| deps = [ | ||
| "//include/envoy/network:listen_socket_interface", | ||
| "//source/common/common:assert_lib", | ||
| "//source/common/common:minimal_logger_lib", | ||
| "//source/common/network:address_lib", | ||
| "//source/common/network:utility_lib", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "socket_option_factory_lib", | ||
| srcs = ["socket_option_factory.cc"], | ||
| hdrs = ["socket_option_factory.h"], | ||
| deps = [ | ||
| ":original_src_socket_option_lib", | ||
| "//include/envoy/network:listen_socket_interface", | ||
| "//source/common/network:address_lib", | ||
| "//source/common/network:socket_option_factory_lib", | ||
| "//source/common/network:utility_lib", | ||
| ], | ||
| ) |
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
40 changes: 40 additions & 0 deletions
40
source/extensions/filters/common/original_src/socket_option_factory.cc
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,40 @@ | ||
| #include "extensions/filters/common/original_src/socket_option_factory.h" | ||
|
|
||
| #include "common/network/socket_option_factory.h" | ||
| #include "common/network/utility.h" | ||
|
|
||
| #include "extensions/filters/common/original_src/original_src_socket_option.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Filters { | ||
| namespace Common { | ||
| namespace OriginalSrc { | ||
|
|
||
| Network::Socket::OptionsSharedPtr | ||
| buildOriginalSrcOptions(Network::Address::InstanceConstSharedPtr source, uint32_t mark) { | ||
| const auto address_without_port = Network::Utility::getAddressWithPort(*source, 0); | ||
|
|
||
| // Note: we don't expect this to change the behaviour of the socket. We expect it to be copied | ||
| // into the upstream connection later. | ||
| auto options_to_add = std::make_shared<Network::Socket::Options>(); | ||
| options_to_add->emplace_back( | ||
| std::make_shared<Filters::Common::OriginalSrc::OriginalSrcSocketOption>( | ||
| std::move(address_without_port))); | ||
|
|
||
| if (mark != 0) { | ||
| const auto mark_options = Network::SocketOptionFactory::buildSocketMarkOptions(mark); | ||
| options_to_add->insert(options_to_add->end(), mark_options->begin(), mark_options->end()); | ||
| } | ||
|
|
||
| const auto transparent_options = Network::SocketOptionFactory::buildIpTransparentOptions(); | ||
| options_to_add->insert(options_to_add->end(), transparent_options->begin(), | ||
| transparent_options->end()); | ||
| return options_to_add; | ||
| } | ||
|
|
||
| } // namespace OriginalSrc | ||
| } // namespace Common | ||
| } // namespace Filters | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
19 changes: 19 additions & 0 deletions
19
source/extensions/filters/common/original_src/socket_option_factory.h
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,19 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/network/address.h" | ||
| #include "envoy/network/listen_socket.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Filters { | ||
| namespace Common { | ||
| namespace OriginalSrc { | ||
|
|
||
| Network::Socket::OptionsSharedPtr | ||
| buildOriginalSrcOptions(Network::Address::InstanceConstSharedPtr source, uint32_t mark); | ||
|
|
||
| } // namespace OriginalSrc | ||
| } // namespace Common | ||
| } // namespace Filters | ||
| } // namespace Extensions | ||
| } // 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,47 @@ | ||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| # A filter for mirroring the downstream remote address on the upstream's source. | ||
|
|
||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_package", | ||
| ) | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "config_lib", | ||
| srcs = ["config.cc"], | ||
| hdrs = ["config.h"], | ||
| deps = [ | ||
| "@envoy_api//envoy/config/filter/http/original_src/v2alpha1:original_src_cc", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "original_src_lib", | ||
| srcs = ["original_src.cc"], | ||
| hdrs = ["original_src.h"], | ||
| deps = [ | ||
| ":config_lib", | ||
| "//include/envoy/http:filter_interface", | ||
| "//source/common/common:assert_lib", | ||
| "//source/common/common:minimal_logger_lib", | ||
| "//source/extensions/filters/common/original_src:socket_option_factory_lib", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "config", # The extension build system requires a library named config | ||
| srcs = ["original_src_config_factory.cc"], | ||
| hdrs = ["original_src_config_factory.h"], | ||
| deps = [ | ||
| ":config_lib", | ||
| ":original_src_lib", | ||
| "//include/envoy/registry", | ||
| "//source/extensions/filters/http:well_known_names", | ||
| "//source/extensions/filters/http/common:factory_base_lib", | ||
| "@envoy_api//envoy/config/filter/http/original_src/v2alpha1:original_src_cc", | ||
| ], | ||
| ) |
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.