Skip to content

Conversation

fivetran-kostaszoumpatianos
Copy link
Contributor

@fivetran-kostaszoumpatianos fivetran-kostaszoumpatianos commented Aug 25, 2025

Fixes #2444.

This PR adds a user principal tag in metrics and an associated configuration option that turns it on.
This is the following: polaris.metrics.user-principal-tag.enable-in-api-metrics, and by default this is set to false.

To retrieve the user principal ID it uses the SecurityContext and annotates it with a MeterTag annotation under the key principal.

dimas-b
dimas-b previously approved these changes Aug 25, 2025
Copy link
Contributor

@dimas-b dimas-b left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Thanks for your contribution, @fivetran-kostaszoumpatianos !

* even crash the server.
*/
@WithDefault("false")
boolean enableInApiMetrics();
Copy link
Contributor

Choose a reason for hiding this comment

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

Defaulting to false here looks reasonable to me. Still, since this may expose sensitive information, please open a dev email discussion for visibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @dimas-b I sent an email to dev.

@github-project-automation github-project-automation bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board Aug 25, 2025
@fivetran-kostaszoumpatianos
Copy link
Contributor Author

LGTM 👍 Thanks for your contribution, @fivetran-kostaszoumpatianos !

Thanks @dimas-b I will send a dev email.

@fivetran-kostaszoumpatianos
Copy link
Contributor Author

@dimas-b I had to re-format the code, and your approval got removed. Could you please take another look? Thanks!

@adutra
Copy link
Contributor

adutra commented Aug 26, 2025

FYI here is the ML discussion thread:

https://lists.apache.org/thread/o7of5dpmglmkjosftqsyr54x3dcfo1o4

I replied there but to summarize my opinion here: I'm not against the idea but there are security risks. Imo this feature should be opt-in (which is the case) and guarded by a production readiness check.

@fivetran-kostaszoumpatianos
Copy link
Contributor Author

FYI here is the ML discussion thread:

https://lists.apache.org/thread/o7of5dpmglmkjosftqsyr54x3dcfo1o4

I replied there but to summarize my opinion here: I'm not against the idea but there are security risks. Imo this feature should be opt-in (which is the case) and guarded by a production readiness check.

Thank you @adutra I have added a production readiness check.

dimas-b
dimas-b previously approved these changes Aug 26, 2025
if (config.userPrincipalTag().enableInApiMetrics()) {
return ProductionReadinessCheck.of(
Error.of(
"Metrics configuration includes user principal name in tags.",
Copy link
Contributor

@dimas-b dimas-b Aug 26, 2025

Choose a reason for hiding this comment

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

This will effectively always produce WARN log messages in servers where principal tags are enabled, even if the admin user configured that explicitly. From my POV this is not ideal user experience, but having this WARN is probably better that accidentally exposing principal names.

I think we may want to add per-message suppression for production checks at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree. We should have that at some point. In the interim we could get away with just having the warning there. I can open an issue and work on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dimas-b
For selectively turning off readiness checks specific to a given list of offending parameters, I created an issue: #2471 and an associated PR: #2472

@@ -113,6 +114,17 @@ public void warnOnFailedChecks(
}
}

@Produces
public ProductionReadinessCheck checkMetricTags(MetricsConfiguration config) {
if (config.userPrincipalTag().enableInApiMetrics()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we are missing a readiness check when both tags are enabled, since this is the most dangerous situation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, this is a great point. I added one.

@@ -39,7 +39,9 @@ public Map<String, String> getConfigOverrides() {
"polaris.metrics.realm-id-tag.enable-in-api-metrics",
"true",
"polaris.metrics.realm-id-tag.enable-in-http-metrics",
"true");
"true",
Copy link
Contributor

Choose a reason for hiding this comment

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

At some point I think we'll need to refactor these tests and create a sort of "parameterized Quarkus test" that tests all the combinations of (realm tag on/off) x (principal tag on/off). But we can look into that later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good point. Thanks!

eric-maynard
eric-maynard previously approved these changes Aug 26, 2025
Copy link
Contributor

@eric-maynard eric-maynard left a comment

Choose a reason for hiding this comment

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

As long as it's off by default, this LGTM!

@dimas-b dimas-b merged commit 3f1dfb3 into apache:main Aug 26, 2025
12 checks passed
@github-project-automation github-project-automation bot moved this from Ready to merge to Done in Basic Kanban Board Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Report user principal tag in metrics
4 participants