Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing K2 Integration #820

Draft
wants to merge 56 commits into
base: develop-k2-integration
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
b5711e3
initial changes for k2 integration
AnupamJuniwal Sep 21, 2022
20d5117
minor fix
AnupamJuniwal Sep 21, 2022
dfbcf0a
k2 agent would now init without any args
AnupamJuniwal Sep 22, 2022
f399c3a
initial implementation of securty config, removal of switch based k2 …
AnupamJuniwal Sep 27, 2022
c3232c9
minor fix with incorrect value for configuration mapper
AnupamJuniwal Sep 28, 2022
206160e
changes corresponding to latest k2 agent changes
AnupamJuniwal Sep 29, 2022
dd7bd2d
minor fixes
AnupamJuniwal Sep 29, 2022
7578dc0
updated integration source for k2
AnupamJuniwal Sep 30, 2022
857f3f9
Added customer id
AnupamJuniwal Sep 30, 2022
f0c30a1
initial changes for application id propagation
AnupamJuniwal Oct 1, 2022
42d621a
minor fix in application_id extraction
AnupamJuniwal Oct 1, 2022
e700fb2
minor fix
AnupamJuniwal Oct 1, 2022
1d5964b
guid propagation instead of application_id
AnupamJuniwal Oct 2, 2022
a2da1ba
Merge branch 'feature/k2_integration' into k2_integration
AnupamJuniwal Oct 2, 2022
163645b
This implements propagation of all possible k2 config in NR's config
AnupamJuniwal Oct 2, 2022
52e59e2
changes to populate dictionary of policy and changes to reflect secur…
AnupamJuniwal Oct 3, 2022
a609df8
This contains changes for policy propagation to k2
AnupamJuniwal Oct 6, 2022
30a280a
Merge branch 'feature/k2i/policy_propagation' into k2_integration
AnupamJuniwal Oct 6, 2022
a5dd418
updated config for logs upload and exception handling in security mod…
AnupamJuniwal Oct 7, 2022
5f226e8
Merge branch 'feature/k2i/logs_config_propagation' into k2_integration
AnupamJuniwal Oct 9, 2022
6d515e8
Changes for setting the trasnsaction id catcher by handing over a lam…
AnupamJuniwal Oct 9, 2022
34d610b
changes to send trace metadata long with transaction id from metadata…
AnupamJuniwal Oct 10, 2022
e02eacf
Merge 'feature/k2i/logs_config_propagation' into k2_integration
AnupamJuniwal Oct 10, 2022
385b966
This contains multiple changes:
AnupamJuniwal Oct 12, 2022
ded8f48
minor change to reflect k2 module changes
AnupamJuniwal Oct 12, 2022
5298430
Merge branch 'feature/k2i/add_linking_metadata_deprecate_old_k2_auth_…
AnupamJuniwal Oct 12, 2022
a2f385e
Addition of enforce flag
AnupamJuniwal Oct 26, 2022
2f46837
Merge branch 'main' into k2_integration
AnupamJuniwal Oct 26, 2022
a8a7a88
Addition of account id in linking metadata
AnupamJuniwal Dec 21, 2022
d925658
Temp changes
AnupamJuniwal Dec 23, 2022
a741c2d
Let the connect be called with refresh (When linking metadata is avai…
AnupamJuniwal Dec 23, 2022
0ec4fe4
agent would not connect with startup
AnupamJuniwal Dec 28, 2022
f5a98ba
removal of rest server endpoint config, use of SingletonAgentConfig i…
AnupamJuniwal Jan 25, 2023
524b315
removal of all security agent initialization logic
AnupamJuniwal Jan 25, 2023
46637fe
updates to newrelic config for security module
AnupamJuniwal Mar 14, 2023
5be1836
minor fix
AnupamJuniwal Mar 23, 2023
ac7e712
point to nr_adaptation with updated newrelic_security package
AnupamJuniwal Apr 17, 2023
a028082
updated to latest csec statup update
AnupamJuniwal Apr 17, 2023
49d7a99
Merge remote-tracking branch 'nr-public/main' into feature/nr_adaptation
AnupamJuniwal Apr 17, 2023
28d789a
Refactoring and relocation of security settings in core config
AnupamJuniwal Apr 28, 2023
1f780c2
initialising security agent before configuring nr apm hooks
AnupamJuniwal May 4, 2023
f0505f8
Merge branch 'main' into feature/nr_adaptation
AnupamJuniwal May 10, 2023
5fb7a42
fixes in config default values for security config for python 2.7 sup…
AnupamJuniwal May 17, 2023
11c0049
Will use dev branch for security agent
AnupamJuniwal May 26, 2023
1313de9
Merge branch 'k2io/nr-python-agent/develop' into develop-k2-integration
AnupamJuniwal Jun 1, 2023
093fd3a
Updated remote for pulling newrelic_security module
AnupamJuniwal Jun 1, 2023
88cb32e
Update install requires line.
umaannamalai Jun 1, 2023
7a43a7f
[Mega-Linter] Apply linters fixes
umaannamalai Jun 1, 2023
3d44b8c
Restore install requires.
umaannamalai Jun 1, 2023
fe17e36
[Mega-Linter] Apply linters fixes
umaannamalai Jun 1, 2023
b0e0a50
switch ordering
umaannamalai Jun 1, 2023
dada30b
Add dependency links.
umaannamalai Jun 1, 2023
78d90b6
[Mega-Linter] Apply linters fixes
umaannamalai Jun 1, 2023
1b0c1b5
Add security settings to web framework conftests.
umaannamalai Jun 1, 2023
14d7019
github ssh url.
umaannamalai Jun 2, 2023
874fd03
remove ssh prefix.
umaannamalai Jun 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions newrelic/config.py
Expand Up @@ -329,6 +329,13 @@ def _process_configuration(section):
_process_setting(section, "ca_bundle_path", "get", None)
_process_setting(section, "audit_log_file", "get", None)
_process_setting(section, "monitor_mode", "getboolean", None)
_process_setting(section, "security.agent.enabled", "getboolean", None)
_process_setting(section, "security.enabled", "getboolean", None)
_process_setting(section, "security.mode", "get", None)
_process_setting(section, "security.validator_service_url", "get", None)
_process_setting(section, "security.detection.rci.enabled", "getboolean", None)
_process_setting(section, "security.detection.rxss.enabled", "getboolean", None)
_process_setting(section, "security.detection.deserialization.enabled", "getboolean", None)
_process_setting(section, "developer_mode", "getboolean", None)
_process_setting(section, "high_security", "getboolean", None)
_process_setting(section, "capture_params", "getboolean", None)
Expand Down Expand Up @@ -3169,6 +3176,23 @@ def _setup_agent_console():
newrelic.core.agent.Agent.run_on_startup(_startup_agent_console)


def _setup_security_module():
"""Initiates k2 security module and adds a
callback to agent startup to propagate NR config
"""
try:
if not _settings.security.agent.enabled:
return
from newrelic_security.api.agent import Agent as SecurityAgent

# initialize security agent
security_agent = SecurityAgent()
# create a callback to reinitialise the security module
newrelic.core.agent.Agent.run_on_startup(security_agent.refresh_agent)
except Exception as k2error:
_logger.error("K2 Startup failed with error %s", k2error)


def initialize(
config_file=None,
environment=None,
Expand All @@ -3187,6 +3211,8 @@ def initialize(

_load_configuration(config_file, environment, ignore_errors, log_file, log_level)

_setup_security_module()

if _settings.monitor_mode or _settings.developer_mode:
_settings.enabled = True
_setup_instrumentation()
Expand Down
41 changes: 40 additions & 1 deletion newrelic/core/config.py
Expand Up @@ -279,6 +279,30 @@ class ApplicationLoggingLocalDecoratingSettings(Settings):
pass


class SecuritySettings(Settings):
pass


class SecurityDetectionSettings(Settings):
pass


class SecurityAgentSettings(Settings):
pass


class SecurityDetectionRCISettings(Settings):
pass


class SecurityDetectionRXSSSettings(Settings):
pass


class SecurityDetectionDeserializationSettings(Settings):
pass


class InfiniteTracingSettings(Settings):
_trace_observer_host = None

Expand Down Expand Up @@ -395,6 +419,12 @@ class EventHarvestConfigHarvestLimitSettings(Settings):
_settings.message_tracer = MessageTracerSettings()
_settings.process_host = ProcessHostSettings()
_settings.rum = RumSettings()
_settings.security = SecuritySettings()
_settings.security.agent = SecurityAgentSettings()
_settings.security.detection = SecurityDetectionSettings()
_settings.security.detection.deserialization = SecurityDetectionDeserializationSettings()
_settings.security.detection.rci = SecurityDetectionRCISettings()
_settings.security.detection.rxss = SecurityDetectionRXSSSettings()
_settings.serverless_mode = ServerlessModeSettings()
_settings.slow_sql = SlowSqlSettings()
_settings.span_events = SpanEventSettings()
Expand All @@ -412,7 +442,6 @@ class EventHarvestConfigHarvestLimitSettings(Settings):
_settings.transaction_tracer.attributes = TransactionTracerAttributesSettings()
_settings.utilization = UtilizationSettings()


_settings.log_file = os.environ.get("NEW_RELIC_LOG", None)
_settings.audit_log_file = os.environ.get("NEW_RELIC_AUDIT_LOG", None)

Expand Down Expand Up @@ -840,6 +869,16 @@ def default_host(license_key):
"NEW_RELIC_APPLICATION_LOGGING_LOCAL_DECORATING_ENABLED", default=False
)

_settings.security.agent.enabled = _environ_as_bool("NEW_RELIC_SECURITY_AGENT_ENABLED", False)
_settings.security.enabled = _environ_as_bool("NEW_RELIC_SECURITY_ENABLED", False)
_settings.security.mode = os.environ.get("NEW_RELIC_SECURITY_MODE", "IAST")
_settings.security.validator_service_url = os.environ.get("NEW_RELIC_SECURITY_VALIDATOR_SERVICE_URL", None)
_settings.security.detection.rci.enabled = _environ_as_bool("NEW_RELIC_SECURITY_DETECTION_RCI_ENABLED", True)
_settings.security.detection.rxss.enabled = _environ_as_bool("NEW_RELIC_SECURITY_DETECTION_RXSS_ENABLED", True)
_settings.security.detection.deserialization.enabled = _environ_as_bool(
"NEW_RELIC_SECURITY_DETECTION_DESERIALIZATION_ENABLED", True
)


def global_settings():
"""This returns the default global settings. Generally only used
Expand Down
27 changes: 26 additions & 1 deletion newrelic/newrelic.ini
Expand Up @@ -49,6 +49,32 @@ app_name = Python Application
# NEW_RELIC_MONITOR_MODE environment variable.
monitor_mode = true

# Indicates if attack detection security module is to be enabled
security.enabled = false

# To completely disable security set flag to false If the flag is
# set to false, the security module is not loaded. This property
# is read only once at application start.
security.agent.enabled = false


# security module provides two modes IAST or RASP
# RASP stands for Runtime Application Self Protection
# while IAST for Interactive Application Security Testing
# Default mode is IAST
security.mode = IAST


# web-protect agent endpoint connection URLs
security.validator_service_url = wss://csec.nr-data.net


# vulnerabilty detection flags
security.detection.rci.enabled = true
security.detection.rxss.enabled = true
security.detection.deserialization.enabled = true


# Sets the name of a file to log agent messages to. Whatever you
# set this to, you must ensure that the permissions for the
# containing directory and the file itself are correct, and
Expand Down Expand Up @@ -251,5 +277,4 @@ monitor_mode = true

[newrelic:production]
monitor_mode = true

# ---------------------------------------------------------------------------
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -151,6 +151,7 @@ def build_extension(self, ext):
package_data={
"newrelic": ["newrelic.ini", "version.txt", "packages/urllib3/LICENSE.txt", "common/cacert.pem"],
},
#install_requires=["newrelic-security @ git+https://github.com/newrelic/csec-python-agent.git@develop#egg=newrelic-security"],
extras_require={"infinite-tracing": ["grpcio", "protobuf"]},
)

Expand Down
4 changes: 4 additions & 0 deletions tests/framework_bottle/conftest.py
Expand Up @@ -23,6 +23,10 @@
'transaction_tracer.stack_trace_threshold': 0.0,
'debug.log_data_collector_payloads': True,
'debug.record_transaction_failure': True,
"security.agent.enabled": True,
"security.enabled": True,
"security.mode": "IAST",
"security.validator_service_url": "wss://csec-staging.nr-data.net"
}

collector_agent_registration = collector_agent_registration_fixture(
Expand Down
4 changes: 4 additions & 0 deletions tests/framework_django/conftest.py
Expand Up @@ -25,6 +25,10 @@
'debug.record_transaction_failure': True,
'debug.log_autorum_middleware': True,
'feature_flag': set(['django.instrumentation.inclusion-tags.r1']),
"security.agent.enabled": True,
"security.enabled": True,
"security.mode": "IAST",
"security.validator_service_url": "wss://csec-staging.nr-data.net"
}

collector_agent_registration = collector_agent_registration_fixture(
Expand Down
5 changes: 4 additions & 1 deletion tests/framework_flask/conftest.py
Expand Up @@ -19,14 +19,17 @@

from testing_support.fixtures import collector_agent_registration_fixture, collector_available_fixture # noqa: F401; pylint: disable=W0611


_default_settings = {
'transaction_tracer.explain_threshold': 0.0,
'transaction_tracer.transaction_threshold': 0.0,
'transaction_tracer.stack_trace_threshold': 0.0,
'debug.log_data_collector_payloads': True,
'debug.record_transaction_failure': True,
'debug.log_autorum_middleware': True,
"security.agent.enabled": True,
"security.enabled": True,
"security.mode": "IAST",
"security.validator_service_url": "wss://csec-staging.nr-data.net"
}

collector_agent_registration = collector_agent_registration_fixture(
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Expand Up @@ -173,8 +173,10 @@ deps =
{py27,pypy}: pytest==4.6.11
iniconfig
coverage
git+git@github.com:newrelic/csec-python-agent.git#egg=newrelic-security
WebTest==2.0.35


# Test Suite Dependencies
adapter_cheroot: cheroot
adapter_daphne-daphnelatest: daphne
Expand Down