[SecurityBundle] Improve profiler’s data #57425
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Let’s display the profiler for a request matching a lone lazy firewall:
Since no channel is forced, we know the
ChannelListener
did not run. To make it more obvious, this PR displays(none)
instead of0.00 ms
when the duration is null (which will happen once #57369 is merged).Before
After
But what about the
ContextListener
? Since the firewall is stateful we know it ran, yet its displayed duration also is0.00 ms
.Turns out that because the firewall is lazy, the
ContextListener
ran way past the moment theTraceableFirewallListener
stored its data. In fact, it may be theSecurityDataCollector
itself which trigger it by accessing the security token. This PR makes theTraceableFirewallListener
fetch data only when needed, so that they’re up-to-date when theSecurityDataCollector
asks for them.Before
After
Now, let’s add a global access control so that the
AccessListener
can do its job:The profiler then says no security listeners have been recorded 🤔
This is because the
AccessListener
let theExceptionListener
work out a response by throwingAccessDeniedException
s. When this happens, theTraceableFirewallListener
is cut short before it can store the data it needs (note that it also impacts non-lazy firewalls, but past listeners would then be recorded).This PR stores these data before listeners are called, so that they are available even if one of them throws (this includes authenticators’ data which suffer from the same issue).
Before
After
(Other listeners are hidden on this screenshot but they would be displayed in the profiler.)