contrast-agent 6.0.0 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/ext/cs__assess_regexp/cs__assess_regexp.c +15 -2
  3. data/ext/cs__assess_regexp/cs__assess_regexp.h +2 -0
  4. data/ext/cs__assess_string/cs__assess_string.c +8 -0
  5. data/ext/cs__assess_test/cs__assess_test.h +9 -0
  6. data/ext/cs__assess_test/cs__assess_tests.c +22 -0
  7. data/ext/cs__assess_test/extconf.rb +5 -0
  8. data/ext/cs__common/cs__common.c +101 -0
  9. data/ext/cs__common/cs__common.h +29 -5
  10. data/ext/cs__contrast_patch/cs__contrast_patch.c +1 -1
  11. data/ext/cs__tests/cs__tests.c +12 -0
  12. data/ext/cs__tests/cs__tests.h +3 -0
  13. data/ext/cs__tests/extconf.rb +5 -0
  14. data/lib/contrast/agent/assess/contrast_object.rb +16 -16
  15. data/lib/contrast/agent/assess/events/source_event.rb +17 -19
  16. data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -16
  17. data/lib/contrast/agent/assess/policy/propagator/split.rb +15 -19
  18. data/lib/contrast/agent/assess/policy/trigger_method.rb +3 -11
  19. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +7 -2
  20. data/lib/contrast/agent/assess/rule/response/base_rule.rb +11 -3
  21. data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +60 -36
  22. data/lib/contrast/agent/at_exit_hook.rb +1 -1
  23. data/lib/contrast/agent/inventory/database_config.rb +10 -3
  24. data/lib/contrast/agent/middleware.rb +3 -3
  25. data/lib/contrast/agent/patching/policy/after_load_patch.rb +0 -2
  26. data/lib/contrast/agent/patching/policy/patch.rb +13 -12
  27. data/lib/contrast/agent/patching/policy/patcher.rb +1 -1
  28. data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +6 -2
  29. data/lib/contrast/agent/reporting/masker/masker.rb +8 -11
  30. data/lib/contrast/agent/reporting/masker/masker_utils.rb +8 -4
  31. data/lib/contrast/agent/reporting/reporter.rb +11 -16
  32. data/lib/contrast/agent/reporting/reporter_heartbeat.rb +49 -0
  33. data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +6 -2
  34. data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +53 -0
  35. data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +48 -0
  36. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +64 -0
  37. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +70 -0
  38. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +57 -0
  39. data/lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb +56 -0
  40. data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +5 -1
  41. data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +58 -0
  42. data/lib/contrast/agent/reporting/reporting_events/application_reporting_event.rb +27 -0
  43. data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +20 -10
  44. data/lib/contrast/agent/reporting/reporting_events/application_update.rb +7 -12
  45. data/lib/contrast/agent/reporting/reporting_events/finding.rb +9 -3
  46. data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +2 -4
  47. data/lib/contrast/agent/reporting/reporting_events/finding_event_object.rb +3 -3
  48. data/lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb +6 -2
  49. data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +7 -3
  50. data/lib/contrast/agent/reporting/reporting_events/poll.rb +6 -2
  51. data/lib/contrast/agent/reporting/reporting_events/preflight.rb +10 -8
  52. data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +6 -10
  53. data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +12 -20
  54. data/lib/contrast/agent/reporting/reporting_events/server_reporting_event.rb +27 -0
  55. data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +17 -27
  56. data/lib/contrast/agent/reporting/reporting_utilities/build_preflight.rb +38 -0
  57. data/lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb +8 -0
  58. data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +6 -0
  59. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +9 -4
  60. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +54 -67
  61. data/lib/contrast/agent/reporting/reporting_utilities/response.rb +17 -7
  62. data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +8 -5
  63. data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +10 -10
  64. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +32 -17
  65. data/lib/contrast/agent/reporting/settings/protect.rb +1 -1
  66. data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +1 -1
  67. data/lib/contrast/agent/request.rb +3 -3
  68. data/lib/contrast/agent/request_context_extend.rb +1 -1
  69. data/lib/contrast/agent/request_handler.rb +3 -3
  70. data/lib/contrast/agent/response.rb +2 -0
  71. data/lib/contrast/agent/service_heartbeat.rb +6 -48
  72. data/lib/contrast/agent/static_analysis.rb +1 -1
  73. data/lib/contrast/agent/telemetry/base.rb +151 -0
  74. data/lib/contrast/agent/telemetry/events/event.rb +35 -0
  75. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +44 -36
  76. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +29 -21
  77. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +91 -73
  78. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +62 -44
  79. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +50 -33
  80. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions.rb +20 -0
  81. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions_report.rb +32 -0
  82. data/lib/contrast/agent/telemetry/events/metric_event.rb +28 -0
  83. data/lib/contrast/agent/telemetry/events/startup_metrics_event.rb +123 -0
  84. data/lib/contrast/agent/thread_watcher.rb +52 -68
  85. data/lib/contrast/agent/version.rb +1 -1
  86. data/lib/contrast/agent/worker_thread.rb +8 -0
  87. data/lib/contrast/agent.rb +1 -3
  88. data/lib/contrast/api/communication/messaging_queue.rb +28 -11
  89. data/lib/contrast/api/communication/response_processor.rb +7 -10
  90. data/lib/contrast/api/communication/speedracer.rb +1 -1
  91. data/lib/contrast/api/decorators/activity.rb +33 -0
  92. data/lib/contrast/api/decorators/http_request.rb +1 -1
  93. data/lib/contrast/components/config.rb +13 -22
  94. data/lib/contrast/components/contrast_service.rb +9 -0
  95. data/lib/contrast/components/settings.rb +10 -0
  96. data/lib/contrast/config/agent_configuration.rb +21 -11
  97. data/lib/contrast/config/api_configuration.rb +12 -8
  98. data/lib/contrast/config/api_proxy_configuration.rb +7 -3
  99. data/lib/contrast/config/application_configuration.rb +15 -11
  100. data/lib/contrast/config/assess_configuration.rb +13 -9
  101. data/lib/contrast/config/assess_rules_configuration.rb +5 -1
  102. data/lib/contrast/config/base_configuration.rb +3 -35
  103. data/lib/contrast/config/certification_configuration.rb +9 -5
  104. data/lib/contrast/config/exception_configuration.rb +10 -7
  105. data/lib/contrast/config/heap_dump_configuration.rb +13 -9
  106. data/lib/contrast/config/inventory_configuration.rb +9 -6
  107. data/lib/contrast/config/logger_configuration.rb +9 -6
  108. data/lib/contrast/config/protect_configuration.rb +9 -6
  109. data/lib/contrast/config/protect_rule_configuration.rb +12 -8
  110. data/lib/contrast/config/protect_rules_configuration.rb +18 -17
  111. data/lib/contrast/config/request_audit_configuration.rb +10 -7
  112. data/lib/contrast/config/root_configuration.rb +28 -11
  113. data/lib/contrast/config/ruby_configuration.rb +14 -11
  114. data/lib/contrast/config/sampling_configuration.rb +11 -8
  115. data/lib/contrast/config/server_configuration.rb +13 -9
  116. data/lib/contrast/config/service_configuration.rb +14 -11
  117. data/lib/contrast/configuration.rb +19 -10
  118. data/lib/contrast/framework/rails/patch/support.rb +13 -45
  119. data/lib/contrast/logger/aliased_logging.rb +87 -0
  120. data/lib/contrast/logger/application.rb +0 -4
  121. data/lib/contrast/tasks/config.rb +22 -13
  122. data/lib/contrast/utils/class_util.rb +2 -6
  123. data/lib/contrast/utils/invalid_configuration_util.rb +1 -1
  124. data/lib/contrast/utils/log_utils.rb +2 -0
  125. data/lib/contrast/utils/middleware_utils.rb +1 -1
  126. data/lib/contrast/utils/object_share.rb +1 -1
  127. data/lib/contrast/utils/telemetry.rb +20 -2
  128. data/lib/contrast/utils/telemetry_client.rb +22 -10
  129. data/lib/contrast/utils/telemetry_hash.rb +41 -0
  130. data/lib/contrast/utils/telemetry_identifier.rb +16 -1
  131. data/lib/contrast.rb +9 -0
  132. data/ruby-agent.gemspec +1 -1
  133. data/service_executables/VERSION +1 -1
  134. data/service_executables/linux/contrast-service +0 -0
  135. data/service_executables/mac/contrast-service +0 -0
  136. metadata +39 -16
  137. data/lib/contrast/agent/telemetry/events/metric_telemetry_event.rb +0 -26
  138. data/lib/contrast/agent/telemetry/events/startup_metrics_telemetry_event.rb +0 -121
  139. data/lib/contrast/agent/telemetry/events/telemetry_event.rb +0 -33
  140. data/lib/contrast/agent/telemetry/telemetry.rb +0 -150
  141. data/lib/contrast/utils/exclude_key.rb +0 -20
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contrast-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - galen.palmer@contrastsecurity.com
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: exe
15
15
  cert_chain: []
16
- date: 2022-04-04 00:00:00.000000000 Z
16
+ date: 2022-05-05 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: bundler
@@ -631,20 +631,22 @@ executables:
631
631
  - contrast_service
632
632
  extensions:
633
633
  - ext/cs__common/extconf.rb
634
- - ext/cs__assess_basic_object/extconf.rb
634
+ - ext/cs__assess_hash/extconf.rb
635
635
  - ext/cs__assess_array/extconf.rb
636
- - ext/cs__assess_string_interpolation26/extconf.rb
637
- - ext/cs__contrast_patch/extconf.rb
638
- - ext/cs__assess_fiber_track/extconf.rb
639
- - ext/cs__assess_marshal_module/extconf.rb
636
+ - ext/cs__assess_test/extconf.rb
640
637
  - ext/cs__os_information/extconf.rb
641
638
  - ext/cs__assess_yield_track/extconf.rb
642
- - ext/cs__assess_string/extconf.rb
643
- - ext/cs__assess_hash/extconf.rb
644
- - ext/cs__scope/extconf.rb
645
639
  - ext/cs__assess_kernel/extconf.rb
646
640
  - ext/cs__assess_module/extconf.rb
641
+ - ext/cs__assess_string_interpolation26/extconf.rb
647
642
  - ext/cs__assess_regexp/extconf.rb
643
+ - ext/cs__assess_fiber_track/extconf.rb
644
+ - ext/cs__scope/extconf.rb
645
+ - ext/cs__assess_marshal_module/extconf.rb
646
+ - ext/cs__assess_string/extconf.rb
647
+ - ext/cs__assess_basic_object/extconf.rb
648
+ - ext/cs__contrast_patch/extconf.rb
649
+ - ext/cs__tests/extconf.rb
648
650
  extra_rdoc_files: []
649
651
  files:
650
652
  - ".clang-format"
@@ -690,6 +692,9 @@ files:
690
692
  - ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c
691
693
  - ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.h
692
694
  - ext/cs__assess_string_interpolation26/extconf.rb
695
+ - ext/cs__assess_test/cs__assess_test.h
696
+ - ext/cs__assess_test/cs__assess_tests.c
697
+ - ext/cs__assess_test/extconf.rb
693
698
  - ext/cs__assess_yield_track/cs__assess_yield_track.c
694
699
  - ext/cs__assess_yield_track/cs__assess_yield_track.h
695
700
  - ext/cs__assess_yield_track/extconf.rb
@@ -705,6 +710,9 @@ files:
705
710
  - ext/cs__scope/cs__scope.c
706
711
  - ext/cs__scope/cs__scope.h
707
712
  - ext/cs__scope/extconf.rb
713
+ - ext/cs__tests/cs__tests.c
714
+ - ext/cs__tests/cs__tests.h
715
+ - ext/cs__tests/extconf.rb
708
716
  - ext/extconf_common.rb
709
717
  - funchook/LICENSE
710
718
  - funchook/Makefile.in
@@ -992,8 +1000,17 @@ files:
992
1000
  - lib/contrast/agent/reporting/masker/masker_utils.rb
993
1001
  - lib/contrast/agent/reporting/report.rb
994
1002
  - lib/contrast/agent/reporting/reporter.rb
1003
+ - lib/contrast/agent/reporting/reporter_heartbeat.rb
995
1004
  - lib/contrast/agent/reporting/reporting_events/agent_startup.rb
1005
+ - lib/contrast/agent/reporting/reporting_events/application_activity.rb
1006
+ - lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb
1007
+ - lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb
1008
+ - lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb
1009
+ - lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb
1010
+ - lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb
996
1011
  - lib/contrast/agent/reporting/reporting_events/application_inventory.rb
1012
+ - lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb
1013
+ - lib/contrast/agent/reporting/reporting_events/application_reporting_event.rb
997
1014
  - lib/contrast/agent/reporting/reporting_events/application_startup.rb
998
1015
  - lib/contrast/agent/reporting/reporting_events/application_startup_instrumentation.rb
999
1016
  - lib/contrast/agent/reporting/reporting_events/application_update.rb
@@ -1021,8 +1038,10 @@ files:
1021
1038
  - lib/contrast/agent/reporting/reporting_events/route_discovery.rb
1022
1039
  - lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
1023
1040
  - lib/contrast/agent/reporting/reporting_events/server_activity.rb
1041
+ - lib/contrast/agent/reporting/reporting_events/server_reporting_event.rb
1024
1042
  - lib/contrast/agent/reporting/reporting_events/trace_event_source.rb
1025
1043
  - lib/contrast/agent/reporting/reporting_utilities/audit.rb
1044
+ - lib/contrast/agent/reporting/reporting_utilities/build_preflight.rb
1026
1045
  - lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb
1027
1046
  - lib/contrast/agent/reporting/reporting_utilities/endpoints.rb
1028
1047
  - lib/contrast/agent/reporting/reporting_utilities/headers.rb
@@ -1054,15 +1073,17 @@ files:
1054
1073
  - lib/contrast/agent/scope.rb
1055
1074
  - lib/contrast/agent/service_heartbeat.rb
1056
1075
  - lib/contrast/agent/static_analysis.rb
1076
+ - lib/contrast/agent/telemetry/base.rb
1077
+ - lib/contrast/agent/telemetry/events/event.rb
1057
1078
  - lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb
1058
1079
  - lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb
1059
1080
  - lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb
1060
1081
  - lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb
1061
1082
  - lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb
1062
- - lib/contrast/agent/telemetry/events/metric_telemetry_event.rb
1063
- - lib/contrast/agent/telemetry/events/startup_metrics_telemetry_event.rb
1064
- - lib/contrast/agent/telemetry/events/telemetry_event.rb
1065
- - lib/contrast/agent/telemetry/telemetry.rb
1083
+ - lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions.rb
1084
+ - lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions_report.rb
1085
+ - lib/contrast/agent/telemetry/events/metric_event.rb
1086
+ - lib/contrast/agent/telemetry/events/startup_metrics_event.rb
1066
1087
  - lib/contrast/agent/thread.rb
1067
1088
  - lib/contrast/agent/thread_watcher.rb
1068
1089
  - lib/contrast/agent/tracepoint_hook.rb
@@ -1081,6 +1102,7 @@ files:
1081
1102
  - lib/contrast/api/communication/tcp_socket.rb
1082
1103
  - lib/contrast/api/communication/unix_socket.rb
1083
1104
  - lib/contrast/api/decorators.rb
1105
+ - lib/contrast/api/decorators/activity.rb
1084
1106
  - lib/contrast/api/decorators/address.rb
1085
1107
  - lib/contrast/api/decorators/agent_startup.rb
1086
1108
  - lib/contrast/api/decorators/application_settings.rb
@@ -1182,6 +1204,7 @@ files:
1182
1204
  - lib/contrast/framework/rails/support.rb
1183
1205
  - lib/contrast/framework/sinatra/support.rb
1184
1206
  - lib/contrast/funchook/funchook.rb
1207
+ - lib/contrast/logger/aliased_logging.rb
1185
1208
  - lib/contrast/logger/application.rb
1186
1209
  - lib/contrast/logger/cef_log.rb
1187
1210
  - lib/contrast/logger/format.rb
@@ -1202,7 +1225,6 @@ files:
1202
1225
  - lib/contrast/utils/class_util.rb
1203
1226
  - lib/contrast/utils/duck_utils.rb
1204
1227
  - lib/contrast/utils/env_configuration_item.rb
1205
- - lib/contrast/utils/exclude_key.rb
1206
1228
  - lib/contrast/utils/findings.rb
1207
1229
  - lib/contrast/utils/hash_digest.rb
1208
1230
  - lib/contrast/utils/hash_digest_extend.rb
@@ -1231,6 +1253,7 @@ files:
1231
1253
  - lib/contrast/utils/tag_util.rb
1232
1254
  - lib/contrast/utils/telemetry.rb
1233
1255
  - lib/contrast/utils/telemetry_client.rb
1256
+ - lib/contrast/utils/telemetry_hash.rb
1234
1257
  - lib/contrast/utils/telemetry_identifier.rb
1235
1258
  - lib/contrast/utils/thread_tracker.rb
1236
1259
  - lib/contrast/utils/timer.rb
@@ -1250,7 +1273,7 @@ homepage: https://www.contrastsecurity.com
1250
1273
  licenses:
1251
1274
  - CONTRAST SECURITY (see license file)
1252
1275
  metadata:
1253
- changelog_uri: https://docs.contrastsecurity.com/release.html
1276
+ changelog_uri: https://docs.contrastsecurity.com/en/ruby-agent-release-notes-and-archive.html
1254
1277
  support_uri: https://support.contrastsecurity.com
1255
1278
  trouble_shooting_uri: https://support.contrastsecurity.com/hc/en-us/search?utf8=%E2%9C%93&query=Ruby
1256
1279
  wiki_uri: https://docs.contrastsecurity.com/
@@ -1,26 +0,0 @@
1
- # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
- # frozen_string_literal: true
3
-
4
- require 'contrast/utils/metrics_hash'
5
- require 'contrast/agent/telemetry/events/telemetry_event'
6
-
7
- module Contrast
8
- module Agent
9
- # This class will hold the basic information for a Telemetry Event
10
- class MetricTelemetryEvent < Contrast::Agent::TelemetryEvent
11
- include Contrast::Utils
12
-
13
- attr_reader :fields
14
-
15
- def initialize
16
- super
17
- @fields = MetricsHash.new(Numeric)
18
- @fields['_filler'] = 0
19
- end
20
-
21
- def to_hash **_args
22
- super.merge!({ fields: @fields })
23
- end
24
- end
25
- end
26
- end
@@ -1,121 +0,0 @@
1
- # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
- # frozen_string_literal: true
3
-
4
- require 'contrast/utils/metrics_hash'
5
- require 'contrast/agent/telemetry/events/metric_telemetry_event'
6
- require 'contrast/agent/version'
7
- require 'contrast/utils/os'
8
-
9
- module Contrast
10
- module Agent
11
- # This class will hold the Startup Metrics Telemetry Event
12
- # The class will include initialization of the agent version, language version
13
- # os type, arch and version
14
- # application framework and version and server framework
15
- # It will be initialized and send in Middleware#agent_startup_routine
16
- class StartupMetricsTelemetryEvent < Contrast::Agent::MetricTelemetryEvent
17
- include Contrast::Utils::OS
18
-
19
- APP_AND_SERVER_DATA = ::Contrast::APP_CONTEXT.app_and_server_information.cs__freeze
20
- # Multi-tenant Production Environments
21
- SAAS_DEFAULT = { addr: 'app.contrastsecurity.com', type: 'SAAS_DEFAULT' }.cs__freeze
22
- SAAS_CS = { addr: /cs[[:digit:]]+\.contrastsecurity\.com/, type: 'SAAS_DEFAULT' }.cs__freeze
23
- SAAS_JP = { addr: 'app.contrastsecurity.jp', type: 'SAAS_DEFAULT' }.cs__freeze
24
- SAAS_CE = { addr: 'ce.contrastsecurity.com', type: 'SAAS_CE' }.cs__freeze
25
- # Multi-tenant Demo Environments
26
- SAAS_DEMO = { addr: 'apptwo.contrastsecurity.com', type: 'SAAS_DEMO' }.cs__freeze
27
- SAAS_POV = { addr: 'eval.contrastsecurity.com', type: 'SAAS_POV' }.cs__freeze
28
- # Multi-tenant Testing Environment
29
- SAAS_RESEARCH = { addr: 'security-research.contrastsecurity.com', type: 'SAAS_RESEARCH' }.cs__freeze
30
- SAAS_ALPHA = { addr: 'alpha.contrastsecurity.com', type: 'SAAS_ALPHA' }.cs__freeze
31
- SAAS_STAGING = { addr: 'teamserver-staging.contsec.com', type: 'SAAS_TESTING' }.cs__freeze
32
- SAAS_STAGING_TOKYO = { addr: 'teamserver-staging.contsec.jp', type: 'SAAS_TESTING' }.cs__freeze
33
- SAAS_TESTING = { addr: 'teamserver-darpa.contsec.com', type: 'SAAS_TESTING' }.cs__freeze
34
- SAAS_OPS_TESTING = { addr: 'teamserver-ops.contsec.com', type: 'SAAS_TESTING' }.cs__freeze
35
- # Fallback for Single-tenant Production Environments
36
- SAAS_CUSTOM = { addr: 'contrastsecurity.com', type: 'SAAS_CUSTOM' }.cs__freeze
37
- SAAS_CUSTOM_JP = { addr: 'contrastsecurity.jp', type: 'SAAS_CUSTOM' }.cs__freeze
38
-
39
- SINGLE_MAP_TENANTS = [
40
- SAAS_DEFAULT, SAAS_JP, SAAS_CE, SAAS_DEMO, SAAS_POV, SAAS_RESEARCH, SAAS_ALPHA,
41
- SAAS_STAGING, SAAS_STAGING_TOKYO, SAAS_TESTING, SAAS_OPS_TESTING
42
- ].cs__freeze
43
- REGEXP_MAP_TENANTS = [SAAS_CS].cs__freeze
44
- FALLBACK_TENANTS = [SAAS_CUSTOM, SAAS_CUSTOM_JP].cs__freeze
45
- # Fallback for Custom, most likely self-hosted, Environments
46
- EOP = 'EOP'
47
- REJECTED_VALUES = [:EMPTY_VALUE, 'NEEDS_TO_BE_SET', Contrast::Utils::ObjectShare::EMPTY_STRING].cs__freeze
48
-
49
- def initialize
50
- super
51
- @settings = []
52
- add_config_keys ::Contrast::CONFIG.root, 'root'
53
- @settings << ENV.keys.select { |v| v.starts_with?('CONTRAST') }
54
- @settings.flatten
55
- add_tags
56
- end
57
-
58
- def path
59
- '/startup'
60
- end
61
-
62
- def add_tags
63
- add_system_tags
64
- @tags['app_framework_and_version'] = APP_AND_SERVER_DATA[:application_info].to_s
65
- @tags['server_framework_and_version'] = APP_AND_SERVER_DATA[:server_info].to_s
66
- @tags['ASSESS'] = Contrast::ASSESS.enabled?.to_s
67
- @tags['PROTECT'] = Contrast::PROTECT.enabled?.to_s
68
- @tags['settings'] = @settings.join(',')
69
- end
70
-
71
- def add_config_keys config, nested_key
72
- config.to_hash.reject! { |_k, v| REJECTED_VALUES.include?(v) }
73
-
74
- config.to_hash.each do |k, v|
75
- unless v.cs__class <= Contrast::Config::BaseConfiguration
76
- @settings << "#{ nested_key }.#{ k }"
77
- next
78
- end
79
-
80
- add_config_keys v, "#{ nested_key }.#{ k }"
81
- end
82
- end
83
-
84
- def sys_info
85
- @sys_info ||= get_system_information if @sys_info.nil?
86
- @sys_info
87
- end
88
-
89
- private
90
-
91
- # Here we extract the TeamServer url type
92
- #
93
- # @return [String] the type of TeamServer environment to which we're connecting
94
- def teamserver_type
95
- @_teamserver_type ||= begin
96
- url = Contrast::API.api_url
97
- if (single = SINGLE_MAP_TENANTS.find { |tenant| url.include?(tenant[:addr]) })
98
- single[:type]
99
- elsif (regexp = REGEXP_MAP_TENANTS.find { |tenant| tenant[:addr].match?(url) })
100
- regexp[:type]
101
- elsif (fallback = FALLBACK_TENANTS.find { |tenant| url.include?(tenant[:addr]) })
102
- fallback[:type]
103
- else
104
- EOP
105
- end
106
- end
107
- end
108
-
109
- # Here we attach the key-value pairs of the system
110
- #
111
- def add_system_tags
112
- @tags['teamserver'] = teamserver_type
113
- @tags['agent_version'] = VERSION
114
- @tags['ruby_version'] = RUBY_VERSION
115
- @tags['os_type'] = sys_info['os_type'] == 'Darwin' ? 'MacOS' : 'Linux'
116
- @tags['os_arch'] = sys_info['os_arch']
117
- @tags['os_version'] = sys_info['os_version']
118
- end
119
- end
120
- end
121
- end
@@ -1,33 +0,0 @@
1
- # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
- # frozen_string_literal: true
3
-
4
- require 'contrast/utils/metrics_hash'
5
-
6
- module Contrast
7
- module Agent
8
- # This class will hold the basic information for a Telemetry Event
9
- class TelemetryEvent
10
- include Contrast::Utils
11
-
12
- attr_reader :tags
13
-
14
- def initialize
15
- @tags = MetricsHash.new(String)
16
- @timestamp = Time.now.iso8601
17
- end
18
-
19
- def path
20
- ''
21
- end
22
-
23
- def to_hash **_args
24
- {
25
- tags: @tags,
26
- timestamp: @timestamp,
27
- instance: Contrast::Agent::Telemetry.instance_id,
28
- application: Contrast::Agent::Telemetry.application_id
29
- }
30
- end
31
- end
32
- end
33
- end
@@ -1,150 +0,0 @@
1
- # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
- # frozen_string_literal: true
3
-
4
- require 'contrast/config/env_variables'
5
- require 'contrast/components/logger'
6
- require 'contrast/utils/telemetry_client'
7
- require 'contrast/agent/worker_thread'
8
- require 'contrast/utils/telemetry'
9
-
10
- module Contrast
11
- module Agent
12
- # This class will initialize and hold everything needed for the telemetry
13
- class Telemetry < WorkerThread
14
- include Contrast::Components::Logger::InstanceMethods
15
- # this is where we will send the data from the agents
16
- URL = 'https://telemetry.ruby.contrastsecurity.com/'
17
- # Suggested timeout after each send is to be 3 hours (10800 seconds)
18
- SUGGESTED_TIMEOUT = 10_800
19
-
20
- class << self
21
- include Contrast::Components::Logger::InstanceMethods
22
- include Contrast::Config::EnvVariables
23
-
24
- def application_id
25
- @_application_id ||= begin
26
- id = nil
27
- mac = Contrast::Utils::Telemetry::Identifier.mac
28
- app_name = Contrast::Utils::Telemetry::Identifier.app_name
29
- id = mac + app_name if mac && app_name
30
- Digest::SHA2.new(256).hexdigest(id || "_#{ SecureRandom.uuid }")
31
- end
32
- end
33
-
34
- def instance_id
35
- @_instance_id ||= Digest::SHA2.new(256).hexdigest(Contrast::Utils::Telemetry::Identifier.mac ||
36
- "_#{ SecureRandom.uuid }")
37
- end
38
-
39
- def enabled?
40
- @_enabled = telemetry_enabled? if @_enabled.nil?
41
- @_enabled
42
- end
43
-
44
- private
45
-
46
- def telemetry_enabled?
47
- opt_out_telemetry = return_value(:telemetry_opt_outs).to_s
48
- return false if opt_out_telemetry.casecmp?('true') || opt_out_telemetry == '1'
49
-
50
- # In case of connection error, do not create the background thread or queue,
51
- # as if the opt-out env var was set
52
- @_client = Contrast::Utils::TelemetryClient.new
53
- ip_opt_out_telemetry = @_client.initialize_connection(URL)
54
- if ip_opt_out_telemetry.nil?
55
- logger.warn("Connection was not established properly!!! \n Telemetry reporting will be disabled!")
56
- return false
57
- end
58
-
59
- true
60
- end
61
- end
62
-
63
- def client
64
- @_client ||= Contrast::Utils::TelemetryClient.new
65
- end
66
-
67
- def connection
68
- @_connection ||= client.initialize_connection(URL)
69
- end
70
-
71
- def attempt_to_start?
72
- unless cs__class.enabled?
73
- logger.warn('Telemetry service is disabled!')
74
- return false
75
- end
76
-
77
- logger.debug('Attempting to start telemetry thread') unless running?
78
- true
79
- end
80
-
81
- def start_thread!
82
- return if running?
83
-
84
- # It is recommended that implementations send a single payload of
85
- # general metrics every 3 hours, starting from implementation startup.
86
- @_thread = Contrast::Agent::Thread.new do
87
- logger.debug('Starting background telemetry thread.')
88
- loop do
89
- next unless client && connection
90
-
91
- until queue.empty?
92
- event = queue.pop
93
- begin
94
- logger.debug('This is the current processed event', event)
95
- sleep_time = request_with_response event
96
- if sleep_time
97
- sleep(sleep_time)
98
- logger.debug('Retrying to process event', event)
99
- retry_sleep_time = request_with_response event
100
- sleep(retry_sleep_time) unless retry_sleep_time.nil?
101
- end
102
- rescue StandardError => e
103
- logger.error('Could not send message to service from telemetry queue.', e)
104
- stop!
105
- end
106
- end
107
- sleep(SUGGESTED_TIMEOUT)
108
- end
109
- end
110
- end
111
-
112
- def send_event event
113
- if ::Contrast::AGENT.disabled?
114
- logger.warn('Attempted to queue event with Agent disabled', caller: caller, event: event)
115
- return
116
- end
117
-
118
- return unless cs__class.enabled?
119
-
120
- logger.debug('Enqueued event for sending', event_type: event.cs__class)
121
- queue << event if event
122
- end
123
-
124
- def delete_queue!
125
- @_queue&.clear
126
- @_queue&.close
127
- @_queue = nil
128
- end
129
-
130
- def stop!
131
- return unless running?
132
-
133
- @_enabled = false
134
- delete_queue!
135
- super
136
- end
137
-
138
- def request_with_response event
139
- res = client.send_request event, connection
140
- client.handle_response res
141
- end
142
-
143
- private
144
-
145
- def queue
146
- @_queue ||= Queue.new
147
- end
148
- end
149
- end
150
- end
@@ -1,20 +0,0 @@
1
- # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
- # frozen_string_literal: true
3
-
4
- module Contrast
5
- module Utils
6
- # Determine if configuration keys is excluded from logging
7
- module ExcludeKey
8
- EXCLUDE_FROM_LOG = %w[api api_key url service_key user_name].cs__freeze
9
- class << self
10
- # Check if a config key can be logged or not
11
- #
12
- # @param key [String] key to check
13
- # @return[Boolean] true | false
14
- def excludable? key
15
- EXCLUDE_FROM_LOG.any? { |exclude_key| key.include? exclude_key }
16
- end
17
- end
18
- end
19
- end
20
- end