2018-07-17 12:50:04 +00:00
|
|
|
module Gitlab
|
|
|
|
module Auth
|
|
|
|
##
|
|
|
|
# Metrics and logging for user authentication activity.
|
|
|
|
#
|
|
|
|
class Activity
|
|
|
|
extend Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
COUNTERS = {
|
|
|
|
user_authenticated: 'Counter of total successful authentication events',
|
|
|
|
user_unauthenticated: 'Counter of total authentication failures',
|
|
|
|
user_not_found: 'Counter of total failed log-ins when user is unknown',
|
|
|
|
user_password_invalid: 'Counter of failed log-ins with invalid password',
|
|
|
|
user_session_fetched: 'Counter of total sessions fetched',
|
|
|
|
user_session_override: 'Counter of manual log-ins and sessions overrides',
|
|
|
|
user_signed_out: 'Counter of total user sign out events'
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
def initialize(opts)
|
|
|
|
@opts = opts
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_authentication_failed!
|
|
|
|
self.class.user_unauthenticated_counter.increment
|
|
|
|
|
|
|
|
case @opts[:message]
|
|
|
|
when :not_found_in_database
|
|
|
|
self.class.user_not_found_counter.increment
|
|
|
|
when :invalid
|
|
|
|
self.class.user_password_invalid_counter.increment
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_authenticated!
|
|
|
|
self.class.user_authenticated_counter.increment
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_session_fetched!
|
|
|
|
self.class.user_session_fetched_counter.increment
|
|
|
|
end
|
|
|
|
|
2018-07-19 08:34:58 +00:00
|
|
|
def user_session_override!
|
2018-07-17 12:50:04 +00:00
|
|
|
self.class.user_session_override_counter.increment
|
|
|
|
end
|
|
|
|
|
2018-07-19 08:34:58 +00:00
|
|
|
def user_signed_out!
|
2018-07-17 12:50:04 +00:00
|
|
|
self.class.user_signed_out_counter.increment
|
|
|
|
end
|
|
|
|
|
|
|
|
COUNTERS.each_pair do |metric, description|
|
|
|
|
define_singleton_method("#{metric}_counter") do
|
|
|
|
strong_memoize(metric) do
|
2018-07-19 08:34:58 +00:00
|
|
|
Gitlab::Metrics.counter("gitlab_auth_#{metric}_total".to_sym, description)
|
2018-07-17 12:50:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|