Commit e632ae80 authored by Stan Hu's avatar Stan Hu Committed by Mayra Cabrera

Standardize remote_ip and path keys for auth.log and api_json.log

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
parent a493cccd
...@@ -41,9 +41,9 @@ module InvisibleCaptcha ...@@ -41,9 +41,9 @@ module InvisibleCaptcha
request_information = { request_information = {
message: message, message: message,
env: :invisible_captcha_signup_bot_detected, env: :invisible_captcha_signup_bot_detected,
ip: request.ip, remote_ip: request.ip,
request_method: request.request_method, request_method: request.request_method,
fullpath: request.fullpath path: request.fullpath
} }
Gitlab::AuthLogger.error(request_information) Gitlab::AuthLogger.error(request_information)
......
...@@ -7,9 +7,9 @@ ActiveSupport::Notifications.subscribe('rack.attack') do |name, start, finish, r ...@@ -7,9 +7,9 @@ ActiveSupport::Notifications.subscribe('rack.attack') do |name, start, finish, r
rack_attack_info = { rack_attack_info = {
message: 'Rack_Attack', message: 'Rack_Attack',
env: req.env['rack.attack.match_type'], env: req.env['rack.attack.match_type'],
ip: req.ip, remote_ip: req.ip,
request_method: req.request_method, request_method: req.request_method,
fullpath: req.fullpath path: req.fullpath
} }
if %w(throttle_authenticated_api throttle_authenticated_web).include? req.env['rack.attack.matched'] if %w(throttle_authenticated_api throttle_authenticated_web).include? req.env['rack.attack.matched']
......
...@@ -88,7 +88,7 @@ Introduced in GitLab 10.0, this file lives in ...@@ -88,7 +88,7 @@ Introduced in GitLab 10.0, this file lives in
It helps you see requests made directly to the API. For example: It helps you see requests made directly to the API. For example:
```json ```json
{"time":"2018-10-29T12:49:42.123Z","severity":"INFO","duration":709.08,"db":14.59,"view":694.49,"status":200,"method":"GET","path":"/api/v4/projects","params":[{"key":"action","value":"git-upload-pack"},{"key":"changes","value":"_any"},{"key":"key_id","value":"secret"},{"key":"secret_token","value":"[FILTERED]"}],"host":"localhost","ip":"::1","ua":"Ruby","route":"/api/:version/projects","user_id":1,"username":"root","queue_duration":100.31,"gitaly_calls":30,"gitaly_duration":5.36} {"time":"2018-10-29T12:49:42.123Z","severity":"INFO","duration":709.08,"db":14.59,"view":694.49,"status":200,"method":"GET","path":"/api/v4/projects","params":[{"key":"action","value":"git-upload-pack"},{"key":"changes","value":"_any"},{"key":"key_id","value":"secret"},{"key":"secret_token","value":"[FILTERED]"}],"host":"localhost","remote_ip":"::1","ua":"Ruby","route":"/api/:version/projects","user_id":1,"username":"root","queue_duration":100.31,"gitaly_calls":30,"gitaly_duration":5.36}
``` ```
This entry above shows an access to an internal endpoint to check whether an This entry above shows an access to an internal endpoint to check whether an
......
...@@ -18,7 +18,7 @@ module API ...@@ -18,7 +18,7 @@ module API
formatter: Gitlab::GrapeLogging::Formatters::LogrageWithTimestamp.new, formatter: Gitlab::GrapeLogging::Formatters::LogrageWithTimestamp.new,
include: [ include: [
GrapeLogging::Loggers::FilterParameters.new(LOG_FILTERS), GrapeLogging::Loggers::FilterParameters.new(LOG_FILTERS),
GrapeLogging::Loggers::ClientEnv.new, Gitlab::GrapeLogging::Loggers::ClientEnvLogger.new,
Gitlab::GrapeLogging::Loggers::RouteLogger.new, Gitlab::GrapeLogging::Loggers::RouteLogger.new,
Gitlab::GrapeLogging::Loggers::UserLogger.new, Gitlab::GrapeLogging::Loggers::UserLogger.new,
Gitlab::GrapeLogging::Loggers::QueueDurationLogger.new, Gitlab::GrapeLogging::Loggers::QueueDurationLogger.new,
......
...@@ -49,9 +49,9 @@ module Gitlab ...@@ -49,9 +49,9 @@ module Gitlab
request_information = { request_information = {
message: 'Action_Rate_Limiter_Request', message: 'Action_Rate_Limiter_Request',
env: type, env: type,
ip: request.ip, remote_ip: request.ip,
request_method: request.request_method, request_method: request.request_method,
fullpath: request.fullpath path: request.fullpath
} }
if current_user if current_user
......
# frozen_string_literal: true
# This is a fork of
# https://github.com/aserafin/grape_logging/blob/master/lib/grape_logging/loggers/client_env.rb
# to use remote_ip instead of ip.
module Gitlab
module GrapeLogging
module Loggers
class ClientEnvLogger < ::GrapeLogging::Loggers::Base
def parameters(request, _)
{ remote_ip: request.env["HTTP_X_FORWARDED_FOR"] || request.env["REMOTE_ADDR"], ua: request.env["HTTP_USER_AGENT"] }
end
end
end
end
end
...@@ -67,9 +67,9 @@ describe Projects::RawController do ...@@ -67,9 +67,9 @@ describe Projects::RawController do
attributes = { attributes = {
message: 'Action_Rate_Limiter_Request', message: 'Action_Rate_Limiter_Request',
env: :raw_blob_request_limit, env: :raw_blob_request_limit,
ip: '0.0.0.0', remote_ip: '0.0.0.0',
request_method: 'GET', request_method: 'GET',
fullpath: "/#{project.full_path}/raw/#{file_path}" path: "/#{project.full_path}/raw/#{file_path}"
} }
expect(Gitlab::AuthLogger).to receive(:error).with(attributes).once expect(Gitlab::AuthLogger).to receive(:error).with(attributes).once
......
...@@ -129,9 +129,9 @@ describe RegistrationsController do ...@@ -129,9 +129,9 @@ describe RegistrationsController do
{ {
message: auth_log_message, message: auth_log_message,
env: :invisible_captcha_signup_bot_detected, env: :invisible_captcha_signup_bot_detected,
ip: '0.0.0.0', remote_ip: '0.0.0.0',
request_method: 'POST', request_method: 'POST',
fullpath: '/users' path: '/users'
} }
end end
......
...@@ -74,9 +74,9 @@ describe Gitlab::ActionRateLimiter, :clean_gitlab_redis_cache do ...@@ -74,9 +74,9 @@ describe Gitlab::ActionRateLimiter, :clean_gitlab_redis_cache do
{ {
message: 'Action_Rate_Limiter_Request', message: 'Action_Rate_Limiter_Request',
env: type, env: type,
ip: '127.0.0.1', remote_ip: '127.0.0.1',
request_method: 'GET', request_method: 'GET',
fullpath: fullpath path: fullpath
} }
end end
......
...@@ -112,9 +112,9 @@ describe 'Rack Attack global throttles' do ...@@ -112,9 +112,9 @@ describe 'Rack Attack global throttles' do
arguments = { arguments = {
message: 'Rack_Attack', message: 'Rack_Attack',
env: :throttle, env: :throttle,
ip: '127.0.0.1', remote_ip: '127.0.0.1',
request_method: 'GET', request_method: 'GET',
fullpath: get_args.first, path: get_args.first,
user_id: user.id, user_id: user.id,
username: user.username username: user.username
} }
...@@ -213,9 +213,9 @@ describe 'Rack Attack global throttles' do ...@@ -213,9 +213,9 @@ describe 'Rack Attack global throttles' do
arguments = { arguments = {
message: 'Rack_Attack', message: 'Rack_Attack',
env: :throttle, env: :throttle,
ip: '127.0.0.1', remote_ip: '127.0.0.1',
request_method: 'GET', request_method: 'GET',
fullpath: '/users/sign_in' path: '/users/sign_in'
} }
expect(Gitlab::AuthLogger).to receive(:error).with(arguments) expect(Gitlab::AuthLogger).to receive(:error).with(arguments)
...@@ -377,9 +377,9 @@ describe 'Rack Attack global throttles' do ...@@ -377,9 +377,9 @@ describe 'Rack Attack global throttles' do
arguments = { arguments = {
message: 'Rack_Attack', message: 'Rack_Attack',
env: :throttle, env: :throttle,
ip: '127.0.0.1', remote_ip: '127.0.0.1',
request_method: 'GET', request_method: 'GET',
fullpath: '/dashboard/snippets', path: '/dashboard/snippets',
user_id: user.id, user_id: user.id,
username: user.username username: user.username
} }
......
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