-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Instrument advanced auditing #46732
Instrument advanced auditing #46732
Conversation
|
||
"github.com/golang/glog" | ||
"github.com/prometheus/client_golang/prometheus" | ||
auditinternal "k8s.io/apiserver/pkg/apis/audit" |
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.
nit: empty line above
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.
Not sure what you mean here?
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.
By convention the k8s.io imports and third party libs are separated with an empty line.
plugin, len(impacted), err) | ||
for _, ev := range impacted { | ||
// Simple formatting of audit event. | ||
event := fmt.Sprintf("%s id=%q stage=%q ip=%v method=%q uri=%q user=%q groups=%q", |
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.
Can/Should we use the log backend format here?
if ev.ResponseStatus != nil { | ||
event = fmt.Sprintf("%s response=\"%d\"", event, ev.ResponseStatus.Code) | ||
} | ||
msg = msg + fmt.Sprintf("{%s}\n", event) |
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 pretty much looks like the log backend output. Let's share that code.
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.
Done.
Looks good in general. Would like to see shared code for the glog error logging and the log backend. |
^^ can be in a follow-up if the freeze becomes an issue. In that case, lgtm. |
Squash, then lgtm |
Squashed. Thanks! |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sttts, timstclair The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
Rebased on #45919 and called @ericchiang Could you take a quick look? |
Reapplying LGTM after rebase. |
lgtm |
@k8s-bot pull-kubernetes-federation-e2e-gce test this |
@k8s-bot pull-kubernetes-federation-e2e-gce test this |
@k8s-bot test this [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue (batch tested with PRs 46620, 46732, 46773, 46772, 46725) |
@timstclair: 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/test-infra repository. I understand the commands that are listed here. |
eventCounter = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Subsystem: subsystem, | ||
Name: "event_count", |
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.
According to metric naming convention these should have the suffix total
instead of count
.
Automatic merge from submit-queue (batch tested with PRs 48106, 46761) s/count/total/ in audit prometheus metrics Responding to #46732 (comment), making the metric names conform with the [metric naming convention](https://prometheus.io/docs/practices/naming/#metric-names). kubernetes/enhancements#22 /cc @ericchiang @ihmccreery
) | ||
|
||
const ( | ||
subsystem = "apiserver_audit" |
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.
I'd say that the namespace should be "apiserver" and subsystem "audit". It doesn't have any impact on how the metric will eventually look like - just for sanity.
@brancz do you agree?
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.
Add prometheus metrics for audit logging, including:
For kubernetes/enhancements#22
HandlePluginError
from the webhook backend, once apiserver: add a webhook implementation of the audit backend #45919 merges (in this or a separate PR, depending on timing of the merge)/cc @ihmccreery @sttts @soltysh @ericchiang