Skip to content

Add forward proto header configuration for cluster monitoring #729

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

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

Conversation

raj-manvar
Copy link
Member

Description

As documented at https://trino.io/docs/current/security/tls.html#use-a-load-balancer-to-terminate-tls-https, when Trino is behind a loadbalancer or proxy like Trino Gateway, it's common that the TLS is terminated at Trino Gateway.

Correspondingly when Trino Gateway forwards the request to Trino clusters, Gateway adds X-Forwarded-* headers in code here. Relevant documentation is here where users can optionally disable this by setting routing.addXForwardedHeaders to false.

This MR is to add the same Header while making health check calls to get cluster stats like queued queries or running queries. Since it's possible that TLS is terminated at Gateway, a similar header would be required when making the http calls to fetch the cluster stats, for example using the /metrics or /v1/jmx/mbean endpoints

If such a header isn't added, the http call to fetch metrics would fail with an error like:

UnexpectedResponseException{message=Request is missing required keys: 
presto_execution_name_QueryManager_RunningQueries
presto_execution_name_QueryManager_QueuedQueries
trino_metadata_name_DiscoveryNodeManager_ActiveNodeCount
in response: 'Error 403 Forbidden: Authentication over HTTP is not enabled', request=GET http://xxxxxxx/metrics?xxxx

Additional context and related issues

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
(x) Release notes are required, with the following suggested text:

* Add option to add `X-Forwarded-Proto` when fetching cluster stats.

@cla-bot cla-bot bot added the cla-signed label Jul 21, 2025
@raj-manvar raj-manvar force-pushed the add_forwarded_header_for_metrics_collector branch from 2be12cb to 5b715e9 Compare July 21, 2025 20:15
@Chaho12 Chaho12 requested a review from andythsu July 21, 2025 23:12
Copy link
Member

@Chaho12 Chaho12 left a comment

Choose a reason for hiding this comment

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

@andythsu Can you check this?

@raj-manvar raj-manvar force-pushed the add_forwarded_header_for_metrics_collector branch from 5b715e9 to f541a47 Compare July 22, 2025 14:00
@raj-manvar raj-manvar force-pushed the add_forwarded_header_for_metrics_collector branch from f541a47 to c52f01d Compare July 22, 2025 17:27
Copy link
Member

@vishalya vishalya left a comment

Choose a reason for hiding this comment

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

LGTM

@andythsu
Copy link
Member

On a second thought, is this PR necessary? We are currently using UI_API for healthchecks which calls Trino via HTTPS. We had to turn on ssl for this. How is making calls to /metrics different from UI_API?

@raj-manvar
Copy link
Member Author

raj-manvar commented Jul 22, 2025

@andythsu https://trino.io/docs/current/security/tls.html#use-a-load-balancer-to-terminate-tls-https has more details, but when a Trino cluster is behind a LoadBalancer/Gateway it usually just doesn't accept https connections ( and only accepts non-secure http connections) . I think in your case, both Gateway and Trino clusters maybe accepting https connections, but that maynot always be the case.
Copy pasting from the above page.

The load balancer or proxy server accepts TLS connections and forwards them to the Trino coordinator, which typically runs with default HTTP configuration on the default port, 8080.

This is because the Trino clusters don't have a certificate which is globally trusted, only the LoadBalancer/Gateway is mounted with a trusted certificate.
For Trino to accept any non-secure http connection with credentials ( via /metrics endpoints or /v1/query) a X-Forwarded-Proto header is required

@raj-manvar
Copy link
Member Author

raj-manvar commented Jul 22, 2025

We could also consider adding this header by default for all cluster health http calls. For the /v1/statement endpoints this header is added by default here ( unless users specifically set routing.addXForwardedHeaders to false ).
I think having the header maybe harmless incase of secure https connections anyways so we could add it by default

@raj-manvar
Copy link
Member Author

Hello all, is this good to merge now ? Thanks!

@@ -18,6 +18,7 @@ public class BackendStateConfiguration
private String username;
private String password = "";
private Boolean ssl = false;
private boolean addXForwardedProtoHeader;
Copy link
Member

Choose a reason for hiding this comment

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

Could you change to String xForwardedProtoHeader instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

hi, sorry to clarify, you mean the property would take a string value like http or https ? or the property would take string value of true or false ?

Copy link
Member

Choose a reason for hiding this comment

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

The former.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the clarification! Could there be any scenario where the value of the header is anything except https ? 🤔 I don't know of any such cases.

Copy link
Member

Choose a reason for hiding this comment

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

I'm okay with boolean, but we usually don't use "add" prefix. I think we can simply rename it to "xForwardedProtoHeader"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants