Skip to content

Support for x-forwarded-host header. - #18639

Merged
rojkov merged 18 commits into
envoyproxy:mainfrom
arun-vasudev:support-x-forwarded-host
Nov 23, 2021
Merged

rojkov merged 18 commits into
envoyproxy:mainfrom
arun-vasudev:support-x-forwarded-host

Conversation

@arun-vasudev

Copy link
Copy Markdown
Contributor

If, for a request, the host/authority header is changed when the
request is proxied, set the x-forwarded-host header as:
x-forwarded-host = append(x-forwarded-host, host)

Signed-off-by: Arun Olappamanna Vasudevan [email protected]

Commit Message: Support for x-forwarded-host header.

Additional Description:
If, for a request, the host/authority header is changed when the
request is proxied, set the x-forwarded-host header as:
x-forwarded-host = append(x-forwarded-host, host)

Risk Level: Low

Testing: unit test and manual testing

Docs Changes:
Added x-forwarded-host header in HTTP header manipulation
(configuration/http/http_conn_man/headers).
Under the host_rewrite options in route_components.proto
(in v3), added that when host is rewritten, the XFH header is
appended with the original value of host header if append_x_forwarded_host
option is set.

Release Notes: router: added support for x-forwarded-host header.

Platform Specific Features: N/A

Fixes #5940

API Considerations: append_x_forwarded_host in route options

If, for a request, the host/authority header is changed when the
request is proxied, set the x-forwarded-host header as:
x-forwarded-host = append(x-forwarded-host, host)

Signed-off-by: Arun Olappamanna Vasudevan <[email protected]>
@repokitteh-read-only

Copy link
Copy Markdown

Hi @arun-vasudev, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #18639 was opened by arun-vasudev.

see: more, trace.

@repokitteh-read-only

Copy link
Copy Markdown

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

🐱

Caused by: #18639 was opened by arun-vasudev.

see: more, trace.

1. Initialize append_xfh_ in RouteEntry implementation.
2. Version history is not in alphabetical order.
3. Minor typo fix the documentation for append_x_forwarded_host.
4. Fix the cross-references to append_x_forwarded_host.

Signed-off-by: Arun Olappamanna Vasudevan <[email protected]>
@arun-vasudev
arun-vasudev force-pushed the support-x-forwarded-host branch from e6c5cab to 72bb91e Compare October 18, 2021 07:02
@htuch

htuch commented Oct 29, 2021

Copy link
Copy Markdown
Member

/assign-from @envoyproxy/first-pass-reviewers

@repokitteh-read-only

Copy link
Copy Markdown

@envoyproxy/first-pass-reviewers assignee is @rojkov

🐱

Caused by: a #18639 (comment) was created by @htuch.

see: more, trace.

@rojkov rojkov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for working on this! Looks good, only one question to clarify.

Comment thread source/common/http/utility.cc Outdated
Comment on lines +392 to +394
if (hostname.empty()) {
return;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doesn't it change the current default behavior for empty hostnames?
If hostname can never be empty then, perhaps, it's better to ASSERT() it to catch bugs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That makes sense! We can retain the original behavior by removing the check. I do not think we can ASSERT() because host_rewrite_path_regex_->replaceAll in source/common/router/config_impl.cc could potentially return an empty string.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see. Alright then. Could you please extend the unit test to include the case of empty hostname?

* Retain default behavior in updateAuthority.
* Enumerate all host rewrite options in the documentation for
  append_x_forwarded_host.

Signed-off-by: Arun Olappamanna Vasudevan <[email protected]>
@repokitteh-read-only

Copy link
Copy Markdown

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: #18639 was synchronize by arun-vasudev.

see: more, trace.

oneof host_rewrite_specifier {
// Indicates that during forwarding, the host header will be swapped with
// this value.
// this value. Using this option may manipulate the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/may manipulate/will append/g (here and other cases).

@htuch htuch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

API LGTM modulo small comment.

@rojkov

rojkov commented Nov 2, 2021

Copy link
Copy Markdown
Member

/wait

@arun-vasudev
arun-vasudev requested review from htuch and rojkov November 17, 2021 07:07

@rojkov rojkov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Looks very good. The CI checks need to be fixed:

RSTChecker ERROR [current_version] (docs/root/version_history/current.rst:70) Version history not in alphabetical order (router vs oauth filter): please check placement of line
 * oauth filter: setting IdToken and RefreshToken cookies if they are provided by Identity provider along with AccessToken..

To test locally you can run ./tools/code_format/check_format.py fix.

@htuch htuch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm api

@rojkov

rojkov commented Nov 18, 2021

Copy link
Copy Markdown
Member

/wait

@arun-vasudev
arun-vasudev force-pushed the support-x-forwarded-host branch from 3d69e13 to 527ea51 Compare November 19, 2021 23:20
@arun-vasudev
arun-vasudev requested review from htuch and rojkov November 19, 2021 23:23
@arun-vasudev

Copy link
Copy Markdown
Contributor Author

It seems to be failing while trying to download googleapis:

ERROR: An error occurred during the fetch of repository 'com_google_googleapis':
   Traceback (most recent call last):
	File "/build/tmp/_bazel_envoybuild/b570b5ccd0454dc9af9f65ab1833764d/external/bazel_tools/tools/build_defs/repo/http.bzl", line 111, column 45, in _http_archive_impl
		download_info = ctx.download_and_extract(
Error in download_and_extract: java.io.IOException: Error downloading [https://github.com/googleapis/googleapis/archive/82944da21578a53b74e547774cf62ed31a05b841.tar.gz] to /build/tmp/_bazel_envoybuild/b570b5ccd0454dc9af9f65ab1833764d/external/com_google_googleapis/temp17361798439020319310/82944da21578a53b74e547774cf62ed31a05b841.tar.gz: GET returned 502 Bad Gateway
ERROR: Error fetching repository: Traceback (most recent call last):
	File "/build/tmp/_bazel_envoybuild/b570b5ccd0454dc9af9f65ab1833764d/external/bazel_tools/tools/build_defs/repo/http.bzl", line 111, column 45, in _http_archive_impl
		download_info = ctx.download_and_extract(
Error in download_and_extract: java.io.IOException: Error downloading [https://github.com/googleapis/googleapis/archive/82944da21578a53b74e547774cf62ed31a05b841.tar.gz] to /build/tmp/_bazel_envoybuild/b570b5ccd0454dc9af9f65ab1833764d/external/com_google_googleapis/temp17361798439020319310/82944da21578a53b74e547774cf62ed31a05b841.tar.gz: GET returned 502 Bad Gateway
ERROR: no such package '@com_google_googleapis//': java.io.IOException: Error downloading [https://github.com/googleapis/googleapis/archive/82944da21578a53b74e547774cf62ed31a05b841.tar.gz] to /build/tmp/_bazel_envoybuild/b570b5ccd0454dc9af9f65ab1833764d/external/com_google_googleapis/temp17361798439020319310/82944da21578a53b74e547774cf62ed31a05b841.tar.gz: GET returned 502 Bad Gateway
Traceback (most recent call last):
  File "/source/tools/api/generate_go_protobuf.py", line 138, in <module>
    generate_protobufs(args.targets, output, args.api_repo)
  File "/source/tools/api/generate_go_protobuf.py", line 26, in generate_protobufs
    bazel_bin = check_output(['bazel', 'info', 'bazel-bin']).decode().strip()
  File "/usr/lib/python3.8/subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['bazel', 'info', 'bazel-bin']' returned non-zero exit status 1.
##[error]Bash exited with code '1'.
Finishing: Run CI script

https://dev.azure.com/cncf/envoy/_build/results?buildId=94945&view=logs&j=b4781dd6-e8d1-56ca-824c-e97e27bdf79d&t=45617383-04d6-5506-f07f-2ba46008d9c7

Is this a known issue? It'll be great if someone can help out here. @htuch @rojkov

Signed-off-by: Arun Olappamanna Vasudevan <[email protected]>
@arun-vasudev
arun-vasudev force-pushed the support-x-forwarded-host branch from cf713a5 to 8b4f7d0 Compare November 21, 2021 08:00
@arun-vasudev

Copy link
Copy Markdown
Contributor Author

It seems to be a transient issue. The checks look good now.

@rojkov rojkov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! Looks good modulo small nitpick.

x-forwarded-host
----------------

The *x-forwarded-host* header is a standard proxy header which indicates the original host

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: Technically there's no standard for this header. The standard specifies Forwarded instead.

Suggested change
The *x-forwarded-host* header is a standard proxy header which indicates the original host
The *x-forwarded-host* header is a de-facto standard proxy header which indicates the original host

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you, @rojkov. I just fixed that.

@arun-vasudev
arun-vasudev requested a review from rojkov November 23, 2021 00:58

@rojkov rojkov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! LGTM

@rojkov
rojkov merged commit 91c2e6b into envoyproxy:main Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for X-Forwarded-Host header

3 participants