Skip to content

Commit 4c7f8b2

Browse files
authored
chore(asm): make it possible to enable asm threat monitoring in AWS Lambda for dev builds (#13602)
Jira Ticket: APPSEC-57888 ## Description Do not automatically disable ASM in the context of AWS lambda but make it possible to enable threat monitoring with the regular env var DD_APPSEC_ENABLED. In production libddwaf is stripped from the `datadog-lambda-python` release builds and this will force disable ASM regardless. This will only impact dev builds that use DD_APPSEC_ENABLED=true ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
1 parent 0e5abc9 commit 4c7f8b2

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

ddtrace/appsec/_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def on_span_start(self, span: Span) -> None:
179179
if not hasattr(self, "_ddwaf"):
180180
self.delayed_init()
181181

182-
if span.span_type not in {SpanTypes.WEB, SpanTypes.GRPC}:
182+
if span.span_type not in asm_config._asm_processed_span_types:
183183
return
184184

185185
_asm_request_context.start_context(span)

ddtrace/settings/asm.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ddtrace.appsec._constants import LOGIN_EVENTS_MODE
1515
from ddtrace.appsec._constants import TELEMETRY_INFORMATION_NAME
1616
from ddtrace.constants import APPSEC_ENV
17+
from ddtrace.ext import SpanTypes
1718
from ddtrace.internal import core
1819
from ddtrace.internal.serverless import in_aws_lambda
1920
from ddtrace.settings._config import config as tracer_config
@@ -64,6 +65,7 @@ class ASMConfig(DDConfig):
6465
# prevent empty string
6566
if _asm_static_rule_file == "":
6667
_asm_static_rule_file = None
68+
_asm_processed_span_types = {SpanTypes.WEB, SpanTypes.GRPC}
6769
_iast_enabled = tracer_config._from_endpoint.get("iast_enabled", DDConfig.var(bool, IAST.ENV, default=False))
6870
_iast_request_sampling = DDConfig.var(float, IAST.ENV_REQUEST_SAMPLING, default=30.0)
6971
_iast_debug = DDConfig.var(bool, IAST.ENV_DEBUG, default=False, private=True)
@@ -224,9 +226,20 @@ class ASMConfig(DDConfig):
224226

225227
def __init__(self):
226228
super().__init__()
229+
230+
if in_aws_lambda():
231+
self._asm_processed_span_types.add(SpanTypes.SERVERLESS)
232+
233+
# As a first step, only Threat Management in monitoring mode should be enabled in AWS Lambda
234+
tracer_config._remote_config_enabled = False
235+
self._api_security_enabled = False
236+
self._ep_enabled = False
237+
self._iast_supported = False
238+
227239
if not self._iast_supported:
228240
self._iast_enabled = False
229-
if not self._asm_libddwaf_available or in_aws_lambda():
241+
242+
if not self._asm_libddwaf_available:
230243
self._asm_enabled = False
231244
self._asm_can_be_enabled = False
232245
self._iast_enabled = False

tests/appsec/architectures/test_appsec_loading_modules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_loading(appsec_enabled, iast_enabled, aws_lambda):
6363
for m in MODULES_ALWAYS_LOADED:
6464
assert m in data["appsec"], f"{m} not in {data['appsec']}"
6565
for m in MODULE_ASM_ONLY:
66-
if appsec_enabled == "true" and not aws_lambda:
66+
if appsec_enabled == "true":
6767
assert m in data["appsec"], f"{m} not in {data['appsec']} data:{data}"
6868
else:
6969
assert m not in data["appsec"], f"{m} in {data['appsec']} data:{data}"

0 commit comments

Comments
 (0)