-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Add EventSource/EventCounter tracing and metrics for Authentication #4665
Comments
What's the general idea/goal behind what we choose to expose as events/counters? Is this going to be a subset of everything we log/trace? |
@HaoK yes, it is likely a subset of the things we log. In theory, we could make every log message an Event as well, but I think in practice that's a lot of work. Authentication isn't the highest priority area for this work, but I wanted to log what I've found so far and start tracking it since I was exploring this area already to sketch out the patterns we'd use for
|
Also adding @leastprivilege @brockallen and @PinpointTownes for any additional thoughts on this based on what you have seen in the community and problems that customers have run into. |
Parking on @Tratcher 's plate to noodle on this and come up with a final list. |
I'm all for adding ETW tracing/metrics support but it's not super clear how this would concretely help customers with the problems they run into when using the security stack (except maybe... perf issues?).
|
@PinpointTownes this is about tracking trends in your application, not diagnosing individual issues. There is an open question on what data would be meaningful in that context, the counters listed above are only suggestions to start the discussion. For example a single error log from a remote callback is only noise, but when you see that suddenly 20% of logins result in errors then that alerts you to investigate and/or roll back recent changes. These counters can also be left on where constant logging would be too much overhead. |
@PinpointTownes The main goal of this effort is EventCounters, which don't have an analog in logging right now. But EventCounters run on top of EventSources so they end up coming in together. Also EventSource != ETW and we've been looking at ways to make EventSource data more accessible. There are also APM tools that already use it and libraries like EventFlow. We need to add EventSources to get the counters so it won't hurt to beef up our tracing across the board at the same time (ILogger, EventSource, etc.). Also, this work should include putting |
Ah, I guess it changed recently 'cause when it was released a few years ago, it was pretty much tied to ETW (tho' you could register your own listeners, the internal APIs made direct calls to ETW and PerfView was the only tool able to collect the traces).
Thanks for clarifying. I think I got confused when @Eilon mentioned customers problems but your remarks made clearer the fact it's mainly used for statistics (pretty much like what we had in ASP.NET 4.x with perf counters, but for much more events 😅). I took a brief look at the list and it looks good (even if it's indeed mostly for things that didn't go well). Two remarks tho':
|
Not much has changed here, but the in-proc stuff is the place we plan to do some work improving. The API still directly writes to ETW but also to the in-proc listeners and it works fine on Linux (just not calling ETW). The thought here is that we can provide a better in-proc story for gathering and shipping this data. |
Catching up with ASP.NET 4.x perf counters is indeed the primary driving force behind this. The rest is nice-to-have :) |
|
It hasn't been done. Issue here: #47603 |
Closing this as dupe of #47603 |
This is part of the larger EventCounter/EventSource effort across the platform. Specific events and counters are suggested below. Let the discussions begin! :)
Start
/Stop
/Failure
events will all haveDuration
event counters associated with them that will time the duration betweenStart
andStop
.Stop
events occur even in the case of failure (thinkfinally
blocks).Microsoft-AspNetCore-Authentication
Event SourceRemoteAuthenticationFailure
traces calls toRemoteAuthenticationEvents.RemoteFailure
TicketReceived
traces calls toRemoteAuthenticationEvents.TicketReceived
HandleRequestStart
/Stop
/Failure
tracesIAuthenticationRequestHandler.HandleRequestAsync
but only starts afterShouldHandleRequestAsync
succeeds. Thus not tracing requests that are not handled by the handler.Microsoft-AspNetCore-Authentication-Cookies
Event SourceCookieRefreshed
traces whenCookieAuthenticationHandler.RequestRefresh
is called. Payload includes issue time, the old expiration and the new expiration?CookieExpired
traces when an expired cookie token is received. Obviously this can't catch expiry of tokens until the expired token is actually presented to the server.Microsoft-AspNetCore-Authentication-JwtBearer
Event SourceTokenValidationFailed
traces tokens that fail to validateInvalidTokensReceived
counter incremented when token validation failsMicrosoft-AspNetCore-Authentication-OAuth
Event Source (shared by OAuth providers)CorrelationFailed
traces occasions where the correlation ID cannot be verified.CorrelationFailures
counter incremented when token validation failsExchangeCodeStart
/Stop
/Failure
traces the backchannel request to exchange the code for a tokenMicrosoft-AspNetCore-Authentication-OpenIDConnect
Event Source (shared by OIDC providers)RedeemAuthorizationCodeStart
/Stop
/Failure
traces the backchannel request to redeem an authorization codeTokenValidationFailed
traces tokens that fail to validateInvalidTokensReceived
counter incremented when token validation failsGetUserInformationStart
/Stop
/Failure
traces the backchannel request to get user informationI want to avoid the whole "the perfect is the enemy of the good" issue and focus on a relatively simple set of initial events. So I focused on tracing external dependencies and possible malicious actions (invalid tokens). Once in, it should be easy to iterate and add more events.
Also, there's a broad category of AuthN-related events which will live in
HttpAbstractions
withAuthorizationService
See https://gist.github.com/anurse/af1859663ac91c6cf69c820cebe92303 for some guidance on adding
EventSource
s andEventCounter
s to ASP.NET projects./cc @PinpointTownes @Tratcher @davidfowl
The text was updated successfully, but these errors were encountered: