e632ae8084
Current `auth.log` uses `fullpath` and `ip`, while `api_json.log` uses `remote_ip` and `path` for the same fields. Let's standardize these namings to make it easier for people working with the data. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/66167
25 lines
846 B
Ruby
25 lines
846 B
Ruby
# frozen_string_literal: true
|
|
#
|
|
# Adds logging for all Rack Attack blocks and throttling events.
|
|
|
|
ActiveSupport::Notifications.subscribe('rack.attack') do |name, start, finish, request_id, req|
|
|
if [:throttle, :blacklist].include? req.env['rack.attack.match_type']
|
|
rack_attack_info = {
|
|
message: 'Rack_Attack',
|
|
env: req.env['rack.attack.match_type'],
|
|
remote_ip: req.ip,
|
|
request_method: req.request_method,
|
|
path: req.fullpath
|
|
}
|
|
|
|
if %w(throttle_authenticated_api throttle_authenticated_web).include? req.env['rack.attack.matched']
|
|
user_id = req.env['rack.attack.match_discriminator']
|
|
user = User.find_by(id: user_id)
|
|
|
|
rack_attack_info[:user_id] = user_id
|
|
rack_attack_info[:username] = user.username unless user.nil?
|
|
end
|
|
|
|
Gitlab::AuthLogger.error(rack_attack_info)
|
|
end
|
|
end
|