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

Add Prometheus metrics for authentication attempts #15794

Merged
merged 1 commit into from
Sep 20, 2017

Conversation

mrogers950
Copy link
Contributor

@openshift/sig-security

@openshift-merge-robot openshift-merge-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 16, 2017
@stevekuznetsov
Copy link
Contributor

/unassign
/assign @smarterclayton @deads2k

}

func UpdateAuthCounters(user, path, result string) {
authCounterTotal.WithLabelValues().Inc()
Copy link
Contributor

Choose a reason for hiding this comment

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

The cardinality of metrics that are labeled by username are going to be really high. What's the lifetime of these metrics?

Subsystem: AuthSubsystem,
Name: "auth_count_user_path",
Help: "Counts total authentication attempts, by user and request path",
}, []string{"user", "path"},
Copy link
Contributor

Choose a reason for hiding this comment

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

cardinality of this is too high. Either use api request info and bucket by resource and verb, or get rid of this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Basically we cannot have any unbounded cardinality metrics (like path) in the system.

@mrogers950
Copy link
Contributor Author

I removed the high cardinality label metrics.

user, ok, err := l.auth.AuthenticatePassword(username, password)
if err != nil {
glog.Errorf(`Error authenticating %q with provider %q: %v`, username, l.provider, err)
failed(errorpage.AuthenticationErrorCode(err), w, req)
result = "failure"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably distinguish this result as "error"

@mrogers950 mrogers950 force-pushed the auth_prom branch 2 times, most recently from ecf26d4 to d0ef2a3 Compare August 17, 2017 18:07
@mrogers950
Copy link
Contributor Author

@liggitt @smarterclayton lmk if there are any other changes needed.

@mrogers950 mrogers950 requested a review from enj August 30, 2017 14:00
@wanghaoran1988
Copy link
Member

@liggitt @mfojtik @smarterclayton Could you please take a look at this, this is adressing a 3.7 commited card.

@@ -0,0 +1,36 @@
package prometheus
Copy link
Contributor

Choose a reason for hiding this comment

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

Call this package "metrics", we have no plans to support an alternate metrics sysem

)

const (
AuthSubsystem = "auth_subsystem"
Copy link
Contributor

Choose a reason for hiding this comment

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

Private unless there is another reason.

Use "openshift_auth" to better describe (subsystem is redundant in public metrics

prometheus.MustRegister(authCounterResult)
}

func UpdateAuthCounters(result string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally we don't abstract metrics recording like this. Call this method "record"

Signed-off-by: Matt Rogers <mrogers@redhat.com>
@mrogers950
Copy link
Contributor Author

@smarterclayton updated, and rebased.

@mrogers950
Copy link
Contributor Author

/retest

1 similar comment
@mrogers950
Copy link
Contributor Author

/retest

@mrogers950
Copy link
Contributor Author

mrogers950 commented Sep 19, 2017

flake #15900

@mrogers950
Copy link
Contributor Author

/retest

@mrogers950
Copy link
Contributor Author

/test all

@mrogers950
Copy link
Contributor Author

flake #16273

@mrogers950
Copy link
Contributor Author

/retest

user, ok, err := l.auth.AuthenticatePassword(username, password)
if err != nil {
glog.Errorf(`Error authenticating %q with provider %q: %v`, username, l.provider, err)
failed(errorpage.AuthenticationErrorCode(err), w, req)
result = "error"
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 prefer the result be a constant

Copy link
Contributor

Choose a reason for hiding this comment

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

Generally we don't create constants for single use variables.

var result string
defer func() {
metrics.Record(result)
}()
user, ok, err := l.auth.AuthenticatePassword(username, password)
if err != nil {
glog.Errorf(`Error authenticating %q with provider %q: %v`, username, l.provider, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Note, this should be utilruntime.HandleError(...), not glog.Errorf().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opened a separate PR for that.

@smarterclayton
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 20, 2017
@openshift-merge-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mrogers950, smarterclayton

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

@openshift-merge-robot openshift-merge-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 20, 2017
@openshift-merge-robot
Copy link
Contributor

Automatic merge from submit-queue (batch tested with PRs 16411, 16139, 16430, 16435, 15794)

openshift-merge-robot added a commit that referenced this pull request Sep 20, 2017
Automatic merge from submit-queue (batch tested with PRs 16411, 16139, 16430, 16435, 15794)

Add Prometheus metrics for authentication attempts

@openshift/sig-security
@openshift-merge-robot openshift-merge-robot merged commit 6f4cfdb into openshift:master Sep 20, 2017
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. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants