Commit 81642e91 authored by Sean McGivern's avatar Sean McGivern

Rename rack attack log fields to be easier to find

`throttle_type` is now `matched`, as that's what it's called by rack
attack internally. It's now always logged, not just when a user is also
logged.

`username` is now `meta.user` to match the context logging in Rails,
Sidekiq, and Grape logs.
parent 5bdd3c1f
...@@ -11,7 +11,8 @@ ActiveSupport::Notifications.subscribe(/rack_attack/) do |name, start, finish, r ...@@ -11,7 +11,8 @@ ActiveSupport::Notifications.subscribe(/rack_attack/) do |name, start, finish, r
env: req.env['rack.attack.match_type'], env: req.env['rack.attack.match_type'],
remote_ip: req.ip, remote_ip: req.ip,
request_method: req.request_method, request_method: req.request_method,
path: req.fullpath path: req.fullpath,
matched: req.env['rack.attack.matched']
} }
throttles_with_user_information = [ throttles_with_user_information = [
...@@ -25,9 +26,8 @@ ActiveSupport::Notifications.subscribe(/rack_attack/) do |name, start, finish, r ...@@ -25,9 +26,8 @@ ActiveSupport::Notifications.subscribe(/rack_attack/) do |name, start, finish, r
user_id = req.env['rack.attack.match_discriminator'] user_id = req.env['rack.attack.match_discriminator']
user = User.find_by(id: user_id) user = User.find_by(id: user_id)
rack_attack_info[:throttle_type] = req.env['rack.attack.matched']
rack_attack_info[:user_id] = user_id rack_attack_info[:user_id] = user_id
rack_attack_info[:username] = user.username unless user.nil? rack_attack_info['meta.user'] = user.username unless user.nil?
end end
Gitlab::AuthLogger.error(rack_attack_info) Gitlab::AuthLogger.error(rack_attack_info)
......
...@@ -125,7 +125,8 @@ RSpec.describe 'Rack Attack global throttles' do ...@@ -125,7 +125,8 @@ RSpec.describe 'Rack Attack global throttles' do
env: :throttle, env: :throttle,
remote_ip: '127.0.0.1', remote_ip: '127.0.0.1',
request_method: 'GET', request_method: 'GET',
path: '/users/sign_in' path: '/users/sign_in',
matched: 'throttle_unauthenticated'
} }
expect(Gitlab::AuthLogger).to receive(:error).with(arguments) expect(Gitlab::AuthLogger).to receive(:error).with(arguments)
......
...@@ -93,8 +93,8 @@ RSpec.shared_examples 'rate-limited token-authenticated requests' do ...@@ -93,8 +93,8 @@ RSpec.shared_examples 'rate-limited token-authenticated requests' do
request_method: request_method, request_method: request_method,
path: request_args.first, path: request_args.first,
user_id: user.id, user_id: user.id,
username: user.username, 'meta.user' => user.username,
throttle_type: throttle_types[throttle_setting_prefix] matched: throttle_types[throttle_setting_prefix]
} }
expect(Gitlab::AuthLogger).to receive(:error).with(arguments).once expect(Gitlab::AuthLogger).to receive(:error).with(arguments).once
...@@ -222,8 +222,8 @@ RSpec.shared_examples 'rate-limited web authenticated requests' do ...@@ -222,8 +222,8 @@ RSpec.shared_examples 'rate-limited web authenticated requests' do
request_method: request_method, request_method: request_method,
path: url_that_requires_authentication, path: url_that_requires_authentication,
user_id: user.id, user_id: user.id,
username: user.username, 'meta.user' => user.username,
throttle_type: throttle_types[throttle_setting_prefix] matched: throttle_types[throttle_setting_prefix]
} }
expect(Gitlab::AuthLogger).to receive(:error).with(arguments).once expect(Gitlab::AuthLogger).to receive(:error).with(arguments).once
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment