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

router redirect: use port from the request if redirect_port not specified #25573

Closed
wants to merge 3 commits into from

Conversation

cpakulski
Copy link
Contributor

Commit Message:
use port from the request if redirect_port not specified
Additional Description:
If redirect_port config item was empty, the redirect URL did not contain any port. Now the same port is used as in the original request.
Risk Level: Low
Testing: added unit tests and manual testing.
Docs Changes: yes
Release Notes: yes
Fixes #17318

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
@repokitteh-read-only
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @htuch
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #25573 was opened by cpakulski.

see: more, trace.

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM modulo comments, @yanavlasov to provide another set of eyes.

source/common/router/config_impl.cc Show resolved Hide resolved
@@ -1117,6 +1109,17 @@ std::string RouteEntryImplBase::newPath(const Http::RequestHeaderMap& headers) c
final_port = redirect_config_->port_redirect_.c_str();
} else {
final_port = "";
const absl::string_view current_path = headers.getHostValue();
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, this is a direct response but not necessarily a redirect when you get here I think, what's to stop this applying even if it's not a redirect?

@htuch
Copy link
Member

htuch commented Feb 17, 2023

/lgtm api

Copy link
Contributor

@howardjohn howardjohn left a comment

Choose a reason for hiding this comment

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

I am worried this is a breaking change?

@@ -1659,6 +1659,7 @@ message RedirectAction {
[(validate.rules).string = {well_known_regex: HTTP_HEADER_VALUE strict: false}];

// The port value of the URL will be swapped with this value.
// If not specified, the request's port will be used.
Copy link
Contributor

Choose a reason for hiding this comment

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

The "request port" is ambiguous as there can be multiple ports associated with a given request. Is it from :authority? from the actual L4 port?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is from headers, not L4.

@@ -20,6 +20,9 @@ minor_behavior_changes:
- area: http2
change: |
Request authorities are now validated with a library function from QUICHE rather than nghttp2. This behavior change can be reverted by setting ``envoy.reloadable_features.http2_validate_authority_with_quiche`` to ``false``.
- area: router redirect
change: |
when ``port_redirect`` is not specified, the request's port is used.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a breaking change? Our current API, which exposes this option, has the following enum option:

FROM_PROTOCOL_DEFAULT: automatically set to 80 for HTTP and 443 for HTTPS.

AFAIK this was the previous behavior in envoy with port unset. With this new change, it will use another port

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIK this was the previous behavior in envoy with port unset. With this new change, it will use another port

If port_redirect is set explicitly, there is no change in behavior. Does your API requires this param or can it be left unspecified?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry to clarify, when a user sets that in our API we do not set port_redirect and explicitly expect the "automatically set to 80 for HTTP and 443 for HTTPS.". This behavior is changed by this PR, which I think represents a breaking API change for envoy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for explaining. To be precise, Envoy did not add port 80 or 443, but simply stripped the incoming port. The result was that port was auto chosen based on the protocol: http or https.
Solution to that problem would be to set port_redirect to zero for reusing the port from the request. The logic would be:

  • port_redirect not specified - as before (strip port)
  • port_redirect = 0 (reuse from request)
  • port_redirect = value (use the value specified)

Copy link
Contributor

Choose a reason for hiding this comment

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

With a uint32 I don't think you can distinguish unset and 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah.. you are right :-(

Copy link
Member

Choose a reason for hiding this comment

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

API LGTM revoked until we resolve this, thanks for noticing @howardjohn

Copy link
Contributor

Choose a reason for hiding this comment

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

@howardjohn if Istio's API says

FROM_PROTOCOL_DEFAULT: automatically set to 80 for HTTP and 443 for HTTPS

It could now explicitly set these published port values in
https://github.com/istio/istio/blob/96f6a4f16d5a5aa4905ff0c0f94d9dd607b5f5f3/pilot/pkg/networking/core/v1alpha3/route/route.go#L603
rather than implictly assuming envoy will

from the original API PR istio/api#2088 it looks like this is what istio would have wanted envoy to do

Copy link
Contributor

Choose a reason for hiding this comment

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

It really doesn't matter what Istio does or docs say, this is a breaking change in Envoy which will extend beyond Istio.

@phlax
Copy link
Member

phlax commented Feb 21, 2023

/wait

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot added the stale stalebot believes this issue/PR has not been touched recently label Mar 23, 2023
@cpakulski
Copy link
Contributor Author

I am planning to add a new config item with 3 options:

  • STRIP
  • AUTO (take port from request)
  • STATIC

It will be backwards compatible, so if not specified, it will behave as before (STRIP). If port_redirect is specified, it will take precedence over the new config item. port_redirect should be deprecated after (with deprecations guidelines: 12 months of support).

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot added the stale stalebot believes this issue/PR has not been touched recently label Apr 23, 2023
@cpakulski
Copy link
Contributor Author

Closing for now. Will open a new PR with new API.

@cpakulski cpakulski closed this Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale stalebot believes this issue/PR has not been touched recently waiting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

host_redirect cleans up the request port when port_redirect is not specified
6 participants