Skip to content

Wrap diag service listener with multiplexer so it can work behind PROXY enabled loadbalancer/proxy.#39497

Merged
AntonAM merged 7 commits intomasterfrom
anton/diag_proxy_protocol
Apr 2, 2024
Merged

Wrap diag service listener with multiplexer so it can work behind PROXY enabled loadbalancer/proxy.#39497
AntonAM merged 7 commits intomasterfrom
anton/diag_proxy_protocol

Conversation

@AntonAM
Copy link
Copy Markdown
Contributor

@AntonAM AntonAM commented Mar 18, 2024

This PR wraps diag service listener with multiplexer. It now can accept simultaneously connections that are prepended with PROXY line or not. We also add HTTP() protocol listener to multiplexer and a flag that controls whether we should issue warnings about unspecified PROXY protocol mode for this listener - diag service will always run in unspecified mode to support both local access and access from behind a proxy/loadbalancer.

Fixes #39327

Changelog: Allow diagnostic endpoints to be accessed behind a PROXY protocol enabled loadbalancer/proxy.

…XY enabled loadbalancer/proxy.

It accept simultaneously connections that are prepended with PROXY line or not.
We also don't issue warnings about unspecified PROXY protocol mode for this listener.
@AntonAM AntonAM changed the title Wrap diag service listener with multipleexr so it can work behind PROXY enabled loadbalancer/proxy. Wrap diag service listener with multiplexer so it can work behind PROXY enabled loadbalancer/proxy. Mar 18, 2024
@AntonAM AntonAM force-pushed the anton/diag_proxy_protocol branch from 9a7ab44 to 0f358b8 Compare March 18, 2024 11:20
@AntonAM AntonAM requested a review from webvictim March 18, 2024 11:20
@AntonAM AntonAM marked this pull request as ready for review March 18, 2024 11:21
@github-actions github-actions Bot requested review from justinas and zmb3 March 18, 2024 11:21
Copy link
Copy Markdown
Contributor

@espadolini espadolini left a comment

Choose a reason for hiding this comment

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

Can we at least gate this behind an option in metrics_service so we don't add load to the thing that's supposed to be used for super lightweight health checks and profiling?

@AntonAM
Copy link
Copy Markdown
Contributor Author

AntonAM commented Mar 18, 2024

@espadolini dedicated metrics_service shouldn't be affected, it's only affected if in legacy mode metrics are served by the diag service
image

Copy link
Copy Markdown
Contributor

@webvictim webvictim left a comment

Choose a reason for hiding this comment

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

LGTM, but will defer to more experienced reviewers!

Comment thread lib/multiplexer/multiplexer.go Outdated
@espadolini
Copy link
Copy Markdown
Contributor

@AntonAM I realized later that metrics_service doesn't actually serve healthz but only the prom metrics, lol

Can we put this behind a flag so in normal conditions the diag listener is only a regular OS stdlib listener handled by a plain http.Server?

@AntonAM
Copy link
Copy Markdown
Contributor Author

AntonAM commented Mar 19, 2024

@espadolini I apachebenched it and results were not that different, with 35k vs 40k reqs/sec (plain vs mux), memory consumption was relatively equal, with twice more garbage collections for the mux (125 vs 250). Considering that in real life that listener shouldn't see anywhere similar level of load, do you think it's worth it to introduce flag or something?

@espadolini
Copy link
Copy Markdown
Contributor

The additional memory pressure and resource utilization is exactly what I'm worried about, considering that the pprof endpoints are generally used to diagnose situations where resource utilization is already exceeding the norm, but I suppose we'll just be able to rely on the unix socket for the console_service for that.

@AntonAM
Copy link
Copy Markdown
Contributor Author

AntonAM commented Mar 22, 2024

Yep, but that's what I meant with ab-testing result, only twice memory overhead over the plain listener (under specifically loading just this listener with thousands reqs per second) seems negligible for the real world usage, especially for the pprof handlers.

@rosstimothy rosstimothy requested a review from espadolini March 22, 2024 21:19
Comment thread lib/service/service.go Outdated
Comment thread lib/service/service.go Outdated
}
}()

err = server.Serve(listenerHTTP)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With this change we close listenerHTTP rather than listener when we close server; I suspect that it's not a problem in practice (and it might be slightly more correct, even, considering that we want to manage the lifetime of the listener sockets in TeleportProcess rather than let random goroutines close them) but it might be worth noting in a comment in diagnostic.shutdown.

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.

We now close multiplexer in diagnostic.shutdown, which closes listener. So I guess we can do without the comment, since we've got virtually the same situation?

Comment thread lib/service/service.go Outdated
process.RegisterFunc("diagnostic.service", func() error {
err := server.Serve(listener)
if err != nil && err != http.ErrServerClosed {
muxListener, err := multiplexer.New(multiplexer.Config{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should close muxListener either here in a defer or in diagnostic.shutdown.

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.

Done 436d415

AntonAM and others added 3 commits April 1, 2024 22:33
Co-authored-by: Gus Luxton <gus@goteleport.com>
Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
@rosstimothy rosstimothy requested a review from espadolini April 2, 2024 15:00
Comment thread lib/service/service.go Outdated
Comment thread lib/service/service.go
Comment thread lib/service/service.go
Comment thread lib/service/service.go Outdated
Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
@AntonAM AntonAM added this pull request to the merge queue Apr 2, 2024
Merged via the queue into master with commit 73cbb75 Apr 2, 2024
@AntonAM AntonAM deleted the anton/diag_proxy_protocol branch April 2, 2024 19:04
@public-teleport-github-review-bot
Copy link
Copy Markdown

@AntonAM See the table below for backport results.

Branch Result
branch/v13 Failed
branch/v14 Failed
branch/v15 Create PR

AntonAM added a commit that referenced this pull request Apr 2, 2024
…XY enabled loadbalancer/proxy. (#39497)

* Wrap diag service listener with multiplexer so it can work behind PROXY enabled loadbalancer/proxy.

It accept simultaneously connections that are prepended with PROXY line or not.
We also don't issue warnings about unspecified PROXY protocol mode for this listener.

* Fix wording.

Co-authored-by: Gus Luxton <gus@goteleport.com>

* Use ExitContext instead of GracefulExitContext

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>

* Close diag multiplexer listener during diagnostic.shutdown event.

* Refactor server.Serve() call

* Move creation of muxListener outside of diagnostic.service event.

* Combine declaration and usage

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>

---------

Co-authored-by: Gus Luxton <gus@goteleport.com>
Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
AntonAM added a commit that referenced this pull request Apr 2, 2024
…XY enabled loadbalancer/proxy. (#39497)

* Wrap diag service listener with multiplexer so it can work behind PROXY enabled loadbalancer/proxy.

It accept simultaneously connections that are prepended with PROXY line or not.
We also don't issue warnings about unspecified PROXY protocol mode for this listener.

* Fix wording.

Co-authored-by: Gus Luxton <gus@goteleport.com>

* Use ExitContext instead of GracefulExitContext

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>

* Close diag multiplexer listener during diagnostic.shutdown event.

* Refactor server.Serve() call

* Move creation of muxListener outside of diagnostic.service event.

* Combine declaration and usage

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>

---------

Co-authored-by: Gus Luxton <gus@goteleport.com>
Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
github-merge-queue Bot pushed a commit that referenced this pull request Apr 2, 2024
…XY enabled loadbalancer/proxy. (#39497) (#40139)

* Wrap diag service listener with multiplexer so it can work behind PROXY enabled loadbalancer/proxy.

It accept simultaneously connections that are prepended with PROXY line or not.
We also don't issue warnings about unspecified PROXY protocol mode for this listener.

* Fix wording.



* Use ExitContext instead of GracefulExitContext



* Close diag multiplexer listener during diagnostic.shutdown event.

* Refactor server.Serve() call

* Move creation of muxListener outside of diagnostic.service event.

* Combine declaration and usage



---------

Co-authored-by: Gus Luxton <gus@goteleport.com>
Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
github-merge-queue Bot pushed a commit that referenced this pull request Apr 3, 2024
…XY enabled loadbalancer/proxy. (#39497) (#40140)

* Wrap diag service listener with multiplexer so it can work behind PROXY enabled loadbalancer/proxy.

It accept simultaneously connections that are prepended with PROXY line or not.
We also don't issue warnings about unspecified PROXY protocol mode for this listener.

* Fix wording.



* Use ExitContext instead of GracefulExitContext



* Close diag multiplexer listener during diagnostic.shutdown event.

* Refactor server.Serve() call

* Move creation of muxListener outside of diagnostic.service event.

* Combine declaration and usage



---------

Co-authored-by: Gus Luxton <gus@goteleport.com>
Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

proxy protocol v2 for diag_addr

4 participants