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

l7 policy: add possibility to configure Envoy proxy xff-num-trusted-hops #32200

Merged
merged 1 commit into from
Apr 30, 2024

Conversation

mhofstetter
Copy link
Member

@mhofstetter mhofstetter commented Apr 26, 2024

Currently, when L7 policies (egress or ingress) are enforced for traffic
between Pods, Envoy might change x-forwarded-for related headers because the corresponding
Envoy listeners don't trust the downstream headers because XffNumTrustedHops
is set to 0.

e.g. x-forwarded-proto header:

Downstream x-forwarded-proto headers will only be trusted if xff_num_trusted_hops is non-zero. If xff_num_trusted_hops is zero, downstream x-forwarded-proto headers and :scheme headers will be set to http or https based on if the downstream connection is TLS or not.

https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers#x-forwarded-proto

This might be problematic if L7 policies are used for egress traffic for Pods from
a non-Cilium ingress controller (e.g. nginx). If the Ingress Controller is terminating TLS
traffic and forwards the protocol via x-forwarded-proto=https, Cilium Envoy Proxy changes
this header to x-forwarded-proto=http (if no tls termination itself is used in the policy configuration).

This breaks applications that depend on the forwarded protocol.

Therefore, this commit introduces two new config flags proxy-xff-num-trusted-hops-ingress and
proxy-xff-num-trusted-hops-egresss that configures the property XffNumTrustedHops on the respective
L7 policy Envoy listeners.

For backwards compabitility and security reasons, the values still default to 0.

Note: It's also possible to configure these values via Helm (envoy.xffNumTrustedHopsL7PolicyIngress &
envoy.xffNumTrustedHopsL7PolicyEgress).

@mhofstetter mhofstetter added area/proxy Impacts proxy components, including DNS, Kafka, Envoy and/or XDS servers. release-note/misc This PR makes changes that have no direct user impact. area/servicemesh GH issues or PRs regarding servicemesh labels Apr 26, 2024
@mhofstetter mhofstetter marked this pull request as ready for review April 26, 2024 08:46
@mhofstetter mhofstetter requested a review from a team as a code owner April 26, 2024 08:46
@mhofstetter
Copy link
Member Author

/test

@mhofstetter mhofstetter marked this pull request as draft April 26, 2024 15:17
@mhofstetter mhofstetter force-pushed the pr/mhofstetter/proxy-xff-hops branch 2 times, most recently from 2e95a6d to a192f38 Compare April 26, 2024 15:33
@mhofstetter mhofstetter changed the title l7 policy: introduce flag proxy-xff-num-trusted-hops l7 policy: add possibility to configure Envoy proxy xff-num-trusted-hops Apr 26, 2024
@mhofstetter mhofstetter force-pushed the pr/mhofstetter/proxy-xff-hops branch from a192f38 to c78dd75 Compare April 26, 2024 15:40
@mhofstetter mhofstetter added needs-backport/1.14 This PR / issue needs backporting to the v1.14 branch needs-backport/1.15 This PR / issue needs backporting to the v1.15 branch labels Apr 26, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from main in 1.15.5 Apr 26, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from main in 1.14.11 Apr 26, 2024
@jrajahalme
Copy link
Member

/test

Copy link
Member

@jrajahalme jrajahalme left a comment

Choose a reason for hiding this comment

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

LGTM

@mhofstetter mhofstetter marked this pull request as ready for review April 29, 2024 08:30
@mhofstetter mhofstetter requested review from a team as code owners April 29, 2024 08:30
@mhofstetter mhofstetter added the backport/author The backport will be carried out by the author of the PR. label Apr 29, 2024
Copy link
Member

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

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

Some nits on the docs, looks good otherwise. Thanks!

Currently, when L7 policies (egress or ingress) are enforced for traffic
between Pods, Envoy might change x-forwarded-for related headers because the corresponding
Envoy listeners don't trust the downstream headers because `XffNumTrustedHops`
is set to `0`.

e.g. `x-forwarded-proto` header:

> Downstream x-forwarded-proto headers will only be trusted if xff_num_trusted_hops is non-zero. If xff_num_trusted_hops is zero, downstream x-forwarded-proto headers and :scheme headers will be set to http or https based on if the downstream connection is TLS or not.

https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers#x-forwarded-proto

This might be problematic if L7 policies are used for egress traffic for Pods from
a non-Cilium ingress controller (e.g. nginx). If the Ingress Controller is terminating TLS
traffic and forwards the protocol via `x-forwarded-proto=https`, Cilium Envoy Proxy changes
this header to `x-forwarded-proto=http` (if no tls termination itself is used in the policy configuration).

This breaks applications that depend on the forwarded protocol.

Therefore, this commit introduces two new config flags `proxy-xff-num-trusted-hops-ingress` and
`proxy-xff-num-trusted-hops-egresss` that configures the property `XffNumTrustedHops` on the respective
L7 policy Envoy listeners.

For backwards compabitility and security reasons, the values still default to `0`.

Note: It's also possible to configure these values via Helm (`envoy.xffNumTrustedHopsL7PolicyIngress` &
`envoy.xffNumTrustedHopsL7PolicyEgress`).

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
@mhofstetter mhofstetter force-pushed the pr/mhofstetter/proxy-xff-hops branch from c78dd75 to d0d5c50 Compare April 29, 2024 09:01
@mhofstetter
Copy link
Member Author

Some nits on the docs, looks good otherwise. Thanks!

Thanks @qmonnet 🚀 🙏 - I incorporated your feedback! PTAL.

Copy link
Member

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

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

Thank you!

@qmonnet
Copy link
Member

qmonnet commented Apr 29, 2024

/test

Copy link
Member

@sayboras sayboras left a comment

Choose a reason for hiding this comment

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

LGTM ✔️

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Apr 30, 2024
@tklauser tklauser added this pull request to the merge queue Apr 30, 2024
Merged via the queue into cilium:main with commit 1bc2c75 Apr 30, 2024
64 checks passed
@mhofstetter mhofstetter deleted the pr/mhofstetter/proxy-xff-hops branch April 30, 2024 11:42
@mhofstetter mhofstetter added backport-pending/1.15 The backport for Cilium 1.15.x for this PR is in progress. and removed needs-backport/1.15 This PR / issue needs backporting to the v1.15 branch labels Apr 30, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from main to Backport pending to v1.15 in 1.15.5 Apr 30, 2024
@mhofstetter mhofstetter added backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. and removed needs-backport/1.14 This PR / issue needs backporting to the v1.14 branch labels Apr 30, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from main to Backport pending to v1.14 in 1.14.11 Apr 30, 2024
@github-actions github-actions bot added backport-done/1.14 The backport for Cilium 1.14.x for this PR is done. and removed backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. labels May 1, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot removed this from Backport pending to v1.14 in 1.14.11 May 1, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Backport done to v1.14 in 1.14.11 May 1, 2024
@github-actions github-actions bot added backport-done/1.15 The backport for Cilium 1.15.x for this PR is done. and removed backport-pending/1.15 The backport for Cilium 1.15.x for this PR is in progress. labels May 3, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.15 to Backport done to v1.15 in 1.15.5 May 3, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot removed this from Backport done to v1.15 in 1.15.5 May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/proxy Impacts proxy components, including DNS, Kafka, Envoy and/or XDS servers. area/servicemesh GH issues or PRs regarding servicemesh backport/author The backport will be carried out by the author of the PR. backport-done/1.14 The backport for Cilium 1.14.x for this PR is done. backport-done/1.15 The backport for Cilium 1.15.x for this PR is done. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.
Projects
No open projects
1.14.11
Backport done to v1.14
Development

Successfully merging this pull request may close these issues.

None yet

6 participants