tcell_agent 2.1.2 → 2.4.1

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.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +2 -2
  3. data/bin/tcell_agent +41 -150
  4. data/lib/tcell_agent.rb +8 -16
  5. data/lib/tcell_agent/agent.rb +87 -52
  6. data/lib/tcell_agent/config_initializer.rb +62 -0
  7. data/lib/tcell_agent/configuration.rb +72 -267
  8. data/lib/tcell_agent/hooks/login_fraud.rb +1 -1
  9. data/lib/tcell_agent/instrument_servers.rb +14 -18
  10. data/lib/tcell_agent/instrumentation.rb +14 -6
  11. data/lib/tcell_agent/instrumentation/cmdi.rb +32 -0
  12. data/lib/tcell_agent/instrumentation/lfi.rb +55 -9
  13. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_2/file.rb +21 -0
  14. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_2/io.rb +75 -0
  15. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_2/kernel.rb +80 -0
  16. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_3/file.rb +21 -0
  17. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_3/io.rb +75 -0
  18. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_3/kernel.rb +80 -0
  19. data/lib/tcell_agent/logger.rb +3 -4
  20. data/lib/tcell_agent/policies/dataloss_policy.rb +15 -8
  21. data/lib/tcell_agent/policies/headers_policy.rb +2 -2
  22. data/lib/tcell_agent/policies/patches_policy.rb +8 -4
  23. data/lib/tcell_agent/policies/policies_manager.rb +1 -0
  24. data/lib/tcell_agent/policies/policy_polling.rb +4 -3
  25. data/lib/tcell_agent/rails/auth/authlogic.rb +49 -44
  26. data/lib/tcell_agent/rails/auth/authlogic_helper.rb +20 -0
  27. data/lib/tcell_agent/rails/auth/devise.rb +103 -102
  28. data/lib/tcell_agent/rails/auth/devise_helper.rb +29 -0
  29. data/lib/tcell_agent/rails/auth/doorkeeper.rb +54 -57
  30. data/lib/tcell_agent/{userinfo.rb → rails/auth/userinfo.rb} +0 -0
  31. data/lib/tcell_agent/rails/better_ip.rb +7 -19
  32. data/lib/tcell_agent/rails/csrf_exception.rb +0 -8
  33. data/lib/tcell_agent/rails/dlp.rb +48 -52
  34. data/lib/tcell_agent/rails/dlp/process_request.rb +5 -0
  35. data/lib/tcell_agent/rails/dlp_handler.rb +9 -10
  36. data/lib/tcell_agent/rails/js_agent_insert.rb +2 -3
  37. data/lib/tcell_agent/rails/middleware/context_middleware.rb +2 -1
  38. data/lib/tcell_agent/rails/middleware/global_middleware.rb +3 -4
  39. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +1 -0
  40. data/lib/tcell_agent/rails/{on_start.rb → railties/tcell_agent_railties.rb} +9 -16
  41. data/lib/tcell_agent/rails/railties/tcell_agent_unicorn_railties.rb +8 -0
  42. data/lib/tcell_agent/rails/routes.rb +3 -6
  43. data/lib/tcell_agent/rails/routes/grape.rb +3 -4
  44. data/lib/tcell_agent/rails/settings_reporter.rb +3 -6
  45. data/lib/tcell_agent/rails/tcell_body_proxy.rb +4 -7
  46. data/lib/tcell_agent/routes/table.rb +3 -0
  47. data/lib/tcell_agent/rust/agent_config.rb +59 -33
  48. data/lib/tcell_agent/rust/{libtcellagent-4.18.0.so → libtcellagent-alpine.so} +0 -0
  49. data/lib/tcell_agent/rust/libtcellagent-x64.dll +0 -0
  50. data/lib/tcell_agent/rust/{libtcellagent-4.18.0.dylib → libtcellagent.dylib} +0 -0
  51. data/lib/tcell_agent/rust/{libtcellagent-alpine-4.18.0.so → libtcellagent.so} +0 -0
  52. data/lib/tcell_agent/rust/models.rb +9 -0
  53. data/lib/tcell_agent/rust/native_agent.rb +58 -50
  54. data/lib/tcell_agent/rust/native_library.rb +8 -10
  55. data/lib/tcell_agent/sensor_events/server_agent.rb +3 -100
  56. data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +1 -0
  57. data/lib/tcell_agent/servers/puma.rb +30 -13
  58. data/lib/tcell_agent/servers/rack_puma_handler.rb +33 -0
  59. data/lib/tcell_agent/servers/rails_server.rb +4 -4
  60. data/lib/tcell_agent/servers/unicorn.rb +1 -1
  61. data/lib/tcell_agent/servers/webrick.rb +12 -3
  62. data/lib/tcell_agent/settings_reporter.rb +0 -93
  63. data/lib/tcell_agent/sinatra.rb +1 -0
  64. data/lib/tcell_agent/tcell_context.rb +16 -7
  65. data/lib/tcell_agent/utils/headers.rb +0 -1
  66. data/lib/tcell_agent/utils/strings.rb +2 -2
  67. data/lib/tcell_agent/version.rb +1 -1
  68. data/spec/cruby_spec_helper.rb +26 -0
  69. data/spec/lib/tcell_agent/configuration_spec.rb +62 -212
  70. data/spec/lib/tcell_agent/instrument_servers_spec.rb +95 -0
  71. data/spec/lib/tcell_agent/instrumentation/cmdi/io_cmdi_spec.rb +2 -2
  72. data/spec/lib/tcell_agent/instrumentation/lfi/file_lfi_spec.rb +211 -272
  73. data/spec/lib/tcell_agent/instrumentation/lfi/io_lfi_spec.rb +207 -223
  74. data/spec/lib/tcell_agent/instrumentation/lfi/kernel_lfi_spec.rb +89 -70
  75. data/spec/lib/tcell_agent/instrumentation/lfi_spec.rb +73 -0
  76. data/spec/lib/tcell_agent/patches_spec.rb +2 -1
  77. data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +1 -2
  78. data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +5 -6
  79. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +21 -2
  80. data/spec/lib/tcell_agent/policies/policies_manager_spec.rb +1 -1
  81. data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +14 -8
  82. data/spec/lib/tcell_agent/rails/better_ip_spec.rb +9 -11
  83. data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +6 -6
  84. data/spec/lib/tcell_agent/rails/dlp_spec.rb +1 -0
  85. data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +10 -2
  86. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +2 -1
  87. data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +4 -4
  88. data/spec/lib/tcell_agent/rust/agent_config_spec.rb +27 -0
  89. data/spec/lib/tcell_agent/settings_reporter_spec.rb +2 -89
  90. data/spec/lib/tcell_agent/tcell_context_spec.rb +6 -5
  91. data/spec/spec_helper.rb +9 -1
  92. data/spec/support/builders.rb +8 -7
  93. data/spec/support/server_mocks/passenger_mock.rb +7 -0
  94. data/spec/support/server_mocks/puma_mock.rb +21 -0
  95. data/spec/support/server_mocks/rails_mock.rb +7 -0
  96. data/spec/support/server_mocks/thin_mock.rb +7 -0
  97. data/spec/support/server_mocks/unicorn_mock.rb +11 -0
  98. data/spec/support/shared_spec.rb +29 -0
  99. data/tcell_agent.gemspec +14 -14
  100. metadata +44 -27
  101. data/Rakefile +0 -18
  102. data/lib/tcell_agent/authlogic.rb +0 -23
  103. data/lib/tcell_agent/config/unknown_options.rb +0 -119
  104. data/lib/tcell_agent/devise.rb +0 -33
  105. data/lib/tcell_agent/instrumentation/monkey_patches/file.rb +0 -25
  106. data/lib/tcell_agent/instrumentation/monkey_patches/io.rb +0 -131
  107. data/lib/tcell_agent/instrumentation/monkey_patches/kernel.rb +0 -102
  108. data/lib/tcell_agent/rails/start_agent_after_initializers.rb +0 -12
  109. data/lib/tcell_agent/rust/tcellagent-4.18.0.dll +0 -0
  110. data/spec/lib/tcell_agent/config/unknown_options_spec.rb +0 -195
@@ -3,7 +3,7 @@ require 'tcell_agent/agent'
3
3
  module TCellAgent
4
4
  module Hooks
5
5
  module LoginFraud
6
- # Note: mock out in tests
6
+ # NOTE: mock out in tests
7
7
  def self.get_logger
8
8
  unless defined?(@login_fraud_logger)
9
9
  @login_fraud_logger = TCellAgent::ModuleLogger.new(TCellAgent.logger, name)
@@ -1,25 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  tcell_server = ENV['TCELL_AGENT_SERVER']
2
4
 
3
- if TCellAgent.configuration.should_instrument?
4
- unless tcell_server && tcell_server == 'mock'
5
- if (tcell_server && tcell_server == 'webrick') || defined?(Rails::Server)
6
- require('tcell_agent/servers/rails_server')
5
+ TCellAgent.thread_agent.instrument_built_ins if tcell_server &&
6
+ tcell_server == 'mock'
7
7
 
8
- elsif (tcell_server && tcell_server == 'thin') || defined?(Thin)
9
- require('tcell_agent/servers/thin')
8
+ require('tcell_agent/servers/rails_server') if (tcell_server && tcell_server == 'webrick') ||
9
+ defined?(Rails::Server)
10
10
 
11
- elsif (tcell_server && tcell_server == 'puma') || defined?(Puma)
12
- require('tcell_agent/servers/puma')
11
+ require('tcell_agent/servers/thin') if (tcell_server && tcell_server == 'thin') ||
12
+ defined?(Thin)
13
13
 
14
- elsif (tcell_server && tcell_server == 'unicorn') || defined?(Unicorn)
15
- require('tcell_agent/servers/unicorn')
14
+ require('tcell_agent/servers/puma') if (tcell_server && tcell_server == 'puma') ||
15
+ defined?(Puma)
16
16
 
17
- elsif (tcell_server && tcell_server == 'passenger') || defined?(PhusionPassenger)
18
- require('tcell_agent/servers/passenger')
19
- end
20
- end
17
+ require('tcell_agent/servers/unicorn') if (tcell_server && tcell_server == 'unicorn') ||
18
+ defined?(Unicorn)
21
19
 
22
- elsif (tcell_server && tcell_server == 'unicorn') || defined?(Unicorn)
23
- # unicorn is always instrumented to support rolling restarts
24
- require('tcell_agent/servers/unicorn')
25
- end
20
+ require('tcell_agent/servers/passenger') if (tcell_server && tcell_server == 'passenger') ||
21
+ defined?(PhusionPassenger)
@@ -65,7 +65,8 @@ module TCellAgent
65
65
  :password, :route_id, :path, :uri, :fullpath, :context_filters_by_term,
66
66
  :database_filters, :remote_address, :user_agent, :request_method,
67
67
  :path_parameters, :patches_blocking_triggered, :grape_mount_endpoint,
68
- :referrer, :csrf_exception_name, :sql_exceptions, :database_result_sizes
68
+ :referrer, :csrf_exception_name, :sql_exceptions, :database_result_sizes,
69
+ :reverse_proxy_header_value
69
70
 
70
71
  def self.filterx(sanitize_string, event_flag, replace_flag, term)
71
72
  send_event = false
@@ -91,26 +92,31 @@ module TCellAgent
91
92
 
92
93
  def valid_term?(term)
93
94
  return true if !term.nil? && term != '' && term.to_s.length >= 5
95
+
94
96
  false
95
97
  end
96
98
 
97
99
  def add_response_db_filter(term, action_obj, database, schema, table, field)
98
100
  return unless valid_term?(term)
101
+
99
102
  context_filters_by_term[term.to_s].add(ContextFilter.new.for_database(database, schema, table, field, action_obj))
100
103
  end
101
104
 
102
105
  def add_filter_for_request_parameter(term, rule, parameter_name)
103
106
  return unless valid_term?(term)
107
+
104
108
  context_filters_by_term[term.to_s].add(ContextFilter.new.for_request('form', parameter_name, rule))
105
109
  end
106
110
 
107
111
  def add_filter_for_header_value(term, rule, header_name)
108
112
  return unless valid_term?(term)
113
+
109
114
  context_filters_by_term[term.to_s].add(ContextFilter.new.for_request('header', header_name, rule))
110
115
  end
111
116
 
112
117
  def add_filter_for_cookie_value(term, rule, cookie_name)
113
118
  return unless valid_term?(term)
119
+
114
120
  context_filters_by_term[term.to_s].add(ContextFilter.new.for_request('cookie', cookie_name, rule))
115
121
  end
116
122
 
@@ -139,6 +145,7 @@ module TCellAgent
139
145
  send_flag = TCellData.filterx(body, !event_filters.empty?, !replace_filters.empty?, term)
140
146
  send_flag ||= TCellData.filterx(body, !event_filters.empty?, !replace_filters.empty?, CGI.escapeHTML(term))
141
147
  next unless send_flag
148
+
142
149
  (replace_filters + event_filters).each do |filter|
143
150
  base_event = TCellAgent::SensorEvents::DlpEvent.new(
144
151
  route_id,
@@ -183,6 +190,7 @@ module TCellAgent
183
190
  event_filters = (context_filters.select { |context_filter| (context_filter.rule.log_redact != true && context_filter.rule.log_event == true) })
184
191
  send_flag = TCellData.filterx(log_msg, !event_filters.empty?, !replace_filters.empty?, term)
185
192
  next unless send_flag
193
+
186
194
  (replace_filters + event_filters).each do |filter|
187
195
  base_event = TCellAgent::SensorEvents::DlpEvent.new(
188
196
  route_id,
@@ -213,7 +221,7 @@ module TCellAgent
213
221
  end
214
222
  end
215
223
 
216
- # Note: mock for tests
224
+ # NOTE: mock for tests
217
225
  def self.get_safe_block_logger
218
226
  unless defined?(@safe_block_logger)
219
227
  @safe_block_logger = TCellAgent::ModuleLogger.new(TCellAgent.logger, name)
@@ -224,15 +232,15 @@ module TCellAgent
224
232
 
225
233
  def self.safe_block(message, &block)
226
234
  block.call
227
- rescue StandardError => ex
235
+ rescue StandardError => e
228
236
  logger = get_safe_block_logger
229
- logger.error("Error #{message} (#{ex.class}): #{ex.message}")
230
- logger.exception(ex)
237
+ logger.error("Error #{message} (#{e.class}): #{e.message}")
238
+ logger.exception(e)
231
239
  end
232
240
 
233
241
  def self.safe_block_no_log(_message, &block)
234
242
  block.call
235
- rescue StandardError # rubocop:disable Lint/HandleExceptions
243
+ rescue StandardError
236
244
  # do nothing
237
245
  end
238
246
  end
@@ -56,5 +56,37 @@ module TCellAgent
56
56
 
57
57
  cmd
58
58
  end
59
+
60
+ def self.raise_if_block(cmd)
61
+ return unless TCellAgent::Cmdi.block_command?(cmd)
62
+
63
+ raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
64
+ end
65
+
66
+ def self.default_cmdi_handler(args)
67
+ cmd = TCellAgent::Cmdi.parse_command(*args)
68
+
69
+ raise_if_block(cmd)
70
+ end
71
+
72
+ def self.popen_cmdi_handler(args)
73
+ return if args.empty?
74
+
75
+ cmd = ''
76
+
77
+ TCellAgent::Instrumentation.safe_block('CMDI Parsing popen *args') do
78
+ args_copy = Array.new(args)
79
+ args_copy.shift if args_copy.first.is_a?(Hash)
80
+ args_copy.pop if args_copy.last.is_a?(Hash)
81
+
82
+ cmd = if args_copy.first.is_a?(String)
83
+ args_copy.shift
84
+ else
85
+ TCellAgent::Cmdi.parse_command(*args_copy.shift)
86
+ end
87
+ end
88
+
89
+ raise_if_block(cmd)
90
+ end
59
91
  end
60
92
  end
@@ -5,6 +5,8 @@ require 'tcell_agent/configuration'
5
5
  module TCellAgent
6
6
  module Instrumentation
7
7
  module Lfi
8
+ extend TCellAgent::ModuleLoggerAccess
9
+
8
10
  def self.block_file_access?(path, mode)
9
11
  TCellAgent::Instrumentation.safe_block('Checking Local Files Policy') do
10
12
  if TCellAgent::Utils::Strings.present?(path)
@@ -54,17 +56,27 @@ module TCellAgent
54
56
  mode = 'Read'
55
57
 
56
58
  TCellAgent::Instrumentation.safe_block('LFI Parsing ARGF') do
57
- if ARGF.eof? && !ARGV.empty?
58
- argv_copy = Array.new(ARGV)
59
- path = argv_copy.shift
60
- else
61
- path = ARGF.filename
62
- end
59
+ begin
60
+ return ['', ''] if ARGF.file == $stdin
63
61
 
64
- if path && path.to_s[0] != '|'
65
- [File.expand_path(path.to_s), mode]
66
- else
62
+ if ARGF.eof? && !ARGV.empty?
63
+ argv_copy = Array.new(ARGV)
64
+ path = argv_copy.shift
65
+ else
66
+ path = ARGF.filename
67
+ end
68
+
69
+ if path && path.to_s[0] != '|'
70
+ [File.expand_path(path.to_s), mode]
71
+ else
72
+ ['', '']
73
+ end
74
+ rescue Errno::ENOENT
75
+ module_logger.debug('LFI Parsing ARGF: attempted to read a non-existent file')
67
76
  ['', '']
77
+ rescue Errno::EISDIR
78
+ module_logger.debug('LFI Parsing ARGF: attempted to read a directory')
79
+ [ARGF.filename, mode]
68
80
  end
69
81
  end
70
82
  end
@@ -79,6 +91,40 @@ module TCellAgent
79
91
  end
80
92
  'Read'
81
93
  end
94
+
95
+ def self.raise_if_block(path, mode)
96
+ return unless block_file_access?(path, mode)
97
+
98
+ raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
99
+ end
100
+
101
+ def self.default_open_handler(args, override_mode = '')
102
+ path, mode = extract_path_mode(*args)
103
+
104
+ mode = override_mode unless override_mode.empty?
105
+
106
+ raise_if_block(path, mode)
107
+ end
108
+
109
+ def self.argf_open_handler
110
+ path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode_argf
111
+
112
+ raise_if_block(path, mode)
113
+ end
114
+
115
+ def self.cmdi_open_handler(args, override_mode = '')
116
+ path, mode = extract_path_mode(*args)
117
+
118
+ mode = override_mode unless override_mode.empty?
119
+
120
+ raise_if_block(path, mode)
121
+
122
+ return unless path.empty?
123
+
124
+ cmd = TCellAgent::Cmdi.parse_command_from_open(*args)
125
+
126
+ TCellAgent::Cmdi.raise_if_block(cmd) if cmd
127
+ end
82
128
  end
83
129
  end
84
130
  end
@@ -0,0 +1,21 @@
1
+ class File
2
+ class << self
3
+ if TCellAgent.configuration.should_instrument?('File::new')
4
+ alias_method :tcell_original_new, :new
5
+ def new(*args, &block)
6
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args)
7
+
8
+ tcell_original_new(*args, &block)
9
+ end
10
+ end
11
+
12
+ if TCellAgent.configuration.should_instrument?('File::open')
13
+ alias_method :tcell_original_open, :open
14
+ def open(*args, &block)
15
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args)
16
+
17
+ tcell_original_open(*args, &block)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,75 @@
1
+ class IO
2
+ class << self
3
+ if TCellAgent.configuration.should_instrument?('IO::binread')
4
+ alias_method :tcell_original_binread, :binread
5
+ def binread(*args, &block)
6
+ TCellAgent::Instrumentation::Lfi.cmdi_open_handler(args)
7
+
8
+ tcell_original_binread(*args, &block)
9
+ end
10
+ end
11
+
12
+ if TCellAgent.configuration.should_instrument?('IO::binwrite')
13
+ alias_method :tcell_original_binwrite, :binwrite
14
+ def binwrite(*args, &block)
15
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args, 'Write')
16
+
17
+ tcell_original_binwrite(*args, &block)
18
+ end
19
+ end
20
+
21
+ if TCellAgent.configuration.should_instrument?('IO::foreach')
22
+ alias_method :tcell_original_foreach, :foreach
23
+ def foreach(*args, &block)
24
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args, 'Read')
25
+
26
+ tcell_original_foreach(*args, &block)
27
+ end
28
+ end
29
+
30
+ if TCellAgent.configuration.should_instrument?('IO::popen')
31
+ alias_method :tcell_original_popen, :popen
32
+ def popen(*args, &block)
33
+ TCellAgent::Cmdi.popen_cmdi_handler(args)
34
+
35
+ tcell_original_popen(*args, &block)
36
+ end
37
+ end
38
+
39
+ if TCellAgent.configuration.should_instrument?('IO::read')
40
+ alias_method :tcell_original_read, :read
41
+ def read(*args, &block)
42
+ TCellAgent::Instrumentation::Lfi.cmdi_open_handler(args, 'Read')
43
+
44
+ tcell_original_read(*args, &block)
45
+ end
46
+ end
47
+
48
+ if TCellAgent.configuration.should_instrument?('IO::readlines')
49
+ alias_method :tcell_original_readlines, :readlines
50
+ def readlines(*args, &block)
51
+ TCellAgent::Instrumentation::Lfi.cmdi_open_handler(args, 'Read')
52
+
53
+ tcell_original_readlines(*args, &block)
54
+ end
55
+ end
56
+
57
+ if TCellAgent.configuration.should_instrument?('IO::sysopen')
58
+ alias_method :tcell_original_sysopen, :sysopen
59
+ def sysopen(*args, &block)
60
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args)
61
+
62
+ tcell_original_sysopen(*args, &block)
63
+ end
64
+ end
65
+
66
+ if TCellAgent.configuration.should_instrument?('IO::write')
67
+ alias_method :tcell_original_write, :write
68
+ def write(*args, &block)
69
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args, 'Write')
70
+
71
+ tcell_original_write(*args, &block)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,80 @@
1
+ module Kernel
2
+ private
3
+
4
+ if TCellAgent.configuration.should_instrument?('Kernel#`')
5
+ alias_method :tcell_original_backtick, :`
6
+ def `(cmd)
7
+ TCellAgent::Cmdi.raise_if_block(cmd)
8
+
9
+ tcell_original_backtick(cmd)
10
+ end
11
+
12
+ module_function :`
13
+ end
14
+
15
+ if TCellAgent.configuration.should_instrument?('Kernel#exec')
16
+ alias_method :tcell_original_exec, :exec
17
+ def exec(*args)
18
+ TCellAgent::Cmdi.default_cmdi_handler(args)
19
+
20
+ tcell_original_exec(*args)
21
+ end
22
+
23
+ module_function :exec
24
+ end
25
+
26
+ if TCellAgent.configuration.should_instrument?('Kernel#gets')
27
+ alias_method :tcell_original_gets, :gets
28
+ def gets(*args, &block)
29
+ TCellAgent::Instrumentation::Lfi.argf_open_handler
30
+
31
+ tcell_original_gets(*args, &block)
32
+ end
33
+
34
+ module_function :gets
35
+ end
36
+
37
+ if TCellAgent.configuration.should_instrument?('Kernel#open')
38
+ alias_method :tcell_original_open, :open
39
+ def open(*args, &block)
40
+ TCellAgent::Instrumentation::Lfi.cmdi_open_handler(args)
41
+
42
+ tcell_original_open(*args, &block)
43
+ end
44
+
45
+ module_function :open
46
+ end
47
+
48
+ if TCellAgent.configuration.should_instrument?('Kernel#readline')
49
+ alias_method :tcell_original_readline, :readline
50
+ def readline(*args, &block)
51
+ TCellAgent::Instrumentation::Lfi.argf_open_handler
52
+
53
+ tcell_original_readline(*args, &block)
54
+ end
55
+
56
+ module_function :readline
57
+ end
58
+
59
+ if TCellAgent.configuration.should_instrument?('Kernel#spawn')
60
+ alias_method :tcell_original_spawn, :spawn
61
+ def spawn(*args)
62
+ TCellAgent::Cmdi.default_cmdi_handler(args)
63
+
64
+ tcell_original_spawn(*args)
65
+ end
66
+
67
+ module_function :spawn
68
+ end
69
+
70
+ if TCellAgent.configuration.should_instrument?('Kernel#system')
71
+ alias_method :tcell_original_system, :system
72
+ def system(*args)
73
+ TCellAgent::Cmdi.default_cmdi_handler(args)
74
+
75
+ tcell_original_system(*args)
76
+ end
77
+
78
+ module_function :system
79
+ end
80
+ end
@@ -0,0 +1,21 @@
1
+ class File
2
+ class << self
3
+ if TCellAgent.configuration.should_instrument?('File::new')
4
+ alias_method :tcell_original_new, :new
5
+ def new(*args, **kwargs, &block)
6
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args)
7
+
8
+ tcell_original_new(*args, **kwargs, &block)
9
+ end
10
+ end
11
+
12
+ if TCellAgent.configuration.should_instrument?('File::open')
13
+ alias_method :tcell_original_open, :open
14
+ def open(*args, **kwargs, &block)
15
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args)
16
+
17
+ tcell_original_open(*args, **kwargs, &block)
18
+ end
19
+ end
20
+ end
21
+ end