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

Cleanup illegal_ports and ARC all of PI #1040

Merged
merged 9 commits into from
May 22, 2024

Conversation

bleggett
Copy link
Contributor

@bleggett bleggett commented May 10, 2024

This is mostly just pushing some minor local cleanups.

  • Arc all of ProxyInputs. We can probably de-arc some of the bits inside so they aren't double-arc'd eventually, but handlers shouldn't be able to get mut-ref to anything in PI - if they need to, it doesn't belong in PI.

  • Put illegal_ports in config - it is effectively config anyway - all the values are sourced from config, and everywhere we use illegal_ports we already have config.

General goal is to make sure handlers keep a clean distinction between runtime-mutable state (their inner state/explicit mutable args) and state that should not be runtime-mutable (static config, proxyinputs)

We have tests that (ab)use this lack of immutability which this also twiddles a bit, mostly just enough to prevent us from writing more tests like that.

@istio-testing
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@istio-testing istio-testing added the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label May 10, 2024
@bleggett bleggett marked this pull request as ready for review May 10, 2024 18:56
@bleggett bleggett requested a review from a team as a code owner May 10, 2024 18:56
@istio-testing istio-testing added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. labels May 10, 2024
Copy link
Member

@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.

How can this work in tests where we use dynamic ports?

@howardjohn
Copy link
Member

ah we do the test in namespaced which doesn't use dynamic ports

@bleggett
Copy link
Contributor Author

bleggett commented May 10, 2024

How can this work in tests where we use dynamic ports?

We don't allow people to customize the listener ports (they're consts in the config which is where the listeners && illegal_ports both get them from) so if there are any tests that use dynamic ports, that's a bit suspect/spurious (but yeah, I don't think any do).

@howardjohn
Copy link
Member

@bleggett in direct we do, we just don't care about the illegal ports there

@bleggett
Copy link
Contributor Author

@bleggett in direct we do, we just don't care about the illegal ports there

Yeah I'm taking a look at those.

@istio-testing istio-testing added the needs-rebase Indicates a PR needs to be rebased before being merged label May 10, 2024
@bleggett bleggett force-pushed the bleggett/arc-pi branch 2 times, most recently from 3de0e8a to 91e488a Compare May 11, 2024 00:38
@istio-testing istio-testing removed the needs-rebase Indicates a PR needs to be rebased before being merged label May 11, 2024
@bleggett
Copy link
Contributor Author

@bleggett in direct we do, we just don't care about the illegal ports there

Yeah I'm taking a look at those.

What it boils down to is we break normal/prod behavior just for the purpose of some integration tests, and we have to add punchthrus to support providing a latebound HBONE port, when in every case outside of those few tests doing so would be a bug/a bad thing.

Proper solution is to move everything in direct to namespaced and drop the random HBONE port assignment to avoid port conflicts without relying on test-only structural hacks, but for now I've just prevented the use of said hack outside test code.

src/proxy.rs Outdated
// except in (some) contrived integ test cases (direct), where we bind to random non-well-known ports,
// and cannot rely on a well-known port - which is why this exists, so we can ignore
// the config object and sidechannel the non-fixed runtime-bound port.
#[cfg(any(test, feature = "testing"))]
Copy link
Member

Choose a reason for hiding this comment

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

Adding these conditional paths is risky - we effectively are now never testing the production codepath.

Why do we even need to split it? the test path will work for prod, no?

if we really want to verify we could just make an assertion conditional compiled in that hbone_port == 15008 or whatever want to check?

Copy link
Contributor Author

@bleggett bleggett May 13, 2024

Choose a reason for hiding this comment

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

We don't test the production codepath now - the production codepath can never use a dynamic port override, and we were making large chunks of (critical) state runtime-mutable just to enable this. Only tests can make use of it.

To be fair, I don't like the conditionals either though, and may just rewrite the tests to stop using dynamic port overrides.

Creating a runtime source of truth just to inject a duplicative static config value into it (but only for test flows) is both confusing to anyone that doesn't know why we are doing it, and a smell.

Copy link
Member

Choose a reason for hiding this comment

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

We do test both today because we have code running dynamic and static ports (direct and namespaced). With this PR, the tests doesn't even compile the production codepath.

Copy link
Contributor Author

@bleggett bleggett May 14, 2024

Choose a reason for hiding this comment

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

With this PR, the tests doesn't even compile the production codepath.

Right, and those tests still pass, because they were never testing that particular production codepath to begin with.

The only tests I removed were ones that were using non-production punchthrus.

The only tests that have ever hit this particular codepath directly relied on doing stuff you can't/shouldn't do in production. It's a catch 22. I'll move the direct tests to namespaced and then we should be able to drop the test-only assumptions/mess.

Copy link
Contributor Author

@bleggett bleggett May 21, 2024

Choose a reason for hiding this comment

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

Namespacing every test in direct.rs is expensive, so I picked something that should be a decent compromise.

src/proxy/inbound.rs Outdated Show resolved Hide resolved
@bleggett bleggett added the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label May 15, 2024
@istio-testing istio-testing added the needs-rebase Indicates a PR needs to be rebased before being merged label May 19, 2024
Signed-off-by: Benjamin Leggett <benjamin.leggett@solo.io>
Signed-off-by: Benjamin Leggett <benjamin.leggett@solo.io>
Signed-off-by: Benjamin Leggett <benjamin.leggett@solo.io>
Signed-off-by: Benjamin Leggett <benjamin.leggett@solo.io>
@istio-testing istio-testing removed the needs-rebase Indicates a PR needs to be rebased before being merged label May 21, 2024
Signed-off-by: Benjamin Leggett <benjamin.leggett@solo.io>
Signed-off-by: Benjamin Leggett <benjamin.leggett@solo.io>
Signed-off-by: Benjamin Leggett <benjamin.leggett@solo.io>
@bleggett bleggett removed the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label May 21, 2024
socks5_addr: Some(SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 0)),
admin_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 0),
readiness_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 0),
stats_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 0),
outbound_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 0),
inbound_plaintext_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 0),
dns_proxy_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 0),
illegal_ports: HashSet::new(), // for "direct" tests, since the ports are latebound, we can't test illegal ports
Copy link
Member

Choose a reason for hiding this comment

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

If we are not setting this, do we need to fix inbound_addr to a non-zero port?

The current approach will flake if you run multiple tests concurrently like cargo-nextest or others (I run it to detect flakes, etc)

Copy link
Member

Choose a reason for hiding this comment

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

Ah we need the hbone port

Copy link
Member

Choose a reason for hiding this comment

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

How bad is it to pass the hbone port still but keep the illegal_ports?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry I feel a bit like https://xkcd.com/1172/...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current approach will flake if you run multiple tests concurrently like cargo-nextest or others (I run it to detect flakes, etc)

Ah ok. We could probably work around this by using the namespaced ctor stuff (not isolated per-test, but isolated per-run)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still gross, but gross in one signposted spot. Should do for nextest and friends. Does for me.

@bleggett bleggett added the do-not-merge/hold Block automatic merging of a PR. label May 21, 2024
@bleggett bleggett force-pushed the bleggett/arc-pi branch 2 times, most recently from fc27069 to beebe75 Compare May 21, 2024 23:53
Signed-off-by: Benjamin Leggett <benjamin.leggett@solo.io>
src/proxy.rs Show resolved Hide resolved
Signed-off-by: Benjamin Leggett <benjamin.leggett@solo.io>
@bleggett bleggett removed the do-not-merge/hold Block automatic merging of a PR. label May 22, 2024
@istio-testing istio-testing merged commit c57fa6b into istio:master May 22, 2024
3 checks passed
howardjohn added a commit to howardjohn/ztunnel that referenced this pull request May 22, 2024
We were using the `cfg` in pool since istio#1040. `cfg` is not whether its
used, but rather the intent of the user -- we may enable or disable at
runtime.

This renames the field to make it clear it should not be used like this,
and fixes the issue. This went through CI due to
istio#1084.
istio-testing pushed a commit that referenced this pull request May 28, 2024
* Fix regression in source IP spoofing

We were using the `cfg` in pool since #1040. `cfg` is not whether its
used, but rather the intent of the user -- we may enable or disable at
runtime.

This renames the field to make it clear it should not be used like this,
and fixes the issue. This went through CI due to
#1084.

* cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants