Repository navigation
hcm: adding a knob for setting scheme - #17070
Conversation
Signed-off-by: Alyssa Wilk <[email protected]>
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
Signed-off-by: Alyssa Wilk <[email protected]>
snowp
left a comment
There was a problem hiding this comment.
Thanks, just a few comments
| // Overwrite any Scheme header with the contents of scheme | ||
| OVERWRITE_SCHEME = 0; | ||
|
|
||
| // If no Scheme header is present, append Scheme scheme |
There was a problem hiding this comment.
Since we'd always be appending to an empty string should this be called ADD_SCHEME_IF_ABSENT instead?
| OVERWRITE_SCHEME = 0; | ||
|
|
||
| // If no Scheme header is present, append Scheme scheme | ||
| // If a Scheme header is present, pass it through. |
There was a problem hiding this comment.
For my understanding: when would the scheme not be present?
| [(validate.rules).enum = {defined_only: true}]; | ||
|
|
||
| // Defines the action to be applied to the Scheme header on the request path | ||
| // if scheme is set in the config. Defaults to OVERWRITE_SCHEME. |
There was a problem hiding this comment.
should this reference the scheme parameter with :ref:?
| [(validate.rules).enum = {defined_only: true}]; | ||
|
|
||
| // An optional override. If set, the connection manager will set the request | ||
| // scheme to this value based on scheme_header_transformation. Valid values are 'http' and |
There was a problem hiding this comment.
Same here, :ref: even if they are next to each other :)
| config.schemeHeaderTransformation()); | ||
| } | ||
|
|
||
| TEST_F(HttpConnectionManagerConfigTest, SchemeINvalid) { |
There was a problem hiding this comment.
SchemeINvalid -> SchemeInvalid
Signed-off-by: Alyssa Wilk <[email protected]>
Signed-off-by: Alyssa Wilk <[email protected]>
|
|
||
| enum SchemeHeaderTransformation { | ||
| // Overwrite any Scheme header with the contents of scheme | ||
| OVERWRITE_SCHEME = 0; |
There was a problem hiding this comment.
The config is still confusing to me. Can we define it as "oneof"
oneof {
// the scheme to override
string override_scheme = 11;
// preserve downstream one, if absent set it with upstream security level
protobuf.Empty preserve_downstream = 12;
// always set it as upstream security level
protobuf.Empty by_upstream_security_level = 13
}
There was a problem hiding this comment.
I think this is consistent with other header overrides - will let API shephards make that call through :-)
|
@phlax added the new config here and confirmed it no longer redirects |
|
@alyssawilk i picked the changes in this pr, built envoy with it and tested with the default config not sure if this pr is still wip, but using the built envoy i got three different results
i have log traces from each of the outcomes if its helpful worth mentioning is that whichever of the outcomes occurred the server continued with that until being restarted - ie if it worked once it continued working perfectly. It never gets the redirects problem. This is unlike envoy main in which you start the server and sometimes it works and sometimes it redirects - restarting has no effect fwiw i tested out updating the default config to point to google and that also got spun out on redirects, so its not just the envoyproxy site i think im wondering more generally - if this used to work without having to set anything extra - and that was the "default" demo config - can we make it work that way again - at least initially ? |
|
so the default demo config had a listener which was listening in the clear, and then forwarding that content over TLS. Envoy proxy expects TLS traffic and now can detect (via x-forwarded-proto) that the request was sent in cleartext and is so not actually secure. The new default behavior is closing a fairly serious security loophole. We could address by either having Envoy proxy allow http traffic, or making sure our example uses TLS rather than sending https urls in the clear :-) |
Signed-off-by: Alyssa Wilk <[email protected]>
Signed-off-by: Alyssa Wilk <[email protected]>
mattklein123
left a comment
There was a problem hiding this comment.
Thanks for helping to sort this out. Starting out with some API comments.
/wait
Signed-off-by: Alyssa Wilk <[email protected]>
Signed-off-by: Alyssa Wilk <[email protected]>
Signed-off-by: Alyssa Wilk <[email protected]>
mattklein123
left a comment
There was a problem hiding this comment.
Thanks for fixing this. Looks great. Some small comments.
/wait
| For HTTP/2, and HTTP/3, incoming :scheme headers are trusted and propogated through upstream. | ||
| For HTTP/1, the :scheme header will be set | ||
| 1) From the absolute URL if present and valid. An invalid (not "http" or "https") scheme, or an https scheme over an unencrypted connection will result in Envoy rejecting the request. | ||
| 2) From the value of the :ref:`config_http_conn_man_headers_x-forwarded-proto` header after sanitization. |
There was a problem hiding this comment.
Option 3 is to set from whether the connection is TLS or not? Clarify?
There was a problem hiding this comment.
XFP is set (if absent) first, scheme copies XFP.
https://github.com/envoyproxy/envoy/blob/main/source/common/http/conn_manager_utility.cc#L173
There was a problem hiding this comment.
Here I propose to have another scheme header setting policy: always set it according to the upstream security level.
There was a problem hiding this comment.
I'm pretty sure that'll break mesh networks pretty fast, if some hops are secure and some are insecure.
Generally if scheme is set it should be preserved. If it's not set, it is set according to upstream security level as you suggest.
There was a problem hiding this comment.
I proposed to add an option in scheme_header_transformation to allow setting ":scheme" according to the upstream security level. I totally agreed with you that scheme should be preserved by the proxy if all proxy in the path works the same way. But reality is: some are not. In GCP, there are GFE, Cloud-run app-server, one of them may set scheme wrong. If we add this option, envoy will have a way to set it correctly. This is just an option which will not be enabled by default.
There was a problem hiding this comment.
We can add that if necessary but I'd prefer not to unless we actually need to, because that's not what :scheme is for. As commented, it's a part of the URI and I'm not yet clear on why we'd want to change the URI to one thing for one cluster and another for another. If you have a use case where a global override doesn't work and we need a per cluster override I can of course look into that.
There was a problem hiding this comment.
I do also have concerns about consistency if we go the cluster route. Previously, scheme was only set for outbound traffic so filters didn't see the value. If we add a "set based on cluster" knob we can best effort set on ingress based on expected cluster, but the expected cluster can change over the course of the filter chain so IMO is much less stable and adds complexity to an already complex process.
That said there was previously support for that, so if we need to again we'll just have to discuss how to make it as clear and consistent as possible.
| If *xff_num_trusted_hops* is zero, downstream *x-forwarded-proto* headers will be set to http | ||
| or https based on if the downstream connection is TLS or not. |
There was a problem hiding this comment.
Per above, for H1 scheme will also be set in this case, right?
There was a problem hiding this comment.
yes, though I was trying to talk to scheme updates in the scheme section and XFP in the XFP section. Given the complexity do you think redundancy is a better plan?
There was a problem hiding this comment.
Yeah I would be pretty redundant here and over share, given how important this is to understand.
| request_headers.setScheme(config.schemeToSet().value()); | ||
| request_headers.setForwardedProto(config.schemeToSet().value()); |
There was a problem hiding this comment.
Technically if we control the values here (enum, etc.) I think we could use reference variants here.
There was a problem hiding this comment.
Shouldn't x-forwarded-proto be the old one, not the new one?
There was a problem hiding this comment.
I think in the case we force-overwrite we should force-overwrite both, which is what we have in the API and docs.
There was a problem hiding this comment.
Hmm, I am not sure. I thought XFP should be the one from original client, force-overwrite should not overwrite it.
There was a problem hiding this comment.
Scheme should also be from the original client. :-)
If we're using this knob it's cause we want to set a scheme which doesn't match underlying encryption.
I'm going for the principle of least surprise here. Because XFP is the way to communicate http/https for HTTP/1.1, if we have several Envoy hops of mixed HTTP/1 and HTTP/2 we want to force something to look like it's https scheme, you must overwrite both scheme and XFP to have it consistently look like it's https scheme through both sets of hops. If folks want scheme and XFP to not match they can always change XFP back in request_headers_to_add, but I assume they're usually going to want to have them match.
There was a problem hiding this comment.
My understanding is: scheme should always matches underlying connection security level. I could be wrong then. In that case, I am fine overwriting both scheme and XFP
There was a problem hiding this comment.
ah, :scheme actually indicates a fundamental part of the URI
https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2.3
It's a fundamental part of the resource being requested and is not supposed to change from hop to hop based on connection security level.
Signed-off-by: Alyssa Wilk <[email protected]>
alyssawilk
left a comment
There was a problem hiding this comment.
Thanks for the thoughtful review!
| For HTTP/2, and HTTP/3, incoming :scheme headers are trusted and propogated through upstream. | ||
| For HTTP/1, the :scheme header will be set | ||
| 1) From the absolute URL if present and valid. An invalid (not "http" or "https") scheme, or an https scheme over an unencrypted connection will result in Envoy rejecting the request. | ||
| 2) From the value of the :ref:`config_http_conn_man_headers_x-forwarded-proto` header after sanitization. |
There was a problem hiding this comment.
XFP is set (if absent) first, scheme copies XFP.
https://github.com/envoyproxy/envoy/blob/main/source/common/http/conn_manager_utility.cc#L173
| If *xff_num_trusted_hops* is zero, downstream *x-forwarded-proto* headers will be set to http | ||
| or https based on if the downstream connection is TLS or not. |
There was a problem hiding this comment.
yes, though I was trying to talk to scheme updates in the scheme section and XFP in the XFP section. Given the complexity do you think redundancy is a better plan?
| request_headers.setScheme(config.schemeToSet().value()); | ||
| request_headers.setForwardedProto(config.schemeToSet().value()); |
There was a problem hiding this comment.
I think in the case we force-overwrite we should force-overwrite both, which is what we have in the API and docs.
Signed-off-by: Alyssa Wilk <[email protected]>
mattklein123
left a comment
There was a problem hiding this comment.
Thanks LGTM with a few small comments.
/wait
| HttpConnectionManagerProto::ServerHeaderTransformation server_transformation_{ | ||
| HttpConnectionManagerProto::OVERWRITE}; | ||
| std::string server_name_; | ||
| absl::optional<std::string> scheme_; |
There was a problem hiding this comment.
nit
| absl::optional<std::string> scheme_; | |
| absl::optional<std::string> scheme_to_set_; |
(Or scheme_to_overwrite_ which might be more clear, up to you)
| HttpConnectionManagerConfig config(parseHttpConnectionManagerFromYaml(yaml_string), context_, | ||
| date_provider_, route_config_provider_manager_, | ||
| scoped_routes_config_provider_manager_, http_tracer_manager_, | ||
| filter_config_provider_manager_); |
There was a problem hiding this comment.
This doesn't really test anything. Can you query the value from the config at least?
There was a problem hiding this comment.
whoops - lost the actual test on merge :-P
Signed-off-by: Alyssa Wilk <[email protected]>
mattklein123
left a comment
There was a problem hiding this comment.
LGTM modulo any remaining @qiwzhang comments. Thank you!
|
ill test this with #17200 now... |
|
worked perfectly every time! great, thanks |
phlax
left a comment
There was a problem hiding this comment.
@alyssawilk please could you fix the inline literals in the docs
| For HTTP/2, and HTTP/3, incoming *:scheme* headers are trusted and propogated through upstream. | ||
| For HTTP/1, the *:scheme* header will be set | ||
| 1) From the absolute URL if present and valid. An invalid (not "http" or "https") scheme, or an https scheme over an unencrypted connection will result in Envoy rejecting the request. This is the only scheme validation Envoy performs as it avoids a HTTP/1.1-specific privledge escalation attack for edge Envoys [1]_ which doesn't have a comparable vector for HTTP/2 and above [2]_. | ||
| 2) From the value of the :ref:`config_http_conn_man_headers_x-forwarded-proto` header after sanitization (to valid *x-forwarded-proto* from trusted downstreams, otherwise based on downstream encryption level). |
There was a problem hiding this comment.
please use double-backtick literal for ``x-forward-proto``
There was a problem hiding this comment.
I think I'd prefer a follow-up sweep to tthe file at large. I think all other headers in this file are *d rather than ``d and I'd prefer consistency
x-b3-traceid x-b3-spanid x-b3-parentspanid x-b3-sampled x-datadog-trace-id x-envoy-external-address etc
| of the connection terminated by front/edge Envoy. *x-forwarded-proto* contains this information. It | ||
| will be set to either *http* or *https*. | ||
|
|
||
| Downstream *x-forwarded-proto* headers will only be trusted if *xff_num_trusted_hops* is non-zero. |
| @@ -341,6 +360,14 @@ It is a common case where a service wants to know what the originating protocol | |||
| of the connection terminated by front/edge Envoy. *x-forwarded-proto* contains this information. It | |||
| will be set to either *http* or *https*. | |||
|
@phlax I'm going to merge as-is - lmk if you want a follow up with general docs clean up |
Adding the option to override scheme Risk Level: low (config guarded code) Testing: unit testing Docs Changes: n/a Release Notes: inline Part of envoyproxy#14587 Fixes envoyproxy#17105 Signed-off-by: Alyssa Wilk <[email protected]>
Adding the option to
Risk Level: low (config guarded code)
Testing: unit testing
Docs Changes: n/a
Release Notes: inline
Part of #14587
Fixes #17105