tcell_agent 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/tcell_agent +10 -2
- data/lib/tcell_agent.rb +3 -3
- data/lib/tcell_agent/agent.rb +42 -52
- data/lib/tcell_agent/agent/event_processor.rb +129 -162
- data/lib/tcell_agent/agent/fork_pipe_manager.rb +57 -62
- data/lib/tcell_agent/agent/policy_manager.rb +83 -104
- data/lib/tcell_agent/agent/policy_types.rb +24 -29
- data/lib/tcell_agent/agent/route_manager.rb +36 -46
- data/lib/tcell_agent/agent/static_agent.rb +19 -21
- data/lib/tcell_agent/api.rb +23 -28
- data/lib/tcell_agent/appsensor/injections_reporter.rb +7 -11
- data/lib/tcell_agent/authlogic.rb +7 -7
- data/lib/tcell_agent/cmdi.rb +22 -23
- data/lib/tcell_agent/config/unknown_options.rb +71 -69
- data/lib/tcell_agent/configuration.rb +187 -191
- data/lib/tcell_agent/devise.rb +13 -15
- data/lib/tcell_agent/hooks/login_fraud.rb +1 -1
- data/lib/tcell_agent/instrumentation.rb +120 -124
- data/lib/tcell_agent/logger.rb +29 -45
- data/lib/tcell_agent/patches.rb +5 -5
- data/lib/tcell_agent/policies/dataloss_policy.rb +263 -288
- data/lib/tcell_agent/policies/http_redirect_policy.rb +25 -37
- data/lib/tcell_agent/policies/http_tx_policy.rb +48 -52
- data/lib/tcell_agent/policies/login_fraud_policy.rb +15 -20
- data/lib/tcell_agent/policies/policy.rb +0 -2
- data/lib/tcell_agent/policies/rust_policies.rb +24 -29
- data/lib/tcell_agent/rails.rb +2 -3
- data/lib/tcell_agent/rails/auth/authlogic.rb +2 -2
- data/lib/tcell_agent/rails/auth/devise.rb +2 -2
- data/lib/tcell_agent/rails/auth/doorkeeper.rb +2 -2
- data/lib/tcell_agent/rails/better_ip.rb +12 -16
- data/lib/tcell_agent/rails/csrf_exception.rb +4 -7
- data/lib/tcell_agent/rails/dlp.rb +208 -107
- data/lib/tcell_agent/rails/dlp/process_request.rb +37 -47
- data/lib/tcell_agent/rails/dlp_handler.rb +9 -11
- data/lib/tcell_agent/rails/js_agent_insert.rb +11 -14
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +8 -7
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +4 -5
- data/lib/tcell_agent/rails/middleware/global_middleware.rb +5 -8
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +24 -27
- data/lib/tcell_agent/rails/on_start.rb +5 -5
- data/lib/tcell_agent/rails/responses.rb +7 -9
- data/lib/tcell_agent/rails/routes.rb +62 -81
- data/lib/tcell_agent/rails/routes/grape.rb +25 -30
- data/lib/tcell_agent/rails/routes/route_id.rb +9 -14
- data/lib/tcell_agent/rails/settings_reporter.rb +44 -33
- data/lib/tcell_agent/rails/tcell_body_proxy.rb +15 -18
- data/lib/tcell_agent/routes/table.rb +31 -33
- data/lib/tcell_agent/rust/{libtcellagent-1.3.0.dylib → libtcellagent-1.3.1.dylib} +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-1.3.0.so → libtcellagent-1.3.1.so} +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-alpine-1.3.0.so → libtcellagent-alpine-1.3.1.so} +0 -0
- data/lib/tcell_agent/rust/models.rb +32 -37
- data/lib/tcell_agent/rust/tcellagent-1.3.1.dll +0 -0
- data/lib/tcell_agent/rust/whisperer.rb +101 -104
- data/lib/tcell_agent/sensor_events/app_config.rb +7 -7
- data/lib/tcell_agent/sensor_events/appsensor_event.rb +26 -27
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +20 -88
- data/lib/tcell_agent/sensor_events/command_injection.rb +52 -80
- data/lib/tcell_agent/sensor_events/discovery.rb +27 -27
- data/lib/tcell_agent/sensor_events/dlp.rb +50 -56
- data/lib/tcell_agent/sensor_events/honeytokens.rb +9 -9
- data/lib/tcell_agent/sensor_events/metrics.rb +20 -21
- data/lib/tcell_agent/sensor_events/patches.rb +10 -12
- data/lib/tcell_agent/sensor_events/sensor.rb +32 -36
- data/lib/tcell_agent/sensor_events/server_agent.rb +130 -127
- data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +60 -80
- data/lib/tcell_agent/sensor_events/util/utils.rb +3 -5
- data/lib/tcell_agent/servers/passenger.rb +5 -9
- data/lib/tcell_agent/servers/puma.rb +18 -27
- data/lib/tcell_agent/servers/rails_server.rb +5 -9
- data/lib/tcell_agent/servers/thin.rb +2 -4
- data/lib/tcell_agent/servers/unicorn.rb +18 -27
- data/lib/tcell_agent/servers/webrick.rb +2 -4
- data/lib/tcell_agent/settings_reporter.rb +126 -0
- data/lib/tcell_agent/sinatra.rb +24 -26
- data/lib/tcell_agent/start_background_thread.rb +21 -142
- data/lib/tcell_agent/system_info.rb +4 -3
- data/lib/tcell_agent/tcell_context.rb +150 -0
- data/lib/tcell_agent/userinfo.rb +3 -3
- data/lib/tcell_agent/utils/io.rb +19 -24
- data/lib/tcell_agent/utils/params.rb +9 -15
- data/lib/tcell_agent/utils/queue_with_timeout.rb +26 -32
- data/lib/tcell_agent/utils/strings.rb +4 -6
- data/lib/tcell_agent/version.rb +1 -1
- data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +5 -5
- data/spec/lib/tcell_agent/agent/static_agent_spec.rb +7 -7
- data/spec/lib/tcell_agent/cmdi_spec.rb +21 -21
- data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +29 -24
- data/spec/lib/tcell_agent/instrumentation_spec.rb +4 -4
- data/spec/lib/tcell_agent/patches_spec.rb +8 -8
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +23 -23
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +2 -2
- data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +69 -0
- data/spec/lib/tcell_agent/rails/dlp_spec.rb +1039 -0
- data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +271 -0
- data/spec/lib/tcell_agent/rails/logger_spec.rb +5 -5
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +3 -3
- data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +4 -4
- data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +5 -5
- data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +1 -1
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +11 -8
- data/spec/lib/tcell_agent/rails/responses_spec.rb +2 -2
- data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +2 -2
- data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +1 -1
- data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +4 -4
- data/spec/lib/tcell_agent/rust/models_spec.rb +83 -75
- data/spec/lib/tcell_agent/rust/whisperer_spec.rb +14 -14
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +19 -70
- data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +1 -1
- data/spec/lib/tcell_agent/settings_reporter_spec.rb +162 -0
- data/spec/lib/tcell_agent/tcell_context_spec.rb +154 -0
- data/spec/spec_helper.rb +5 -0
- metadata +18 -10
- data/lib/tcell_agent/appsensor/meta_data.rb +0 -132
- data/lib/tcell_agent/patches/meta_data.rb +0 -59
- data/lib/tcell_agent/rust/tcellagent-1.3.0.dll +0 -0
- data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +0 -71
data/lib/tcell_agent/devise.rb
CHANGED
@@ -11,25 +11,23 @@ module TCellAgent
|
|
11
11
|
if defined?(Devise)
|
12
12
|
TCellAgent::UserInformation.class_eval do
|
13
13
|
class << self
|
14
|
-
alias_method :
|
15
|
-
def
|
16
|
-
orig_user_id =
|
14
|
+
alias_method :original_get_user_from_request, :get_user_from_request
|
15
|
+
def get_user_from_request(request)
|
16
|
+
orig_user_id = original_get_user_from_request(request)
|
17
17
|
begin
|
18
|
-
if request.session && request.session.
|
19
|
-
userkey = request.session[
|
20
|
-
if
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
if user_id.is_a? Integer
|
26
|
-
return user_id.to_s
|
27
|
-
end
|
18
|
+
if request.session && request.session.key?('warden.user.user.key')
|
19
|
+
userkey = request.session['warden.user.user.key']
|
20
|
+
user_id = if userkey.length == 2
|
21
|
+
userkey[0][0]
|
22
|
+
else
|
23
|
+
userkey[1][0]
|
24
|
+
end
|
25
|
+
return user_id.to_s if user_id.is_a? Integer
|
28
26
|
end
|
29
|
-
rescue StandardError
|
27
|
+
rescue StandardError
|
30
28
|
return orig_user_id
|
31
29
|
end
|
32
|
-
|
30
|
+
orig_user_id
|
33
31
|
end
|
34
32
|
end
|
35
33
|
end
|
@@ -12,7 +12,7 @@ module TCellAgent
|
|
12
12
|
user_valid)
|
13
13
|
if TCellAgent.configuration.enabled &&
|
14
14
|
TCellAgent.configuration.should_intercept_requests?
|
15
|
-
login_fraud_policy = TCellAgent.policy(TCellAgent::PolicyTypes::
|
15
|
+
login_fraud_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
|
16
16
|
|
17
17
|
if login_fraud_policy && login_fraud_policy.enabled
|
18
18
|
if tcell_data
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# See the file "LICENSE" for the full license governing this code.
|
3
2
|
require 'tcell_agent/logger'
|
4
3
|
require 'tcell_agent/configuration'
|
@@ -8,7 +7,7 @@ require 'cgi'
|
|
8
7
|
|
9
8
|
module TCellAgent
|
10
9
|
module Instrumentation
|
11
|
-
TCELL_ID =
|
10
|
+
TCELL_ID = 'tcell.request_data'.freeze
|
12
11
|
|
13
12
|
class ContextFilter
|
14
13
|
attr_accessor :type
|
@@ -20,198 +19,199 @@ module TCellAgent
|
|
20
19
|
attr_accessor :table
|
21
20
|
attr_accessor :field
|
22
21
|
|
23
|
-
DATABASE =
|
24
|
-
REQUEST =
|
22
|
+
DATABASE = 'db'.freeze
|
23
|
+
REQUEST = 'request'.freeze
|
25
24
|
|
26
25
|
def for_request(context, parameter, rule)
|
27
26
|
self.type = ContextFilter::REQUEST
|
28
27
|
self.context = context
|
29
28
|
self.parameter = parameter
|
30
29
|
self.rule = rule
|
31
|
-
|
30
|
+
self
|
32
31
|
end
|
32
|
+
|
33
33
|
def create_hash_value
|
34
|
-
|
34
|
+
"#{type}#{context}#{parameter}#{database}#{schema}#{table}#{field}#{rule}".hash
|
35
35
|
end
|
36
|
-
|
37
|
-
|
36
|
+
|
37
|
+
def eql?(other)
|
38
|
+
hash == other.hash
|
38
39
|
end
|
40
|
+
|
39
41
|
def hash
|
40
|
-
|
42
|
+
create_hash_value
|
41
43
|
end
|
44
|
+
|
42
45
|
def for_database(database, schema, table, field, rule)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
self.type = ContextFilter::DATABASE
|
47
|
+
self.database = database
|
48
|
+
self.schema = schema
|
49
|
+
self.table = table
|
50
|
+
self.field = field
|
51
|
+
self.rule = rule
|
52
|
+
self
|
50
53
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
|
55
|
+
def for_request(context, parameter, rule) # rubocop:disable Lint/DuplicateMethods
|
56
|
+
self.type = ContextFilter::REQUEST
|
57
|
+
self.context = context
|
58
|
+
self.parameter = parameter
|
59
|
+
self.rule = rule
|
60
|
+
self
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
60
|
-
|
61
64
|
class TCellData
|
62
65
|
attr_accessor :transaction_id, :session_id, :hmac_session_id, :user_id,
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
66
|
+
:password, :route_id, :path, :uri, :fullpath, :context_filters_by_term,
|
67
|
+
:database_filters, :ip_address, :user_agent, :request_method,
|
68
|
+
:path_parameters, :patches_blocking_triggered, :grape_mount_endpoint,
|
69
|
+
:referrer, :csrf_exception_name, :sql_exceptions, :database_result_sizes
|
67
70
|
|
68
71
|
def self.filterx(sanitize_string, event_flag, replace_flag, term)
|
69
72
|
send_event = false
|
70
|
-
sanitize_string.gsub!(term)
|
73
|
+
sanitize_string.gsub!(term) do |m|
|
71
74
|
if replace_flag
|
72
|
-
m =
|
75
|
+
m = '[redacted]'
|
73
76
|
send_event = true
|
74
77
|
elsif event_flag
|
75
78
|
# m = "[hash]"
|
76
79
|
send_event = true
|
77
80
|
end
|
78
81
|
m
|
79
|
-
|
80
|
-
|
82
|
+
end
|
83
|
+
send_event
|
81
84
|
end
|
85
|
+
|
82
86
|
def initialize
|
83
87
|
@patches_blocking_triggered = false
|
84
|
-
@context_filters_by_term = Hash.new{|h,k| h[k] = Set.new}
|
88
|
+
@context_filters_by_term = Hash.new { |h, k| h[k] = Set.new }
|
85
89
|
@sql_exceptions = []
|
86
90
|
@database_result_sizes = []
|
87
91
|
end
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
return false
|
92
|
+
|
93
|
+
def valid_term?(term)
|
94
|
+
return true if !term.nil? && term != '' && term.to_s.length >= 5
|
95
|
+
false
|
93
96
|
end
|
97
|
+
|
94
98
|
def add_response_db_filter(term, action_obj, database, schema, table, field)
|
95
|
-
|
96
|
-
|
97
|
-
end
|
99
|
+
return unless valid_term?(term)
|
100
|
+
context_filters_by_term[term.to_s].add(ContextFilter.new.for_database(database, schema, table, field, action_obj))
|
98
101
|
end
|
102
|
+
|
99
103
|
def add_filter_for_request_parameter(term, rule, parameter_name)
|
100
|
-
|
101
|
-
|
102
|
-
end
|
104
|
+
return unless valid_term?(term)
|
105
|
+
context_filters_by_term[term.to_s].add(ContextFilter.new.for_request('form', parameter_name, rule))
|
103
106
|
end
|
107
|
+
|
104
108
|
def add_filter_for_header_value(term, rule, header_name)
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
+
return unless valid_term?(term)
|
110
|
+
context_filters_by_term[term.to_s].add(ContextFilter.new.for_request('header', header_name, rule))
|
111
|
+
end
|
112
|
+
|
109
113
|
def add_filter_for_cookie_value(term, rule, cookie_name)
|
110
|
-
|
111
|
-
|
112
|
-
end
|
114
|
+
return unless valid_term?(term)
|
115
|
+
context_filters_by_term[term.to_s].add(ContextFilter.new.for_request('cookie', cookie_name, rule))
|
113
116
|
end
|
114
117
|
|
115
118
|
def filter_body!(body)
|
116
|
-
dlp_policy = TCellAgent.policy(TCellAgent::PolicyTypes::
|
117
|
-
if dlp_policy &&
|
119
|
+
dlp_policy = TCellAgent.policy(TCellAgent::PolicyTypes::DATALOSS)
|
120
|
+
if dlp_policy && session_id
|
118
121
|
session_id_actions = dlp_policy.get_actions_for_session_id
|
119
122
|
if session_id_actions
|
120
|
-
send_flag = TCellData.filterx(body, session_id_actions.body_event, session_id_actions.body_redact,
|
123
|
+
send_flag = TCellData.filterx(body, session_id_actions.body_event, session_id_actions.body_redact, session_id)
|
121
124
|
if send_flag
|
122
125
|
TCellAgent.send_event(
|
123
126
|
TCellAgent::SensorEvents::DlpEvent.new(
|
124
|
-
|
125
|
-
|
127
|
+
route_id,
|
128
|
+
uri,
|
126
129
|
TCellAgent::SensorEvents::DlpEvent::FOUND_IN_BODY,
|
127
130
|
session_id_actions.action_id
|
128
|
-
|
131
|
+
).for_framework(TCellAgent::SensorEvents::DlpEvent::FRAMEWORK_VARIABLE_SESSION_ID)
|
129
132
|
)
|
130
133
|
|
131
134
|
end
|
132
135
|
end
|
133
136
|
end
|
134
|
-
|
135
|
-
replace_filters = (context_filters.select {|context_filter| context_filter.rule.body_redact == true })
|
136
|
-
event_filters = (context_filters.select {|context_filter| (context_filter.rule.body_redact != true && context_filter.rule.body_event == true) })
|
137
|
-
send_flag = TCellData.filterx(body, event_filters.
|
138
|
-
send_flag
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
137
|
+
context_filters_by_term.sort_by { |term, _context_filters| -term.length }.each do |term, context_filters|
|
138
|
+
replace_filters = (context_filters.select { |context_filter| context_filter.rule.body_redact == true })
|
139
|
+
event_filters = (context_filters.select { |context_filter| (context_filter.rule.body_redact != true && context_filter.rule.body_event == true) })
|
140
|
+
send_flag = TCellData.filterx(body, !event_filters.empty?, !replace_filters.empty?, term)
|
141
|
+
send_flag ||= TCellData.filterx(body, !event_filters.empty?, !replace_filters.empty?, CGI.escapeHTML(term))
|
142
|
+
next unless send_flag
|
143
|
+
(replace_filters + event_filters).each do |filter|
|
144
|
+
base_event = TCellAgent::SensorEvents::DlpEvent.new(
|
145
|
+
route_id,
|
146
|
+
uri,
|
147
|
+
TCellAgent::SensorEvents::DlpEvent::FOUND_IN_BODY,
|
148
|
+
filter.rule.action_id
|
149
|
+
)
|
150
|
+
if filter.type == ContextFilter::DATABASE
|
151
|
+
TCellAgent.send_event(
|
152
|
+
base_event.for_database(filter.database, filter.schema, filter.table, filter.field)
|
153
|
+
)
|
154
|
+
elsif filter.type == ContextFilter::REQUEST
|
155
|
+
TCellAgent.send_event(
|
156
|
+
base_event.for_request(filter.context, filter.parameter)
|
146
157
|
)
|
147
|
-
|
148
|
-
TCellAgent.send_event(
|
149
|
-
base_event.for_database(filter.database, filter.schema, filter.table, filter.field)
|
150
|
-
)
|
151
|
-
elsif filter.type == ContextFilter::REQUEST
|
152
|
-
TCellAgent.send_event(
|
153
|
-
base_event.for_request(filter.context, filter.parameter)
|
154
|
-
)
|
155
|
-
end
|
156
|
-
}
|
158
|
+
end
|
157
159
|
end
|
158
160
|
end
|
159
|
-
|
161
|
+
body
|
160
162
|
end
|
161
163
|
|
162
164
|
def filter_log(log_msg)
|
163
|
-
dlp_policy = TCellAgent.policy(TCellAgent::PolicyTypes::
|
164
|
-
if dlp_policy &&
|
165
|
+
dlp_policy = TCellAgent.policy(TCellAgent::PolicyTypes::DATALOSS)
|
166
|
+
if dlp_policy && session_id
|
165
167
|
session_id_actions = dlp_policy.get_actions_for_session_id
|
166
168
|
if session_id_actions
|
167
|
-
send_flag = TCellData.filterx(log_msg, session_id_actions.log_event, session_id_actions.log_redact,
|
169
|
+
send_flag = TCellData.filterx(log_msg, session_id_actions.log_event, session_id_actions.log_redact, session_id)
|
168
170
|
if send_flag
|
169
171
|
TCellAgent.send_event(
|
170
172
|
TCellAgent::SensorEvents::DlpEvent.new(
|
171
|
-
|
172
|
-
|
173
|
+
route_id,
|
174
|
+
uri,
|
173
175
|
TCellAgent::SensorEvents::DlpEvent::FOUND_IN_LOG,
|
174
176
|
session_id_actions.action_id
|
175
|
-
|
177
|
+
).for_framework(TCellAgent::SensorEvents::DlpEvent::FRAMEWORK_VARIABLE_SESSION_ID)
|
176
178
|
)
|
177
179
|
end
|
178
180
|
end
|
179
181
|
end
|
180
|
-
|
181
|
-
replace_filters = (context_filters.select {|context_filter| context_filter.rule.log_redact == true })
|
182
|
-
event_filters = (context_filters.select {|context_filter| (context_filter.rule.log_redact != true && context_filter.rule.log_event == true) })
|
183
|
-
send_flag = TCellData.filterx(log_msg, event_filters.
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
182
|
+
context_filters_by_term.sort_by { |term, _context_filters| -term.length }.each do |term, context_filters|
|
183
|
+
replace_filters = (context_filters.select { |context_filter| context_filter.rule.log_redact == true })
|
184
|
+
event_filters = (context_filters.select { |context_filter| (context_filter.rule.log_redact != true && context_filter.rule.log_event == true) })
|
185
|
+
send_flag = TCellData.filterx(log_msg, !event_filters.empty?, !replace_filters.empty?, term)
|
186
|
+
next unless send_flag
|
187
|
+
(replace_filters + event_filters).each do |filter|
|
188
|
+
base_event = TCellAgent::SensorEvents::DlpEvent.new(
|
189
|
+
route_id,
|
190
|
+
uri,
|
191
|
+
TCellAgent::SensorEvents::DlpEvent::FOUND_IN_LOG,
|
192
|
+
filter.rule.action_id
|
193
|
+
)
|
194
|
+
if filter.type == ContextFilter::DATABASE
|
195
|
+
TCellAgent.send_event(
|
196
|
+
base_event.for_database(filter.database, filter.schema, filter.table, filter.field)
|
191
197
|
)
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
TCellAgent.send_event(
|
198
|
-
base_event.for_request(filter.context, filter.parameter)
|
199
|
-
)
|
200
|
-
end
|
201
|
-
}
|
198
|
+
elsif filter.type == ContextFilter::REQUEST
|
199
|
+
TCellAgent.send_event(
|
200
|
+
base_event.for_request(filter.context, filter.parameter)
|
201
|
+
)
|
202
|
+
end
|
202
203
|
end
|
203
204
|
end
|
204
|
-
|
205
|
+
log_msg
|
205
206
|
end
|
206
207
|
|
207
208
|
def to_s
|
208
|
-
"<#{self.class.name} transaction_id: #{transaction_id} session_id: #{session_id} "
|
209
|
-
"hmac_session_id: #{hmac_session_id} user_id: #{user_id} route_id: #{route_id} "
|
210
|
-
"uri: #{uri} context_filters_by_term: #{context_filters_by_term} "
|
211
|
-
"database_filters: #{database_filters} ip_address: #{ip_address} user_agent: #{user_agent} "
|
209
|
+
"<#{self.class.name} transaction_id: #{transaction_id} session_id: #{session_id} " \
|
210
|
+
"hmac_session_id: #{hmac_session_id} user_id: #{user_id} route_id: #{route_id} " \
|
211
|
+
"uri: #{uri} context_filters_by_term: #{context_filters_by_term} " \
|
212
|
+
"database_filters: #{database_filters} ip_address: #{ip_address} user_agent: #{user_agent} " \
|
212
213
|
"request_method: #{@request_method} path_parameters: #{@path_parameters}>"
|
213
214
|
end
|
214
|
-
|
215
215
|
end
|
216
216
|
|
217
217
|
def self.instrument_frameworks
|
@@ -222,20 +222,16 @@ module TCellAgent
|
|
222
222
|
end
|
223
223
|
|
224
224
|
def self.safe_block(message, &block)
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
TCellAgent.logger.debug "Exception in safe_block #{message}: #{ex.class} happened, message is #{ex.message}"
|
230
|
-
TCellAgent.logger.debug(ex.backtrace)
|
231
|
-
end
|
225
|
+
block.call
|
226
|
+
rescue StandardError => ex
|
227
|
+
TCellAgent.logger.debug "Exception in safe_block #{message}: #{ex.class} happened, message is #{ex.message}"
|
228
|
+
TCellAgent.logger.debug(ex.backtrace)
|
232
229
|
end
|
233
230
|
|
234
|
-
def self.safe_block_no_log(
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
end
|
231
|
+
def self.safe_block_no_log(_message, &block)
|
232
|
+
block.call
|
233
|
+
rescue StandardError # rubocop:disable Lint/HandleExceptions
|
234
|
+
# do nothing
|
239
235
|
end
|
240
236
|
end
|
241
237
|
end
|
data/lib/tcell_agent/logger.rb
CHANGED
@@ -5,7 +5,6 @@ require 'tcell_agent/configuration'
|
|
5
5
|
require 'tcell_agent/utils/io'
|
6
6
|
|
7
7
|
module TCellAgent
|
8
|
-
|
9
8
|
class TaggedLogger
|
10
9
|
def initialize(tag, logger)
|
11
10
|
@tag = tag
|
@@ -38,11 +37,9 @@ module TCellAgent
|
|
38
37
|
end
|
39
38
|
|
40
39
|
class NullLoger < Logger
|
41
|
-
|
42
|
-
end
|
40
|
+
def initialize(*args); end
|
43
41
|
|
44
|
-
|
45
|
-
end
|
42
|
+
def add(*args, &block); end
|
46
43
|
end
|
47
44
|
|
48
45
|
class TCellLogDevice < Logger::LogDevice
|
@@ -58,26 +55,18 @@ module TCellAgent
|
|
58
55
|
@@logger_pid = Process.pid
|
59
56
|
@null_logger = TCellAgent::NullLoger.new
|
60
57
|
|
61
|
-
def self.
|
62
|
-
if
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
return Logger::INFO
|
68
|
-
elsif (levelString == "ERROR")
|
69
|
-
return Logger::ERROR
|
70
|
-
elsif (levelString == "FATAL")
|
71
|
-
return Logger::FATAL
|
72
|
-
end
|
58
|
+
def self.logging_level_from_string(level_string)
|
59
|
+
return Logger::DEBUG if level_string == 'DEBUG'
|
60
|
+
return Logger::WARN if level_string == 'WARN'
|
61
|
+
return Logger::INFO if level_string == 'INFO'
|
62
|
+
return Logger::ERROR if level_string == 'ERROR'
|
63
|
+
return Logger::FATAL if level_string == 'FATAL'
|
73
64
|
|
74
|
-
|
65
|
+
Logger::INFO
|
75
66
|
end
|
76
67
|
|
77
68
|
def self.appfirewall_payloads_logger
|
78
|
-
|
79
|
-
return @null_logger
|
80
|
-
end
|
69
|
+
return @null_logger unless TCellAgent.configuration.enabled
|
81
70
|
|
82
71
|
if defined?(@paylods_logger) && @logger_pid == Process.pid
|
83
72
|
return @payloads_logger
|
@@ -96,34 +85,30 @@ module TCellAgent
|
|
96
85
|
|
97
86
|
log_device = TCellLogDevice.new(
|
98
87
|
TCellAgent.configuration.appfirewall_payloads_log_filename,
|
99
|
-
:shift_age => 9, :shift_size =>
|
88
|
+
:shift_age => 9, :shift_size => 5_242_880
|
100
89
|
)
|
101
90
|
@payloads_logger = Logger.new(log_device)
|
102
91
|
@payloads_logger.level = Logger::INFO
|
103
|
-
@payloads_logger.formatter = proc do |
|
104
|
-
date_format = datetime.strftime(
|
105
|
-
|
92
|
+
@payloads_logger.formatter = proc do |_severity, datetime, _progname, msg|
|
93
|
+
date_format = datetime.strftime('%Y-%m-%dT%H:%M:%S.%L%:z')
|
94
|
+
"#{date_format} - #{msg}\n"
|
106
95
|
end
|
107
96
|
|
108
|
-
|
97
|
+
@payloads_logger
|
109
98
|
end
|
110
99
|
|
111
100
|
def self.logger
|
112
|
-
|
113
|
-
return @null_logger
|
114
|
-
end
|
101
|
+
return @null_logger unless TCellAgent.configuration.enabled
|
115
102
|
|
116
|
-
if defined?(@logger) && @logger_pid == Process.pid
|
117
|
-
return @logger
|
118
|
-
end
|
103
|
+
return @logger if defined?(@logger) && @logger_pid == Process.pid
|
119
104
|
|
120
105
|
if TCellAgent.configuration.logger
|
121
106
|
@logger_pid = Process.pid
|
122
|
-
if TCellAgent.configuration.log_tag
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
107
|
+
@logger = if TCellAgent.configuration.log_tag
|
108
|
+
TCellAgent::TaggedLogger.new(TCellAgent.configuration.log_tag, TCellAgent.configuration.logger)
|
109
|
+
else
|
110
|
+
TCellAgent.configuration.logger
|
111
|
+
end
|
127
112
|
|
128
113
|
return @logger
|
129
114
|
end
|
@@ -131,23 +116,23 @@ module TCellAgent
|
|
131
116
|
@logger_pid = Process.pid
|
132
117
|
logging_options = TCellAgent.configuration.logging_options || {}
|
133
118
|
|
134
|
-
use_default_setting = !logging_options.
|
119
|
+
use_default_setting = !logging_options.key?(:enabled) && !logging_options.key?('enabled')
|
135
120
|
|
136
|
-
if use_default_setting || logging_options[:enabled] || logging_options[
|
121
|
+
if use_default_setting || logging_options[:enabled] || logging_options['enabled']
|
137
122
|
logging_file = TCellAgent.configuration.log_filename
|
138
123
|
logging_directory = File.dirname(logging_file)
|
139
124
|
TCellAgent::Utils::IO.create_directory(logging_directory, TCellAgent.configuration.agent_home_owner.to_s)
|
140
125
|
|
141
|
-
log_device = TCellLogDevice.new(logging_file, :shift_age => 9, :shift_size =>
|
126
|
+
log_device = TCellLogDevice.new(logging_file, :shift_age => 9, :shift_size => 5_242_880)
|
142
127
|
|
143
|
-
level =
|
128
|
+
level = logging_level_from_string(logging_options[:level] || logging_options['level'])
|
144
129
|
# limit the total log file to about 9 * 5 = 45 mb
|
145
130
|
@logger = Logger.new(log_device)
|
146
131
|
@logger.level = level
|
147
|
-
@logger.formatter = proc do |severity, datetime,
|
132
|
+
@logger.formatter = proc do |severity, datetime, _progname, msg|
|
148
133
|
# ISO 8601 format
|
149
|
-
date_format = datetime.strftime(
|
150
|
-
|
134
|
+
date_format = datetime.strftime('%Y-%m-%dT%H:%M:%S.%L%:z')
|
135
|
+
"#{date_format} - [#{TCellAgent::VERSION}] - #{severity}[#{@logger_pid}]: #{msg}\n"
|
151
136
|
end
|
152
137
|
|
153
138
|
return @logger
|
@@ -162,5 +147,4 @@ module TCellAgent
|
|
162
147
|
def self.logger=(logger)
|
163
148
|
@logger = logger
|
164
149
|
end
|
165
|
-
|
166
150
|
end
|