-
Notifications
You must be signed in to change notification settings - Fork 870
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
Capture identity attributes (enduser.*) for applications using Spring Security #9400
Comments
Hey @philsttr , I think this'd be a welcome addition 👍
fragment in the spec theough. |
Agreed. Probably should do that for the existing servlet instrumentation that sets |
Maybe these attributes could be captured for most spring security use cases by instrumenting SecurityContextHolder#setContext? From there a list of GrantedAuthority are accessible, which is where roles and scopes are stored. The spring convention is that roles start with the prefix One of the things i'm not sure about is this part of the convention:
For example, i've seen production queue consumer code that manually calls |
Filed #9740 for updating the existing servlet instrumentation to not capture |
Looking for advice on how to best implement this requirement..
Should this requirement be implemented by:
Also looking for suggestions on what the configuration property should be named. |
IMO option 1 should be chosen as the solution here -- treat this attribute as an opt-in thing, and only collect it when the user explicitly configures the agent to do so.
SGTM 👍 |
I agree. I have seen a lot of code other than inbound authentication code call SecurityContextHolder#setContext. So I think if we were to instrument that method, it would catch too many use cases outside of the scope of setting the
I agree with this. After looking through spring security code a bit, I think the authentication related filters would be the best place to capture the Reactive:
Servlet:
|
related: open-telemetry/semantic-conventions#128 (comment)
|
I just filed spring-projects/spring-security#14046 to see if the Spring Security team would consider adding a hook that could be used by instrumentation to capture these attributes, or to see if they would recommend a different approach. |
New approach, as suggested by the spring-security folks... Add a filter into the spring security filter chain. The new filter is ordered after the filters that setup the spring security context. Therefore, the new filter can retrieve the Authentication and populate the enduser.* attributes. More specifically
|
For reference: #9777 adds the OpenTelemetry instrumentation described above |
Is your feature request related to a problem? Please describe.
General identity attributes (
enduser.id
,enduser.role
,enduser.scope
) are not captured for SERVER spans in applications using Spring Security OAuth2 Resource Server for Servlet or WebFlux based applications.The existing servlet instrumentation currently captures the
enduser.id
in a couple places (here and here). However, in an Servlet-based application using Spring Security OAuth2 Resource Server, therequest.getUserPrincipal()
returns null at this level. It returns null here because Spring Security wraps that request object in a request wrapper at a higher level, and the user principal is only returned from the wrapper at the higher level. In other words, since the servlet instrumentation only has access to the lower level request, and not the higher level request wrapper, the user principal seen by the servlet instrumentation is null, and therefore theenduser.id
is not captured.In addition, there is no existing instrumentation for capturing the
enduser.id
in WebFlux applications.Describe the solution you'd like
I would like general identity attributes (
enduser.id
,enduser.role
,enduser.scope
) to be captured for SERVER spans in applications using Spring Security OAuth2 Resource Server for Servlet and WebFlux based applications.Describe alternatives you've considered
No response
Additional context
While the new instrumentation probably needs to be Spring Security specific, it does not necessarily need to be specific to OAuth2 Resource Servers authentication/authorization. i.e. The new instrumentation could probably work for any type of Spring Security based authentication/authorization.
The text was updated successfully, but these errors were encountered: