summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorMayra Cabrera <mcabrera@gitlab.com>2019-07-02 19:48:06 +0000
committerStan Hu <stanhu@gmail.com>2019-07-02 19:48:06 +0000
commitfc85b07a27a5e1cc77105235562e7be151a266a8 (patch)
tree02ba2b2a4934c5f71baa8fa3e902f991c1413483 /config
parent851d19c26023cb977eb29157bc833daab985ba77 (diff)
downloadgitlab-ce-fc85b07a27a5e1cc77105235562e7be151a266a8.tar.gz
Include user id and username in auth log
Fetches user based on the value of 'rack.attack.match_discriminator' Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/62756
Diffstat (limited to 'config')
-rw-r--r--config/initializers/rack_attack_logging.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/config/initializers/rack_attack_logging.rb b/config/initializers/rack_attack_logging.rb
index 2a3fdc8de5f..338e968cc6c 100644
--- a/config/initializers/rack_attack_logging.rb
+++ b/config/initializers/rack_attack_logging.rb
@@ -4,12 +4,22 @@
ActiveSupport::Notifications.subscribe('rack.attack') do |name, start, finish, request_id, req|
if [:throttle, :blacklist].include? req.env['rack.attack.match_type']
- Gitlab::AuthLogger.error(
+ rack_attack_info = {
message: 'Rack_Attack',
env: req.env['rack.attack.match_type'],
ip: req.ip,
request_method: req.request_method,
fullpath: req.fullpath
- )
+ }
+
+ if req.env['rack.attack.matched'] != 'throttle_unauthenticated'
+ 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