-
Notifications
You must be signed in to change notification settings - Fork 40.7k
Bugfix: record authentication latency before audit filter wraps up #132163
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
base: master
Are you sure you want to change the base?
Conversation
/lgtm |
LGTM label has been added. Git tree hash: 812a18d165a7d893990f6dd7dcd645a2c14064ba
|
LGTM as well! |
/lgtm |
/lgtm Thank you. |
defer func() { | ||
metrics(req.Context(), resp, ok, err, apiAuds, authenticationStart, authenticationFinish) | ||
genericapirequest.TrackAuthenticationLatency(req.Context(), authenticationFinish.Sub(authenticationStart)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to make the same change for other Track*Latency calls? lots of those are made in defer calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is non-obvious and apparently fragile enough that some sort of test to demonstrate this works properly and prevent future regressions would be a good idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to make the same change for other Track*Latency calls? lots of those are made in defer calls
we don't need them for now because others are wrapped "inside" the audit filter so the defer block is called before we dump the latency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is non-obvious and apparently fragile enough that some sort of test to demonstrate this works properly and prevent future regressions would be a good idea
agree, but it's tricky to add a unit-test for this. i tried adding one in my 2nd commit but it looks a bit odd to me because it's involving bunch of external types.
/sig auth |
Signed-off-by: Min Jin <[email protected]>
f9614f5
to
66d3f32
Compare
New changes are detected. LGTM label has been removed. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: yue9944882 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: Min Jin <[email protected]>
66d3f32
to
cfd061f
Compare
@yue9944882: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
Previously #130571 added additional annotation to audit events so that we can track authn & authz latency. However it's only able to record authz latency e.g.:
This is because kube-apiserver's filters are chained in such order:
And we recorded authentication latency in a
defer
block which works after persisting the audit log. This PR fixes this issue by recording authn latency out of the defer block. After the fix, the audit event shall look like:/kind bug
/cc @hakuna-matatah @dims @mengqiy