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

mesh: support configuring XFF trusted cidrs #3344

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rudrakhp
Copy link
Member

Ref istio/istio#53185
Related feature in envoy here.

@rudrakhp rudrakhp requested a review from a team as a code owner October 29, 2024 14:01
@istio-policy-bot
Copy link

😊 Welcome @rudrakhp! This is either your first contribution to the Istio api repo, or it's been
a while since you've been here.

You can learn more about the Istio working groups, Code of Conduct, and contribution guidelines
by referring to Contributing to Istio.

Thanks for contributing!

Courtesy of your friendly welcome wagon.

@istio-testing istio-testing added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Oct 29, 2024
@rudrakhp rudrakhp force-pushed the xff_trusted_cidrs branch 2 times, most recently from 6e02798 to 902e15f Compare November 2, 2024 04:59
Signed-off-by: Rudrakh Panigrahi <[email protected]>
@rudrakhp
Copy link
Member Author

rudrakhp commented Dec 1, 2024

@istio/technical-oversight-committee bumping this up. Thanks!

// If all addresses in X-Forwarded-For (XFF) header are within the trusted list, the first (leftmost) entry is used.
// See [Envoy XFF](https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers#config-http-conn-man-headers-x-forwarded-for)
// header handling for more details. Only one of `numTrustedProxies` and `trustedCidrs` may be set.
repeated string trusted_cidrs = 4;
Copy link
Member

Choose a reason for hiding this comment

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

The envoy docs say we cannot use it with UseRemoteAddress. UseRemoteAddress is currently always set to 'true' for gateways.

What will be the behavior if a user sets this? Will we set useRemoteAddress=false? What side effects does this have beyond deciding how to parse the XFF header?

Copy link
Member Author

Choose a reason for hiding this comment

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

@howardjohn Yes we will have to always set UseRemoteAddress to false if we decide to use the XFF original IP detection extension (which is recommended over the alternative we use today, might soon be on deprecation path).

What side effects does this have beyond deciding how to parse the XFF header?

From the docs it does look like the only thing that changes is how the original IP is determined, HCM does it natively today, we will be moving to original IP detection extension.

Meanwhile waiting on a probable fix for difference in behaviour of HCM and the XFF origin detection extension: envoyproxy/envoy#37780

Copy link
Member Author

@rudrakhp rudrakhp Feb 10, 2025

Choose a reason for hiding this comment

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

@howardjohn please refer envoyproxy/envoy#34241 (comment) for moving to original IP detection extension with backward compatibility. Corresponding implementation in envoyproxy/gateway as an example. WDYT?

Copy link
Contributor

@jaellio jaellio Feb 14, 2025

Choose a reason for hiding this comment

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

Is your goal to use a detection extension and set xff_trusted_cidrs? Is this change blocked on a similar change as above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is your goal to use a detection extension and set xff_trusted_cidrs

Yes

Is this change blocked on a similar change as above?

It's technically not blocked. According to discussion in envoyproxy/envoy#34241 (comment), setting UseRemoteAddress to false will unblock setting trusted CIDRs, but will change the behaviour of XFFNumTrustedHops set today in HCM. So for XFFNumTrustedHops to remain backward compatible after unsetting USeRemoteAddress, we will have to decrement the user configured num hops before setting it in the detection extension. Please refer to comment referred above with an example of equivalent configurations.

@istio-testing istio-testing added the needs-rebase Indicates a PR needs to be rebased before being merged label Dec 4, 2024
@istio-testing
Copy link
Collaborator

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Comment on lines +279 to +281
// When the remote IP address matches a trusted CIDR and the X-Forwarded-For (XFF) header was sent,
// each entry in the X-Forwarded-For (XFF) header is evaluated from right to left
// and the first public non-trusted address is used as the original client address.
Copy link
Contributor

@jaellio jaellio Feb 14, 2025

Choose a reason for hiding this comment

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

This differs from the current envoy documentation. https://github.com/envoyproxy/envoy/blob/main/docs/root/configuration/http/http_conn_man/headers.rst?plain=1#L274-L276

  • If the remote address is contained by an entry in xff_trusted_cidrs, and the last
    (rightmost) entry is also contained by an entry in xff_trusted_cidrs, the trusted client
    address is second-last IP address in XFF.

Based on the docs I'd expect the second to last IP address in the XFF header to be used as the original client address. Not sure if this documentation is correct though. The docs conflict with a later example https://github.com/envoyproxy/envoy/blob/main/docs/root/configuration/http/http_conn_man/headers.rst?plain=1#L370-L383

 Example 7: Envoy as edge proxy, with one trusted CIDR
 Settings:
   | use_remote_address = false
   | xff_trusted_cidrs = 192.0.2.0/24

 Request details:
   | Downstream IP address = 192.0.2.5
   | XFF = "203.0.113.128, 203.0.113.10, 192.0.2.1"

 Result:
   | Trusted client address = 192.0.2.1
   | X-Envoy-External-Address is set to 192.0.2.1
   | XFF is changed to "203.0.113.128, 203.0.113.10, 192.0.2.1, 192.0.2.5"
   | X-Envoy-Internal is removed (if it was present in the incoming request)```

Note the trusted client address is set to `192.0.2.1`. Based on the documentation I would have expected the trusted client address to be set to `203.0.113.10`. I thought maybe the `second-last` address was evaluated after appending the downstream IP address to the XFF but this also conflicts with a later example https://github.com/envoyproxy/envoy/blob/main/docs/root/configuration/http/http_conn_man/headers.rst?plain=1#L385-398
Example 8: Envoy as edge proxy, with two trusted CIDRs
Settings:
  | use_remote_address = false
  | xff_trusted_cidrs = 192.0.2.0/24, 198.51.100.0/24

Request details:
  | Downstream IP address = 192.0.2.5
  | XFF = "203.0.113.128, 203.0.113.10, 198.51.100.1"

Result:
  | Trusted client address = 203.0.113.10
  | X-Envoy-External-Address is set to 203.0.113.10
  | XFF is changed to "203.0.113.128, 203.0.113.10, 198.51.100.1, 192.0.2.5"
  | X-Envoy-Internal is removed (if it was present in the incoming request)```

In example 8, the trusted client address is set to 203.0.113.10 which is the expected second-last XFF IP.

@rudrakhp Could you please verify the expected behavior? I'd block merging until this is clarified.

Copy link
Contributor

@jaellio jaellio Feb 14, 2025

Choose a reason for hiding this comment

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

Created an envoy issue to track this envoyproxy/envoy#38462

Copy link
Contributor

@jaellio jaellio Feb 18, 2025

Choose a reason for hiding this comment

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

Based on my investigation and digging into the envoy code, your comment is correct. The envoy documentation is incorrect. Updated the envoy issue accordingly envoyproxy/envoy#38462 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

@jaellio thanks for confirming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-rebase Indicates a PR needs to be rebased before being merged size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants