Skip to content
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

HCM: add support for IP detection extensions #14855

Merged
merged 175 commits into from
May 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
175 commits
Select commit Hold shift + click to select a range
2be9bdd
HCM: add support for IP detection extensions
Jan 28, 2021
e55d622
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Jan 28, 2021
eee3cd5
Rename --> original_ip_detection
Jan 29, 2021
e8d890a
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Jan 29, 2021
03819df
Update changelog
Jan 29, 2021
701e979
Some docs
Jan 29, 2021
68c9785
Add HCM config tests
Feb 1, 2021
c525fa0
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 1, 2021
b42737b
Add test for mutateRequestHeaders() using an extension
Feb 1, 2021
9a4421d
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 1, 2021
09a28e2
Use TypedExtensionConfig
Feb 2, 2021
2358acb
Extensive comments around the config message
Feb 2, 2021
445d0b2
Fix test
Feb 2, 2021
c8b4115
Fix another test
Feb 2, 2021
0868c1e
clang-tidy fixes
Feb 2, 2021
986f598
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 2, 2021
1552d08
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 2, 2021
d2b691a
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 3, 2021
def62d3
Add integration test
Feb 3, 2021
a44ce6f
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 4, 2021
c48840a
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 8, 2021
b8d50d9
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 11, 2021
8634819
Address Alyssa's review.
Feb 11, 2021
6193ad2
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 11, 2021
7d4d71b
Don't copy downstream_remote_address
Feb 11, 2021
b30ce45
Fix build
Feb 11, 2021
406d825
Drop struct
Feb 11, 2021
8832af6
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 11, 2021
7440409
Review feedback
Feb 12, 2021
8ebd8b8
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 12, 2021
3960337
Implement/Exercise allow_trusted_address_checks option
Feb 12, 2021
24a45b0
Drop struct
Feb 12, 2021
612ae54
Add XFF detection extension
Feb 12, 2021
2937e99
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 12, 2021
9db5c61
Use the XFF extension as the default fallback
Feb 12, 2021
3608dbf
Add support for rejecting requests when detection fails
Feb 13, 2021
1190035
Fixes for CI
Feb 13, 2021
970b42b
Fix docs
Feb 13, 2021
2e5e67f
Fix spelling
Feb 14, 2021
a23f44f
Code owners
Feb 14, 2021
5bd6813
Fix test
Feb 15, 2021
bd00e7f
Fix clang-tidy issue
Feb 15, 2021
178d287
Fix coverage
Feb 15, 2021
802c379
Check that a good detection doesn't set rejection options
Feb 15, 2021
151f5f8
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 16, 2021
8f5165b
Review comments
Feb 16, 2021
a246e9e
Add stat for ip detection rejections
Feb 16, 2021
d86f908
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 16, 2021
e2fc581
Remove possible exception from data path
Feb 16, 2021
7476d1a
Matt's review comments
Feb 17, 2021
370c16d
clang tidy
Feb 17, 2021
aa7306c
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 17, 2021
1e1ac79
Drop mostly duplicated extension for test
Feb 17, 2021
3eca009
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 17, 2021
e32eef6
More CI fixes
Feb 17, 2021
5871471
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 17, 2021
f0e29ae
Fix merge
Feb 17, 2021
92c0ed4
More cleanup
Feb 17, 2021
a20c9bb
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 17, 2021
ac430bb
Fix format
Feb 18, 2021
4446232
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 22, 2021
d2fec64
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 22, 2021
b60a227
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 24, 2021
822aa25
Fixes
Feb 24, 2021
b14fe36
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 24, 2021
a1edf65
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Feb 24, 2021
79a6282
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 3, 2021
8ad18c6
Rename config param to allow_extension_to_set_address_as_trusted
Mar 3, 2021
9a0d41b
Update header to reflect we now support a list of extensions
Mar 3, 2021
4043a4a
Alyssa's feedback
Mar 3, 2021
0bd4551
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 3, 2021
f873002
Fix deprecation error in test
Mar 3, 2021
b9d2949
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 4, 2021
cc2dc36
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 4, 2021
ca7bd7e
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 4, 2021
98bb064
Force registration of the XFF extension
Mar 4, 2021
a523594
Visibility public for XFF config
Mar 4, 2021
9861c9d
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 5, 2021
820f866
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 5, 2021
63b8f2c
Fix merge
Mar 5, 2021
4fa79d7
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 5, 2021
056db7c
Fix merge leftover
Mar 5, 2021
3885ec4
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 8, 2021
d33994c
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 9, 2021
af498c8
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 11, 2021
309b1b4
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 11, 2021
977f42b
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 12, 2021
24b9de8
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 14, 2021
d0a99c1
Fix merge
Mar 14, 2021
6a85d81
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 15, 2021
c4188ce
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 15, 2021
ab19e4d
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 16, 2021
02d9c88
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 17, 2021
684c8af
Fix merge
Mar 17, 2021
a226897
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 22, 2021
728fa54
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 24, 2021
bb2ec49
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Mar 30, 2021
8a692d6
Fix merge snafu
Mar 30, 2021
222eeae
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 2, 2021
4adad84
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 5, 2021
8568494
Add code block example for replacing xff_num_trusted_hops
Apr 5, 2021
cd9b360
Alyssa's feedback (partial)
Apr 5, 2021
0647ad9
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 6, 2021
57443bd
Fix build
Apr 6, 2021
d6bbeaa
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 6, 2021
99bd132
Fix
Apr 6, 2021
ea48936
Fix test
Apr 6, 2021
63ccd3f
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 6, 2021
7c78b24
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 6, 2021
a823d94
Address latest batch of comments
Apr 7, 2021
e4b99bc
Test for createExtension() returning nullptr
Apr 7, 2021
19180ff
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 7, 2021
f8df690
Add extension name to the exception message
Apr 7, 2021
7ce524e
Test case for v6
Apr 7, 2021
bd05e1a
clang-tidy
Apr 7, 2021
95779af
custom header: improve coverage
Apr 7, 2021
18f02c3
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 7, 2021
516de72
Set the custom header extension to out by default
Apr 7, 2021
63a3987
Update headers.rst to reflect the use of IP detection extensions
Apr 8, 2021
d0f50da
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 8, 2021
305f2ed
extensions/ -> extensions/http/
Apr 8, 2021
7fe2d81
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 8, 2021
29af4d3
Reduce (or hide) the dynamic_cast calls
Apr 8, 2021
336261c
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 8, 2021
720d541
Fix visibility comments
Apr 8, 2021
de30bd9
More comment fixes
Apr 8, 2021
ab852ff
Validate header name
Apr 8, 2021
4582469
More fixes
Apr 8, 2021
8ec2a83
More namespaces fixes
Apr 9, 2021
129b0bf
Expand integration test
Apr 9, 2021
6ac62e6
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 9, 2021
c338b65
Validate header name
Apr 9, 2021
c2717ba
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 12, 2021
800b843
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 15, 2021
5070b90
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 15, 2021
91806ca
Matt's feedback
Apr 15, 2021
5f15518
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 15, 2021
014d6d4
Update changelog
Apr 15, 2021
15dc56a
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 15, 2021
eaca63d
Fix changelog
Apr 15, 2021
9b0f98b
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 16, 2021
a241827
Fix current changelog
Apr 16, 2021
bffe4d1
Bring back the custom header extension
Apr 16, 2021
991996b
Fix format
Apr 16, 2021
73aad95
Avoid namespace pollution issues
Apr 16, 2021
6cd3d43
Another test fix
Apr 16, 2021
42776e9
Another test fix
Apr 16, 2021
7e6da84
Fix
Apr 16, 2021
ef56193
Format
Apr 16, 2021
04b19b9
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 16, 2021
66f2296
Fix integration tests
Apr 16, 2021
b78ba36
extensions/common/aws needs xff to run
Apr 16, 2021
16a736e
xff:config should have been a dep of hcm:config in the prev commit
Apr 16, 2021
fcf7945
HCM's test needs the custom header extension
Apr 18, 2021
098ecd5
clang-tidy
Apr 18, 2021
081e731
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 20, 2021
c025400
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 20, 2021
ff6b944
Undo jwt proto formatting
Apr 20, 2021
09c84e4
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 23, 2021
cef2d20
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 26, 2021
e1f0ac5
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 27, 2021
145809a
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 27, 2021
a62ede7
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
Apr 28, 2021
0eac980
Fallback -> fall back
Apr 28, 2021
c751398
Comment on allow trusted check
Apr 28, 2021
bafa351
Status code comment
Apr 28, 2021
f9a372c
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
May 13, 2021
892a4a8
Fix merge
May 13, 2021
fd10840
Trim down comment for original_ip_detection_extensions
May 13, 2021
3ef96b1
More fixes
May 13, 2021
f841b5f
Field name update
May 13, 2021
c4a21e7
Fix
May 14, 2021
166eddb
htuch's review
May 14, 2021
43ff219
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
May 14, 2021
d53e920
Merge remote-tracking branch 'upstream/main' into add-ip-detection-ex…
May 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE;
// HTTP connection manager :ref:`configuration overview <config_http_conn_man>`.
// [#extension: envoy.filters.network.http_connection_manager]

// [#next-free-field: 43]
// [#next-free-field: 44]
message HttpConnectionManager {
option (udpa.annotations.versioning).previous_message_type =
"envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager";
Expand Down Expand Up @@ -583,6 +583,11 @@ message HttpConnectionManager {
// *not* the deprecated but similarly named :ref:`stream_error_on_invalid_http_messaging
// <envoy_v3_api_field_config.core.v3.Http2ProtocolOptions.stream_error_on_invalid_http_messaging>`
google.protobuf.BoolValue stream_error_on_invalid_http_message = 40;

// The configuration of the IP detection extension.
rgs1 marked this conversation as resolved.
Show resolved Hide resolved
//
// If not set, Envoy uses the default remote IP detection.
IPDetectionExtension ip_detection_extension = 43;
rgs1 marked this conversation as resolved.
Show resolved Hide resolved
}

// The configuration to customize local reply returned by Envoy.
Expand Down Expand Up @@ -851,3 +856,8 @@ message RequestIDExtension {
// Request ID extension specific configuration.
google.protobuf.Any typed_config = 1;
}

message IPDetectionExtension {
// IP detection extension specific configuration.
google.protobuf.Any typed_config = 1;
rgs1 marked this conversation as resolved.
Show resolved Hide resolved
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/root/version_history/current.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ New Features
* access log: added the :ref:`formatters <envoy_v3_api_field_config.core.v3.SubstitutionFormatString.formatters>` extension point for custom formatters (command operators).
* access log: support command operator: %REQUEST_HEADERS_BYTES%, %RESPONSE_HEADERS_BYTES% and %RESPONSE_TRAILERS_BYTES%.
* dispatcher: supports a stack of `Envoy::ScopeTrackedObject` instead of a single tracked object. This will allow Envoy to dump more debug information on crash.
* http: added support for IP detection extensions.
* http: added support for :ref:`:ref:`preconnecting <envoy_v3_api_msg_config.cluster.v3.Cluster.PreconnectPolicy>`. Preconnecting is off by default, but recommended for clusters serving latency-sensitive traffic, especially if using HTTP/1.1.
* http: change frame flood and abuse checks to the upstream HTTP/2 codec to ON by default. It can be disabled by setting the `envoy.reloadable_features.upstream_http2_flood_checks` runtime key to false.
* overload: add support for scaling :ref:`transport connection timeouts<envoy_v3_api_enum_value_config.overload.v3.ScaleTimersOverloadActionConfig.TimerType.TRANSPORT_SOCKET_CONNECT>`. This can be used to reduce the TLS handshake timeout in response to overload.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions include/envoy/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,12 @@ envoy_cc_library(
":header_map_interface",
],
)

envoy_cc_library(
name = "ip_detection_extension_interface",
hdrs = ["ip_detection_extension.h"],
deps = [
":header_map_interface",
"//include/envoy/config:typed_config_interface",
],
)
49 changes: 49 additions & 0 deletions include/envoy/http/ip_detection_extension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

#include <memory>
#include <string>

#include "envoy/common/pure.h"
#include "envoy/http/header_map.h"

namespace Envoy {
namespace Http {

/**
* Interface class for IP detection extensions.
*/
class IPDetectionExtension {
public:
virtual ~IPDetectionExtension() = default;

/**
* Detect the final remote address if any.
*
* @param request_headers supplies the incoming request headers.
*/
virtual Network::Address::InstanceConstSharedPtr
detect(Http::RequestHeaderMap& request_headers) PURE;
rgs1 marked this conversation as resolved.
Show resolved Hide resolved
};

using IPDetectionExtensionSharedPtr = std::shared_ptr<IPDetectionExtension>;

/*
* A factory for creating IP detection extensions.
*/
class IPDetectionExtensionFactory : public Envoy::Config::TypedFactory {
public:
~IPDetectionExtensionFactory() override = default;

/**
* Creates a particular Extension implementation.
*
* @param config supplies the configuration for the IP detection extension.
* @return IPDetectionExtensionSharedPtr the extension instance.
*/
virtual IPDetectionExtensionSharedPtr createExtension(const Protobuf::Message& config) const PURE;
};

using IPDetectionExtensionFactoryPtr = std::unique_ptr<IPDetectionExtensionFactory>;

} // namespace Http
} // namespace Envoy
1 change: 1 addition & 0 deletions source/common/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ envoy_cc_library(
":date_provider_lib",
"//include/envoy/config:config_provider_interface",
"//include/envoy/http:filter_interface",
"//include/envoy/http:ip_detection_extension_interface",
"//include/envoy/http:request_id_extension_interface",
"//include/envoy/router:rds_interface",
"//source/common/local_reply:local_reply_lib",
Expand Down
6 changes: 6 additions & 0 deletions source/common/http/conn_manager_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "envoy/config/config_provider.h"
#include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.pb.h"
#include "envoy/http/filter.h"
#include "envoy/http/ip_detection_extension.h"
#include "envoy/http/request_id_extension.h"
#include "envoy/router/rds.h"
#include "envoy/stats/scope.h"
Expand Down Expand Up @@ -466,6 +467,11 @@ class ConnectionManagerConfig {
* @return LocalReply configuration which supplies mapping for local reply generated by Envoy.
*/
virtual const LocalReply::LocalReply& localReply() const PURE;

/**
* @return IPDetectionExtensionSharedPtr The IP detection extension if available.
*/
virtual IPDetectionExtensionSharedPtr ipDetectionExtension() PURE;
};
} // namespace Http
} // namespace Envoy
75 changes: 46 additions & 29 deletions source/common/http/conn_manager_utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Network::Address::InstanceConstSharedPtr ConnectionManagerUtility::mutateRequest
// peer. Cases where we don't "use remote address" include trusted double proxy where we expect
// our peer to have already properly set XFF, etc.
Network::Address::InstanceConstSharedPtr final_remote_address;
bool single_xff_address;
bool single_xff_address = false;
rgs1 marked this conversation as resolved.
Show resolved Hide resolved
const uint32_t xff_num_trusted_hops = config.xffNumTrustedHops();

if (config.useRemoteAddress()) {
Expand Down Expand Up @@ -127,12 +127,23 @@ Network::Address::InstanceConstSharedPtr ConnectionManagerUtility::mutateRequest
connection.ssl() ? Headers::get().SchemeValues.Https : Headers::get().SchemeValues.Http);
}
} else {
// If we are not using remote address, attempt to pull a valid IPv4 or IPv6 address out of XFF.
// If we are not using remote address, attempt to pull a valid IPv4 or IPv6 address out of XFF
// or through an extension. An extension might be needed when XFF doesn't work (e.g. an
// irregular network).
//
// If we find one, it will be used as the downstream address for logging. It may or may not be
// used for determining internal/external status (see below).
auto ret = Utility::getLastAddressFromXFF(request_headers, xff_num_trusted_hops);
final_remote_address = ret.address_;
single_xff_address = ret.single_address_;
auto ip_detection_extension = config.ipDetectionExtension();
if (ip_detection_extension) {
final_remote_address = ip_detection_extension->detect(request_headers);
}

// If there's no extension or it failed to detect, give XFF a try.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should definitely comment this up in the include docs, and make it clear that the extension is called ahead of XFF checks, but fails over to standard mechanisms.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some to docs/root/intro/arch_overview/other_features/ip_transparency.rst, the header file and the proto files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, should we consider moving XFF handling to an extension that implements the API that is added in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to suggest the same thing that @antoniovicente did. If we're adding an extension point here, let's take the opportunity to move the existing functionality into an extension, and just make that the default extension.

if (!final_remote_address) {
auto ret = Utility::getLastAddressFromXFF(request_headers, xff_num_trusted_hops);
final_remote_address = ret.address_;
single_xff_address = ret.single_address_;
}
}

// If the x-forwarded-proto header is not set, set it here, since Envoy uses it for determining
Expand Down Expand Up @@ -170,30 +181,7 @@ Network::Address::InstanceConstSharedPtr ConnectionManagerUtility::mutateRequest
request_headers.setReferenceEnvoyInternalRequest(
Headers::get().EnvoyInternalRequestValues.True);
} else {
if (edge_request) {
request_headers.removeEnvoyDecoratorOperation();
request_headers.removeEnvoyDownstreamServiceCluster();
request_headers.removeEnvoyDownstreamServiceNode();
}

request_headers.removeEnvoyRetriableStatusCodes();
request_headers.removeEnvoyRetriableHeaderNames();
request_headers.removeEnvoyRetryOn();
request_headers.removeEnvoyRetryGrpcOn();
request_headers.removeEnvoyMaxRetries();
request_headers.removeEnvoyUpstreamAltStatName();
request_headers.removeEnvoyUpstreamRequestTimeoutMs();
request_headers.removeEnvoyUpstreamRequestPerTryTimeoutMs();
request_headers.removeEnvoyUpstreamRequestTimeoutAltResponse();
request_headers.removeEnvoyExpectedRequestTimeoutMs();
request_headers.removeEnvoyForceTrace();
request_headers.removeEnvoyIpTags();
request_headers.removeEnvoyOriginalUrl();
request_headers.removeEnvoyHedgeOnPerTryTimeout();

for (const LowerCaseString& header : route_config.internalOnlyHeaders()) {
request_headers.remove(header);
}
cleanInternalHeaders(request_headers, edge_request, route_config.internalOnlyHeaders());
}

if (config.userAgent()) {
Expand Down Expand Up @@ -236,6 +224,35 @@ Network::Address::InstanceConstSharedPtr ConnectionManagerUtility::mutateRequest
return final_remote_address;
}

void ConnectionManagerUtility::cleanInternalHeaders(
RequestHeaderMap& request_headers, bool edge_request,
const std::list<Http::LowerCaseString>& internal_only_headers) {
if (edge_request) {
request_headers.removeEnvoyDecoratorOperation();
request_headers.removeEnvoyDownstreamServiceCluster();
request_headers.removeEnvoyDownstreamServiceNode();
}

request_headers.removeEnvoyRetriableStatusCodes();
request_headers.removeEnvoyRetriableHeaderNames();
request_headers.removeEnvoyRetryOn();
request_headers.removeEnvoyRetryGrpcOn();
request_headers.removeEnvoyMaxRetries();
request_headers.removeEnvoyUpstreamAltStatName();
request_headers.removeEnvoyUpstreamRequestTimeoutMs();
request_headers.removeEnvoyUpstreamRequestPerTryTimeoutMs();
request_headers.removeEnvoyUpstreamRequestTimeoutAltResponse();
request_headers.removeEnvoyExpectedRequestTimeoutMs();
request_headers.removeEnvoyForceTrace();
request_headers.removeEnvoyIpTags();
request_headers.removeEnvoyOriginalUrl();
request_headers.removeEnvoyHedgeOnPerTryTimeout();

for (const LowerCaseString& header : internal_only_headers) {
request_headers.remove(header);
}
}

void ConnectionManagerUtility::mutateTracingRequestHeader(RequestHeaderMap& request_headers,
Runtime::Loader& runtime,
ConnectionManagerConfig& config,
Expand Down
2 changes: 2 additions & 0 deletions source/common/http/conn_manager_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class ConnectionManagerUtility {
static void mutateXfccRequestHeader(RequestHeaderMap& request_headers,
Network::Connection& connection,
ConnectionManagerConfig& config);
static void cleanInternalHeaders(RequestHeaderMap& request_headers, bool edge_request,
const std::list<Http::LowerCaseString>& internal_only_headers);
};

} // namespace Http
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ envoy_cc_extension(
"//include/envoy/filesystem:filesystem_interface",
"//include/envoy/http:codec_interface",
"//include/envoy/http:filter_interface",
"//include/envoy/http:ip_detection_extension_interface",
"//include/envoy/http:request_id_extension_interface",
"//include/envoy/registry",
"//include/envoy/router:route_config_provider_manager_interface",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,18 @@ HttpConnectionManagerConfig::HttpConnectionManagerConfig(
Http::RequestIDExtensionFactory::defaultInstance(context_.api().randomGenerator());
}

// Check if we are provided with an IP detection extension.
if (config.ip_detection_extension().has_typed_config()) {
auto& typed_config = config.ip_detection_extension().typed_config();
const std::string type{TypeUtil::typeUrlToDescriptorFullName(typed_config.type_url())};
auto* ip_detection_extension_factory =
Registry::FactoryRegistry<Http::IPDetectionExtensionFactory>::getFactoryByType(type);
if (!ip_detection_extension_factory) {
throw EnvoyException("IP detection extension not found");
}
ip_detection_extension_ = ip_detection_extension_factory->createExtension(typed_config);
}

// If scoped RDS is enabled, avoid creating a route config provider. Route config providers will
// be managed by the scoped routing logic instead.
switch (config.route_specifier_case()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.pb.validate.h"
#include "envoy/filter/http/filter_config_provider.h"
#include "envoy/http/filter.h"
#include "envoy/http/ip_detection_extension.h"
#include "envoy/http/request_id_extension.h"
#include "envoy/router/route_config_provider_manager.h"
#include "envoy/tracing/http_tracer_manager.h"
Expand Down Expand Up @@ -177,6 +178,9 @@ class HttpConnectionManagerConfig : Logger::Loggable<Logger::Id::config>,
}
std::chrono::milliseconds delayedCloseTimeout() const override { return delayed_close_timeout_; }
const LocalReply::LocalReply& localReply() const override { return *local_reply_; }
Http::IPDetectionExtensionSharedPtr ipDetectionExtension() override {
return ip_detection_extension_;
}

private:
enum class CodecType { HTTP1, HTTP2, HTTP3, AUTO };
Expand Down Expand Up @@ -255,6 +259,7 @@ class HttpConnectionManagerConfig : Logger::Loggable<Logger::Id::config>,
const envoy::config::core::v3::HttpProtocolOptions::HeadersWithUnderscoresAction
headers_with_underscores_action_;
const LocalReply::LocalReplyPtr local_reply_;
Http::IPDetectionExtensionSharedPtr ip_detection_extension_{nullptr};

// Default idle timeout is 5 minutes if nothing is specified in the HCM config.
static const uint64_t StreamIdleTimeoutMs = 5 * 60 * 1000;
Expand Down
1 change: 1 addition & 0 deletions source/server/admin/admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class AdminImpl : public Admin,
return envoy::config::core::v3::HttpProtocolOptions::ALLOW;
}
const LocalReply::LocalReply& localReply() const override { return *local_reply_; }
Http::IPDetectionExtensionSharedPtr ipDetectionExtension() override { return nullptr; };
Http::Code request(absl::string_view path_and_query, absl::string_view method,
Http::ResponseHeaderMap& response_headers, std::string& body) override;
void closeSocket();
Expand Down