Skip to content
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

Merged
merged 1 commit into from
Jun 3, 2017

Conversation

timstclair
Copy link

@timstclair timstclair commented May 31, 2017

Add prometheus metrics for audit logging, including:

  • A total count of audit events generated and sent to the output backend
  • A count of audit events that failed to be audited due to an error (per backend)
  • A count of request audit levels (1 per request)

For kubernetes/enhancements#22

/cc @ihmccreery @sttts @soltysh @ericchiang

@timstclair timstclair added the release-note-none Denotes a PR that doesn't merit a release note. label May 31, 2017
@timstclair timstclair added this to the v1.7 milestone May 31, 2017
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 31, 2017
@k8s-github-robot k8s-github-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 31, 2017

"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
auditinternal "k8s.io/apiserver/pkg/apis/audit"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: empty line above

Copy link
Author

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?

Copy link
Contributor

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",
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@sttts
Copy link
Contributor

sttts commented Jun 1, 2017

Looks good in general. Would like to see shared code for the glog error logging and the log backend.

@sttts
Copy link
Contributor

sttts commented Jun 1, 2017

^^ can be in a follow-up if the freeze becomes an issue. In that case, lgtm.

@sttts
Copy link
Contributor

sttts commented Jun 1, 2017

Squash, then lgtm

@timstclair
Copy link
Author

Squashed. Thanks!

@sttts
Copy link
Contributor

sttts commented Jun 1, 2017

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 1, 2017
@k8s-github-robot
Copy link

[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 /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 1, 2017
@timstclair
Copy link
Author

Rebased on #45919 and called HandlePluginError from the webhook backend.

@ericchiang Could you take a quick look?

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 1, 2017
@timstclair
Copy link
Author

Reapplying LGTM after rebase.

@timstclair timstclair added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 1, 2017
@ericchiang
Copy link
Contributor

lgtm

@timstclair
Copy link
Author

@k8s-bot pull-kubernetes-federation-e2e-gce test this

@timstclair
Copy link
Author

@k8s-bot pull-kubernetes-federation-e2e-gce test this

@fejta
Copy link
Contributor

fejta commented Jun 2, 2017

@k8s-bot pull-kubernetes-federation-e2e-gce test this
ref: #46827

@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 46620, 46732, 46773, 46772, 46725)

@k8s-github-robot k8s-github-robot merged commit 6b76c40 into kubernetes:master Jun 3, 2017
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jun 3, 2017

@timstclair: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-unit b77c819 link @k8s-bot pull-kubernetes-unit test this

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.

@piosz
Copy link
Member

piosz commented Jun 26, 2017

cc @brancz @fabxc

eventCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Subsystem: subsystem,
Name: "event_count",
Copy link
Member

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.

k8s-github-robot pushed a commit that referenced this pull request Jun 27, 2017
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"
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add whatever we decide to the instrumentation guide. (/cc @fabxc) Personally I think it's a good idea for easier consistency, but there have been previous discussions around this, but I don't remember the outcome. Maybe @fabxc remembers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants