-
Notifications
You must be signed in to change notification settings - Fork 5.6k
transport_socket(http_11_proxy): add Proxy-Authorization header support #46675
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
Open
glennc24
wants to merge
4
commits into
envoyproxy:main
Choose a base branch
from
glennc24:proxy-authorization-header
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ | |
| #include "source/common/config/well_known_names.h" | ||
| #include "source/common/http/header_utility.h" | ||
| #include "source/common/network/address_impl.h" | ||
| #include "source/common/protobuf/protobuf.h" | ||
| #include "source/common/protobuf/utility.h" | ||
| #include "source/common/runtime/runtime_features.h" | ||
|
|
||
| namespace Envoy { | ||
|
|
@@ -69,8 +71,15 @@ UpstreamHttp11ConnectSocket::UpstreamHttp11ConnectSocket( | |
| } | ||
|
|
||
| // Helper method to create a properly formatted CONNECT request with Host header. | ||
| std::string UpstreamHttp11ConnectSocket::formatConnectRequest(absl::string_view target) { | ||
| return absl::StrCat("CONNECT ", target, " HTTP/1.1\r\n", "Host: ", target, "\r\n\r\n"); | ||
| std::string UpstreamHttp11ConnectSocket::formatConnectRequest(absl::string_view target, | ||
| bool include_host_header, | ||
| absl::string_view authorization) { | ||
| std::string connect_header = absl::StrCat("CONNECT ", target, " HTTP/1.1\r\n"); | ||
| std::string host_header = include_host_header ? absl::StrCat("Host: ", target, "\r\n") : ""; | ||
| std::string proxy_authorization_header = | ||
| !authorization.empty() ? absl::StrCat("Proxy-Authorization: ", authorization, "\r\n") : ""; | ||
|
|
||
| return absl::StrCat(connect_header, host_header, proxy_authorization_header, "\r\n"); | ||
| } | ||
|
|
||
| inline void UpstreamHttp11ConnectSocket::handleProxyInfoConnect( | ||
|
|
@@ -82,17 +91,35 @@ inline void UpstreamHttp11ConnectSocket::handleProxyInfoConnect( | |
| if (!Runtime::runtimeFeatureEnabled( | ||
| "envoy.reloadable_features.http_11_proxy_connect_legacy_format")) { | ||
| // RFC 9110 compliant CONNECT format that includes Host header. | ||
| header_buffer_.add(formatConnectRequest(target)); | ||
| header_buffer_.add(formatConnectRequest(target, true /* include_host_header */)); | ||
| } else { | ||
| // Legacy behavior: no Host header for backward compatibility. | ||
| header_buffer_.add(absl::StrCat("CONNECT ", target, " HTTP/1.1\r\n\r\n")); | ||
| header_buffer_.add(formatConnectRequest(target, false /* include_host_header */)); | ||
| } | ||
| need_to_strip_connect_response_ = true; | ||
| } | ||
| } | ||
|
|
||
| inline void UpstreamHttp11ConnectSocket::handleHostMetadataConnect( | ||
| std::shared_ptr<const Upstream::HostDescription> host) { | ||
| // Look up the optional Proxy-Authorization value from the endpoint's typed metadata. | ||
| std::string authorization; | ||
| if (host->metadata() != nullptr) { | ||
| auto auth_it = host->metadata()->typed_filter_metadata().find( | ||
| Config::MetadataFilters::get().ENVOY_HTTP11_PROXY_TRANSPORT_SOCKET_AUTH); | ||
| if (auth_it != host->metadata()->typed_filter_metadata().end()) { | ||
| Protobuf::StringValue auth_value; | ||
| if (MessageUtil::unpackTo(auth_it->second, auth_value).ok()) { | ||
|
Member
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 this fails, we should emit some kind of trace log.
Contributor
Author
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 |
||
| authorization = auth_value.value(); | ||
| } else { | ||
| ENVOY_CONN_LOG(trace, | ||
| "Failed to unpack Proxy-Authorization string from host metadata, " | ||
| "proceeding with empty authorization", | ||
| callbacks_->connection()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!Runtime::runtimeFeatureEnabled( | ||
| "envoy.reloadable_features.http_11_proxy_connect_legacy_format")) { | ||
| // Prefer <host-name>:<port> for RFC 9110 compliance, unless URI is <host-ip>:<port>. | ||
|
|
@@ -103,11 +130,11 @@ inline void UpstreamHttp11ConnectSocket::handleHostMetadataConnect( | |
| } else { | ||
| target = host->address()->asStringView(); | ||
| } | ||
| header_buffer_.add(formatConnectRequest(target)); | ||
| header_buffer_.add(formatConnectRequest(target, true /* include_host_header */, authorization)); | ||
| } else { | ||
| // Legacy behavior: <host-ip>:<port> format, no Host header for backward compatibility. | ||
| header_buffer_.add( | ||
| absl::StrCat("CONNECT ", host->address()->asStringView(), " HTTP/1.1\r\n\r\n")); | ||
| header_buffer_.add(formatConnectRequest(host->address()->asStringView(), | ||
| false /* include_host_header */, authorization)); | ||
| } | ||
| need_to_strip_connect_response_ = true; | ||
| } | ||
|
|
||
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
Oops, something went wrong.
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.
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.
Can you please update the documentation with this.
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.
Added a comment in upstream_http11_connect.proto describing the proxy_authorization key. Please let me know if you had another location in mind.