tcell_agent 0.2.8 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tcell_agent/agent/event_processor.rb +14 -0
- data/lib/tcell_agent/agent/policy_manager.rb +48 -17
- data/lib/tcell_agent/configuration.rb +20 -7
- data/lib/tcell_agent/policies/http_redirect_policy.rb +2 -2
- data/lib/tcell_agent/rails.rb +0 -3
- data/lib/tcell_agent/rails/auth/authlogic.rb +46 -41
- data/lib/tcell_agent/rails/auth/devise.rb +45 -39
- data/lib/tcell_agent/rails/dlp.rb +126 -84
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +26 -25
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +13 -9
- data/lib/tcell_agent/rails/middleware/global_middleware.rb +24 -22
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +17 -12
- data/lib/tcell_agent/rails/on_start.rb +52 -48
- data/lib/tcell_agent/rails/routes.rb +74 -75
- data/lib/tcell_agent/sensor_events/sensor.rb +4 -1
- data/lib/tcell_agent/servers/thin.rb +1 -0
- data/lib/tcell_agent/servers/unicorn.rb +82 -6
- data/lib/tcell_agent/start_background_thread.rb +24 -19
- data/lib/tcell_agent/version.rb +1 -1
- data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +218 -0
- data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +2 -2
- data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +89 -0
- data/spec/spec_helper.rb +9 -0
- metadata +30 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffa24423fa841f2a9bdb3b19d44b1250ba2bc4ff
|
4
|
+
data.tar.gz: ae260430c31ff45f822cf49efd0735664a181a8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfd43837abf1c1ee7297c09d6960f1bb37673ad0b3dd805b93980bed531f216e57e54384f532e74f3c1f5d435564b177925070d0ab24354fc68dfc06122f0f18
|
7
|
+
data.tar.gz: 0b745e26beb71868ede7f5703a7292462d07c830a3374a0e2a98a3ddedb655695a7b2320a0bbf222926bd3bbeba7dc8462621cd52d465e3295e25a69d25a66e6
|
@@ -51,6 +51,13 @@ module TCellAgent
|
|
51
51
|
@event_processor_thread && @event_processor_thread.alive?
|
52
52
|
end
|
53
53
|
|
54
|
+
def stop_event_processor
|
55
|
+
TCellAgent.logger.debug("Stopping event processor thread")
|
56
|
+
if @event_processor_thread && @event_processor_thread.alive?
|
57
|
+
@event_processor_thread.exit
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
54
61
|
def start_event_processor(send_empties=true)
|
55
62
|
return if TCellAgent.configuration.should_start_event_manager? == false
|
56
63
|
|
@@ -247,6 +254,13 @@ module TCellAgent
|
|
247
254
|
@start_metrics_event_thread && @start_metrics_event_thread.alive?
|
248
255
|
end
|
249
256
|
|
257
|
+
def stop_metrics_event_thread
|
258
|
+
TCellAgent.logger.debug("Stopping metrics event thread")
|
259
|
+
if @start_metrics_event_thread && @start_metrics_event_thread.alive?
|
260
|
+
@start_metrics_event_thread.exit
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
250
264
|
def start_metrics_event_thread
|
251
265
|
return if TCellAgent.configuration.should_consume_event? == false
|
252
266
|
@metrics_event_thread = Thread.new do
|
@@ -42,6 +42,13 @@ module TCellAgent
|
|
42
42
|
@policy_polling_thread && @policy_polling_thread.alive?
|
43
43
|
end
|
44
44
|
|
45
|
+
def stop_policy_polling
|
46
|
+
TCellAgent.logger.debug("Stopping policy polling thread")
|
47
|
+
if @policy_polling_thread && @policy_polling_thread.alive?
|
48
|
+
@policy_polling_thread.exit
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
45
52
|
def start_policy_polling
|
46
53
|
if TCellAgent.configuration.should_start_policy_poll? == true
|
47
54
|
TCellAgent.logger.debug("Starting policy polling thread")
|
@@ -89,7 +96,7 @@ module TCellAgent
|
|
89
96
|
|
90
97
|
if policy_jsons.key?("data")
|
91
98
|
policy_data = policy_jsons["data"]
|
92
|
-
end
|
99
|
+
end
|
93
100
|
|
94
101
|
TCellAgent::PolicyTypes::ClassMap.each do | policy_type, policy_class |
|
95
102
|
if (policy_jsons.key?(policy_type))
|
@@ -108,42 +115,66 @@ module TCellAgent
|
|
108
115
|
end # end of processPolicyJson
|
109
116
|
|
110
117
|
def cache(policy_name, policy)
|
111
|
-
cache_filename = TCellAgent.configuration.
|
112
|
-
|
113
|
-
if TCellAgent.configuration.app_id
|
114
|
-
cache_filename = cache_filename + '.' + TCellAgent.configuration.app_id
|
115
|
-
end
|
116
|
-
policy_cache = policies_from_cachefile()
|
117
|
-
if !policy_cache
|
118
|
-
policy_cache = {}
|
119
|
-
end
|
120
|
-
policy_cache[policy_name] = policy
|
118
|
+
cache_filename = TCellAgent.configuration.cache_filename_with_app_id
|
119
|
+
|
121
120
|
begin
|
122
|
-
|
121
|
+
|
122
|
+
FileUtils.mkdir_p(File.dirname(cache_filename))
|
123
|
+
f1 = open(cache_filename, File::RDWR|File::CREAT)
|
124
|
+
|
125
|
+
Timeout::timeout(0.100) { f1.flock(File::LOCK_EX) }
|
126
|
+
|
127
|
+
policy_cache = {}
|
128
|
+
existing_policy = f1.read
|
129
|
+
|
130
|
+
if !existing_policy.nil? && existing_policy != ""
|
131
|
+
policy_jsons = JSON.parse(existing_policy)
|
132
|
+
if policy_jsons
|
133
|
+
if policy_jsons.key?("result")
|
134
|
+
policy_cache = policy_jsons["result"]
|
135
|
+
else
|
136
|
+
policy_cache = policy_jsons
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
policy_cache[policy_name] = policy
|
141
|
+
|
142
|
+
f1.rewind
|
143
|
+
f1.puts( JSON.dump(policy_cache) )
|
144
|
+
|
123
145
|
rescue Exception => e
|
124
146
|
TCellAgent.logger.error(e.message)
|
147
|
+
|
148
|
+
ensure
|
149
|
+
f1.close unless f1.nil?
|
125
150
|
end
|
151
|
+
|
126
152
|
end
|
127
153
|
|
128
154
|
def policies_from_cachefile
|
129
|
-
cache_filename = TCellAgent.configuration.
|
130
|
-
if TCellAgent.configuration.app_id
|
131
|
-
cache_filename = cache_filename + '.' + TCellAgent.configuration.app_id
|
132
|
-
end
|
155
|
+
cache_filename = TCellAgent.configuration.cache_filename_with_app_id
|
133
156
|
cache_exists = File.exist?(cache_filename)
|
157
|
+
|
134
158
|
if !cache_exists
|
135
159
|
return nil
|
136
160
|
end
|
161
|
+
|
137
162
|
begin
|
138
|
-
|
163
|
+
f1 = File.open(cache_filename, File::RDONLY)
|
164
|
+
Timeout::timeout(1) { f1.flock( File::LOCK_SH ) }
|
165
|
+
policy_filedata = f1.read
|
166
|
+
f1.close
|
167
|
+
|
139
168
|
policy_jsons = JSON.parse(policy_filedata)
|
140
169
|
if policy_jsons.key?("result")
|
141
170
|
return policy_jsons["result"]
|
142
171
|
end
|
143
172
|
return policy_jsons
|
173
|
+
|
144
174
|
rescue Exception => e
|
145
175
|
TCellAgent.logger.error(e.message)
|
146
176
|
end
|
177
|
+
|
147
178
|
return nil
|
148
179
|
end
|
149
180
|
|
@@ -95,11 +95,14 @@ module TCellAgent
|
|
95
95
|
@js_agent_api_base_url ||= nil
|
96
96
|
@js_agent_url ||= "https://api.tcell.io/tcellagent.min.js"
|
97
97
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
98
|
+
if (@host_identifier == nil)
|
99
|
+
begin
|
100
|
+
@host_identifier = (Socket.gethostname() || "localhost")
|
101
|
+
rescue Exception
|
102
|
+
@host_identifier = "host_identifier_not_found"
|
103
|
+
end
|
102
104
|
end
|
105
|
+
|
103
106
|
@uuid = SecureRandom.uuid
|
104
107
|
|
105
108
|
FileUtils::mkdir_p File.dirname(@cache_filename)
|
@@ -110,10 +113,19 @@ module TCellAgent
|
|
110
113
|
end
|
111
114
|
end
|
112
115
|
|
116
|
+
def cache_filename_with_app_id
|
117
|
+
if @app_id
|
118
|
+
"#{@cache_filename}.#{@app_id}"
|
119
|
+
else
|
120
|
+
@cache_filename
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
113
124
|
def read_config_using_env
|
114
|
-
@app_id = ENV["
|
115
|
-
@api_key = ENV["
|
125
|
+
@app_id = ENV["TCELL_AGENT_APP_ID"]
|
126
|
+
@api_key = ENV["TCELL_AGENT_API_KEY"]
|
116
127
|
@hmac_key = ENV["TCELL_HMAC_KEY"]
|
128
|
+
@host_identifier = ENV["TCELL_AGENT_HOST_IDENTIFIER"] || @host_identifier
|
117
129
|
@tcell_api_url = ENV["TCELL_API_URL"]
|
118
130
|
@tcell_input_url = ENV["TCELL_INPUT_URL"]
|
119
131
|
@demomode = ENV["TCELL_DEMOMODE"] || @demomode
|
@@ -163,7 +175,8 @@ module TCellAgent
|
|
163
175
|
@proxy_password = app_data["proxy_password"]
|
164
176
|
|
165
177
|
@use_websockets = app_data["use_websockets"]
|
166
|
-
|
178
|
+
|
179
|
+
@host_identifier = @host_identifier || app_data.fetch("host_identifier", @host_identifier)
|
167
180
|
if (@host_identifier == nil)
|
168
181
|
@host_identifier = (Socket.gethostname() || "localhost")
|
169
182
|
end
|
@@ -41,7 +41,7 @@ module TCellAgent
|
|
41
41
|
end
|
42
42
|
return true
|
43
43
|
end
|
44
|
-
def enforce(target_url, current_host, current_path, method, status_code, remote_addr)
|
44
|
+
def enforce(target_url, current_host, current_path, method, route_id, status_code, remote_addr, session_id=nil)
|
45
45
|
if @enabled == false
|
46
46
|
return nil
|
47
47
|
end
|
@@ -51,7 +51,7 @@ module TCellAgent
|
|
51
51
|
return nil
|
52
52
|
end
|
53
53
|
begin
|
54
|
-
event = TCellAgent::SensorEvents::TCellRedirectSensorEvent.new(host, current_host, current_path, method, status_code, remote_addr)
|
54
|
+
event = TCellAgent::SensorEvents::TCellRedirectSensorEvent.new(host, current_host, current_path, method, route_id, status_code, remote_addr, session_id, nil)
|
55
55
|
TCellAgent.send_event(event)
|
56
56
|
rescue Exception => ie
|
57
57
|
TCellAgent.logger.error("uncaught exception while creating redirect event: #{ie.message}")
|
data/lib/tcell_agent/rails.rb
CHANGED
@@ -18,7 +18,6 @@ require 'tcell_agent/rails/middleware/context_middleware'
|
|
18
18
|
require 'tcell_agent/rails/settings_reporter'
|
19
19
|
require 'tcell_agent/rails/dlp'
|
20
20
|
|
21
|
-
require 'rails/all'
|
22
21
|
|
23
22
|
require 'tcell_agent/userinfo'
|
24
23
|
require 'cgi'
|
@@ -27,7 +26,6 @@ require 'thread'
|
|
27
26
|
module TCellAgent
|
28
27
|
class Railtie < Rails::Railtie
|
29
28
|
initializer "tcell_agent.insert_middleware" do |app|
|
30
|
-
if TCellAgent.configuration.should_intercept_requests?
|
31
29
|
app.config.to_prepare do
|
32
30
|
require 'tcell_agent/devise' if defined?(Devise)
|
33
31
|
require 'tcell_agent/rails/auth/devise' if defined?(Devise)
|
@@ -38,7 +36,6 @@ module TCellAgent
|
|
38
36
|
app.config.middleware.insert_after(0, "TCellAgent::Instrumentation::Rails::Middleware::HeadersMiddleware")
|
39
37
|
app.config.middleware.use "TCellAgent::Instrumentation::Rails::Middleware::BodyFilterMiddleware"
|
40
38
|
app.config.middleware.use "TCellAgent::Instrumentation::Rails::Middleware::GlobalMiddleware"
|
41
|
-
end
|
42
39
|
end
|
43
40
|
end
|
44
41
|
end
|
@@ -5,48 +5,53 @@ require 'tcell_agent/configuration'
|
|
5
5
|
require 'tcell_agent/instrumentation'
|
6
6
|
|
7
7
|
module TCellAgent
|
8
|
-
|
8
|
+
if defined?(Authlogic)
|
9
|
+
TCellAgent.logger.debug("Instrumenting Authlogic")
|
10
|
+
require 'tcell_agent/agent'
|
11
|
+
require 'tcell_agent/sensor_events/login_fraud'
|
12
|
+
Authlogic::Session::Base.class_eval do
|
13
|
+
alias_method :original_save, :save
|
14
|
+
def save(&block)
|
9
15
|
if (TCellAgent.configuration.enabled && TCellAgent.configuration.should_intercept_requests?)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
alias_method :original_save, :save
|
15
|
-
def save(&block)
|
16
|
-
user_logged_in_before = (user != nil)
|
17
|
-
success = original_save
|
18
|
-
user_logged_in_after = (user != nil)
|
19
|
-
TCellAgent::Instrumentation.safe_block("Authlogic login info") {
|
16
|
+
user_logged_in_before = (user != nil)
|
17
|
+
success = original_save
|
18
|
+
user_logged_in_after = (user != nil)
|
19
|
+
TCellAgent::Instrumentation.safe_block("Authlogic login info") {
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
47
|
-
}
|
21
|
+
login_fraud_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LoginFraud)
|
22
|
+
if (login_fraud_policy && login_fraud_policy.enabled)
|
23
|
+
user_id = nil
|
24
|
+
TCellAgent::Instrumentation.safe_block("getting userid for login form") {
|
25
|
+
user_id = self.send(self.class.login_field.to_sym)
|
26
|
+
}
|
27
|
+
if (user_logged_in_before && user_logged_in_after)
|
28
|
+
#password changed or logged in as another user
|
29
|
+
elsif (!user_logged_in_before && !user_logged_in_after)
|
30
|
+
if (login_fraud_policy.login_failed_enabled)
|
31
|
+
request = Authlogic::Session::Base.controller.request
|
32
|
+
response = Authlogic::Session::Base.controller.response
|
33
|
+
hmac_session_id = request.env["tcell.request_data"].hmac_session_id
|
34
|
+
event = TCellAgent::SensorEvents::LoginFailure.new(request, response, user_id, hmac_session_id)
|
35
|
+
TCellAgent.send_event(event)
|
36
|
+
end
|
37
|
+
elsif (!user_logged_in_before && user_logged_in_after)
|
38
|
+
if (login_fraud_policy.login_success_enabled)
|
39
|
+
request = Authlogic::Session::Base.controller.request
|
40
|
+
response = Authlogic::Session::Base.controller.response
|
41
|
+
hmac_session_id = request.env["tcell.request_data"].hmac_session_id
|
42
|
+
event = TCellAgent::SensorEvents::LoginSuccess.new(request, response, user_id, hmac_session_id)
|
43
|
+
TCellAgent.send_event(event)
|
44
|
+
end
|
48
45
|
end
|
49
|
-
end
|
46
|
+
end
|
47
|
+
}
|
48
|
+
|
49
|
+
success
|
50
|
+
|
51
|
+
else
|
52
|
+
original_save
|
50
53
|
end # if instrument
|
51
|
-
|
52
|
-
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end # if Authlogic
|
57
|
+
end
|
@@ -1,24 +1,26 @@
|
|
1
1
|
module TCellAgent
|
2
2
|
if defined?(Devise)
|
3
|
-
if (TCellAgent.configuration.enabled && TCellAgent.configuration.should_intercept_requests?)
|
4
|
-
TCellAgent.logger.debug("Instrumenting Devise")
|
5
3
|
|
6
|
-
|
7
|
-
require 'tcell_agent/sensor_events/login_fraud'
|
8
|
-
require 'tcell_agent/sensor_events/app_sensor'
|
9
|
-
require 'tcell_agent/policies/appsensor_policy'
|
4
|
+
TCellAgent.logger.debug("Instrumenting Devise")
|
10
5
|
|
11
|
-
|
6
|
+
require 'tcell_agent/agent'
|
7
|
+
require 'tcell_agent/sensor_events/login_fraud'
|
8
|
+
require 'tcell_agent/sensor_events/app_sensor'
|
9
|
+
require 'tcell_agent/policies/appsensor_policy'
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
Devise::SessionsController.class_eval do
|
12
|
+
|
13
|
+
after_filter :log_failed_login, :only => :new
|
14
|
+
alias_method :original_new, :new
|
15
|
+
def new
|
16
|
+
original_new
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method :original_create, :create
|
20
|
+
def create(&block)
|
21
|
+
results = original_create(&block)
|
18
22
|
|
19
|
-
|
20
|
-
def create(&block)
|
21
|
-
results = original_create(&block)
|
23
|
+
if (TCellAgent.configuration.enabled && TCellAgent.configuration.should_intercept_requests?)
|
22
24
|
TCellAgent::Instrumentation.safe_block("Devise login successful") {
|
23
25
|
tcell_username = _get_tcell_username
|
24
26
|
login_fraud_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LoginFraud)
|
@@ -27,30 +29,33 @@ module TCellAgent
|
|
27
29
|
request.env["tcell.request_data"].user_id = TCellAgent::UserInformation.getUserFromRequest(request)
|
28
30
|
user_id = tcell_username || request.env["tcell.request_data"].user_id
|
29
31
|
event = TCellAgent::SensorEvents::LoginSuccess.new(request, response, user_id, hmac_session_id)
|
30
|
-
TCellAgent.send_event(event)
|
32
|
+
TCellAgent.send_event(event)
|
31
33
|
end
|
32
34
|
}
|
33
|
-
results
|
34
35
|
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
37
|
+
results
|
38
|
+
end
|
39
|
+
|
40
|
+
def _get_tcell_username
|
41
|
+
_tcell_username = nil
|
42
|
+
TCellAgent::Instrumentation.safe_block("devise login - get username") {
|
43
|
+
keys = resource_class.authentication_keys.dup
|
44
|
+
user_params = request.POST.fetch("user",{})
|
45
|
+
keys.each do |key|
|
46
|
+
next_usename = user_params.fetch(key, nil)
|
47
|
+
if next_usename
|
48
|
+
_tcell_username ||= ""
|
49
|
+
_tcell_username += next_usename
|
47
50
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
+
end
|
52
|
+
}
|
53
|
+
_tcell_username
|
54
|
+
end
|
51
55
|
|
52
|
-
|
53
|
-
|
56
|
+
private
|
57
|
+
def log_failed_login
|
58
|
+
if (TCellAgent.configuration.enabled && TCellAgent.configuration.should_intercept_requests?)
|
54
59
|
TCellAgent::Instrumentation.safe_block("Devise login failed") {
|
55
60
|
tcell_username = _get_tcell_username
|
56
61
|
login_fraud_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LoginFraud)
|
@@ -78,12 +83,13 @@ module TCellAgent
|
|
78
83
|
TCellAgent.send_event(event)
|
79
84
|
end
|
80
85
|
}
|
81
|
-
end
|
86
|
+
end
|
87
|
+
end
|
82
88
|
|
83
|
-
|
84
|
-
|
85
|
-
end
|
89
|
+
def failed_login?
|
90
|
+
(options = env["warden.options"]) && options[:action] == "unauthenticated"
|
86
91
|
end
|
87
|
-
end
|
92
|
+
end
|
93
|
+
|
88
94
|
end #if defined devise
|
89
|
-
end
|
95
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'tcell_agent/authlogic' if defined?(Authlogic)
|
4
4
|
require 'tcell_agent/devise' if defined?(Devise)
|
5
|
-
|
5
|
+
|
6
6
|
require 'rails'
|
7
7
|
require 'uri'
|
8
8
|
require 'tcell_agent/logger'
|
@@ -22,9 +22,6 @@ require 'tcell_agent/rails/middleware/context_middleware'
|
|
22
22
|
|
23
23
|
require 'tcell_agent/rails/routes'
|
24
24
|
require 'tcell_agent/rails/settings_reporter'
|
25
|
-
require 'tcell_agent/rails/dlp'
|
26
|
-
|
27
|
-
require 'rails/all'
|
28
25
|
|
29
26
|
require 'tcell_agent/userinfo'
|
30
27
|
require 'cgi'
|
@@ -53,55 +50,82 @@ require 'thread'
|
|
53
50
|
|
54
51
|
require 'tcell_agent/configuration'
|
55
52
|
|
56
|
-
if TCellAgent.configuration.enabled && TCellAgent.configuration.should_instrument? && TCellAgent.configuration.should_intercept_requests?
|
57
53
|
|
54
|
+
|
55
|
+
module TCellAgent
|
56
|
+
class MyRailtie < Rails::Railtie
|
57
|
+
initializer 'activeservice.autoload', :after => :set_autoload_paths do |app|
|
58
|
+
def database_exists?
|
59
|
+
database_yaml = "#{Rails.root}/config/database.yml"
|
60
|
+
File.exists?database_yaml
|
61
|
+
end
|
62
|
+
|
63
|
+
if (database_exists?)
|
58
64
|
class ActiveRecord::Base
|
59
65
|
# after_initialize do |user|
|
60
66
|
# puts "You have initialized an object!"
|
61
67
|
# puts "ASDF"
|
62
68
|
# end
|
63
69
|
after_find do |record|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
70
|
+
if TCellAgent.configuration.enabled &&
|
71
|
+
TCellAgent.configuration.should_instrument? &&
|
72
|
+
TCellAgent.configuration.should_intercept_requests?
|
73
|
+
|
74
|
+
database_name = self.class.connection_config().fetch(:database,"*").split('/').last
|
75
|
+
dlp_policy = TCellAgent.policy(TCellAgent::PolicyTypes::DataLoss)
|
76
|
+
if dlp_policy
|
77
|
+
request_env = TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS.fetch(Thread.current.object_id, nil)
|
78
|
+
if request_env
|
79
|
+
tcell_context = request_env[TCellAgent::Instrumentation::Rails::Middleware::TCELL_ID]
|
80
|
+
if tcell_context
|
81
|
+
model = record.class
|
82
|
+
column_names = model.columns.map { |col| col.name }
|
83
|
+
if (dlp_policy.database_discovery_enabled)
|
84
|
+
TCellAgent.discover_database_fields(tcell_context.route_id, database_name,"*",model.table_name, column_names)
|
85
|
+
end
|
86
|
+
model.columns.each do |col|
|
87
|
+
#puts "#{model.table_name} .. #{col.name}"
|
88
|
+
action_objs = dlp_policy.get_actions_for_table(database_name, "*", model.table_name, col.name, tcell_context.route_id)
|
89
|
+
if action_objs
|
90
|
+
action_objs.each do |action_obj|
|
91
|
+
tcell_context.add_response_db_filter(record[col.name.to_sym], action_obj, database_name, "*", model.table_name, col.name)
|
92
|
+
end
|
82
93
|
end
|
83
94
|
end
|
84
95
|
end
|
85
96
|
end
|
86
|
-
end
|
97
|
+
end # /if dlp_policy
|
98
|
+
end # /enabled
|
99
|
+
end # /after_find
|
100
|
+
end # /class
|
101
|
+
end
|
102
|
+
|
87
103
|
end
|
88
104
|
end
|
89
105
|
end
|
90
106
|
|
91
|
-
# - Request
|
92
|
-
# - Session Id event
|
93
|
-
# - Session Id redact
|
94
|
-
# - Session Id hash
|
95
|
-
# - Session Id mask
|
96
|
-
# - Database-Stuff - [event, redact]
|
97
|
-
#
|
98
|
-
# - Log
|
99
|
-
#
|
100
107
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
# - Request
|
112
|
+
# - Session Id event
|
113
|
+
# - Session Id redact
|
114
|
+
# - Session Id hash
|
115
|
+
# - Session Id mask
|
116
|
+
# - Database-Stuff - [event, redact]
|
117
|
+
#
|
118
|
+
# - Log
|
119
|
+
#
|
120
|
+
|
121
|
+
module TCellAgent
|
122
|
+
module Policies
|
123
|
+
class DataLossPolicy
|
124
|
+
|
125
|
+
def log_enforce(tcell_context, sanitize_string)
|
126
|
+
if TCellAgent.configuration.enabled &&
|
127
|
+
TCellAgent.configuration.should_instrument? &&
|
128
|
+
TCellAgent.configuration.should_intercept_requests? &&
|
105
129
|
if (tcell_context && tcell_context.session_id)
|
106
130
|
session_id_actions = self.get_actions_for_session_id
|
107
131
|
if session_id_actions
|
@@ -121,17 +145,23 @@ if TCellAgent.configuration.enabled && TCellAgent.configuration.should_instrumen
|
|
121
145
|
if send_event
|
122
146
|
TCellAgent.send_event(
|
123
147
|
TCellAgent::SensorEvents::DlpEvent.new(
|
124
|
-
tcell_context.route_id,
|
125
|
-
tcell_context.uri,
|
148
|
+
tcell_context.route_id,
|
149
|
+
tcell_context.uri,
|
126
150
|
TCellAgent::SensorEvents::DlpEvent::FOUND_IN_LOG
|
127
151
|
).for_framework(TCellAgent::SensorEvents::DlpEvent::FRAMEWORK_VARIABLE_SESSION_ID)
|
128
152
|
)
|
129
153
|
end
|
130
154
|
end
|
131
155
|
end
|
132
|
-
sanitize_string
|
133
156
|
end
|
134
|
-
|
157
|
+
|
158
|
+
sanitize_string
|
159
|
+
end
|
160
|
+
|
161
|
+
def response_body_enforce(tcell_context, sanitize_string)
|
162
|
+
if TCellAgent.configuration.enabled &&
|
163
|
+
TCellAgent.configuration.should_instrument? &&
|
164
|
+
TCellAgent.configuration.should_intercept_requests? &&
|
135
165
|
if (tcell_context && tcell_context.session_id)
|
136
166
|
session_id_actions = self.get_actions_for_session_id
|
137
167
|
if session_id_actions
|
@@ -152,67 +182,79 @@ if TCellAgent.configuration.enabled && TCellAgent.configuration.should_instrumen
|
|
152
182
|
if send_event
|
153
183
|
TCellAgent.send_event(
|
154
184
|
TCellAgent::SensorEvents::DlpEvent.new(
|
155
|
-
tcell_context.route_id,
|
156
|
-
tcell_context.uri,
|
185
|
+
tcell_context.route_id,
|
186
|
+
tcell_context.uri,
|
157
187
|
TCellAgent::SensorEvents::DlpEvent::FOUND_IN_BODY
|
158
188
|
).for_framework(TCellAgent::SensorEvents::DlpEvent::FRAMEWORK_VARIABLE_SESSION_ID)
|
159
189
|
)
|
160
190
|
end
|
161
191
|
end
|
162
|
-
sanitize_string
|
163
192
|
end
|
193
|
+
|
194
|
+
sanitize_string
|
164
195
|
end
|
165
196
|
end
|
166
197
|
end
|
198
|
+
end
|
199
|
+
|
200
|
+
module TCellAgent
|
201
|
+
ActiveSupport.on_load(:action_controller) do
|
202
|
+
ActionController::Base.class_eval do
|
203
|
+
around_filter :global_request_logging
|
204
|
+
def global_request_logging
|
205
|
+
begin
|
206
|
+
|
207
|
+
yield
|
208
|
+
|
209
|
+
if TCellAgent.configuration.enabled &&
|
210
|
+
TCellAgent.configuration.should_instrument? &&
|
211
|
+
TCellAgent.configuration.should_intercept_requests?
|
212
|
+
|
213
|
+
TCellAgent::Instrumentation.safe_block("Running DLP Logging Filters") {
|
214
|
+
tcell_context = request.env[TCellAgent::Instrumentation::Rails::Middleware::TCELL_ID]
|
215
|
+
if tcell_context
|
216
|
+
response.body = tcell_context.filter_body(response.body)
|
217
|
+
end
|
218
|
+
}
|
167
219
|
|
168
|
-
module TCellAgent
|
169
|
-
ActiveSupport.on_load(:action_controller) do
|
170
|
-
ActionController::Base.class_eval do
|
171
|
-
around_filter :global_request_logging
|
172
|
-
def global_request_logging
|
173
|
-
begin
|
174
|
-
yield
|
175
|
-
TCellAgent::Instrumentation.safe_block("Running DLP Logging Filters") {
|
176
|
-
tcell_context = request.env[TCellAgent::Instrumentation::Rails::Middleware::TCELL_ID]
|
177
|
-
if tcell_context
|
178
|
-
response.body = tcell_context.filter_body(response.body)
|
179
|
-
end
|
180
|
-
}
|
181
|
-
end
|
182
220
|
end
|
183
221
|
end
|
184
222
|
end
|
223
|
+
end
|
185
224
|
end
|
225
|
+
end
|
186
226
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
227
|
+
|
228
|
+
class Logger
|
229
|
+
alias_method :tcell_old_add, :add
|
230
|
+
def add(severity, message = nil, progname = nil, &block)
|
231
|
+
if TCellAgent.configuration.enabled &&
|
232
|
+
TCellAgent.configuration.should_instrument? &&
|
233
|
+
TCellAgent.configuration.should_intercept_requests? &&
|
234
|
+
severity >= self.level
|
235
|
+
|
236
|
+
progname ||= @progname
|
237
|
+
if message.nil?
|
238
|
+
if block_given?
|
239
|
+
message = yield
|
240
|
+
else
|
241
|
+
message = progname
|
242
|
+
progname = @progname
|
202
243
|
end
|
244
|
+
end
|
203
245
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
end
|
246
|
+
TCellAgent::Instrumentation.safe_block_no_log("Handling JSAgent add") {
|
247
|
+
dlp_policy = TCellAgent.policy(TCellAgent::PolicyTypes::DataLoss)
|
248
|
+
request_env = TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS.fetch(Thread.current.object_id, nil)
|
249
|
+
if message && dlp_policy && request_env
|
250
|
+
tcell_context = request_env[TCellAgent::Instrumentation::Rails::Middleware::TCELL_ID]
|
251
|
+
if tcell_context
|
252
|
+
tcell_context.filter_log(message)
|
212
253
|
end
|
213
|
-
|
214
|
-
|
215
|
-
end
|
254
|
+
end
|
255
|
+
}
|
216
256
|
end
|
257
|
+
|
258
|
+
tcell_old_add(severity, message, progname)
|
217
259
|
end
|
218
260
|
end
|