Repository navigation
JULIO-18: tag AppSec invocation spans with the AWS access key ID - #887
Draft
Julio-Guerra wants to merge 3 commits into
Draft
Julio-Guerra wants to merge 3 commits into
Julio-Guerra wants to merge 3 commits into
Conversation
When DD_APPSEC_AWS_ACCESS_KEY_ID_TAG_ENABLED is true (default false) and
the wrapper's AppSec path runs (DD_APPSEC_ENABLED=true), asm_start_request
sets aws.lambda.access_key_id on the aws.lambda span of every monitored
HTTP invocation, before the WAF runs.
The value is AWS_ACCESS_KEY_ID only, read once per execution environment
at the first monitored invocation, used only on a full match of
(ASIA|AKIA)[A-Z0-9]{16}, and never logged. SnapStart functions get no tag.
The secret access key and the session token are never read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
Unit and wrapper tests for the LLD test specification (RFC "CADR for AWS Lambda" S1 to S9c, D1 to D7): every monitored HTTP event type, default off and kill switch, canary secret and token, validation and trailing newline, read once, SnapStart, non-HTTP triggers, tag set before the WAF, the real WAF on crs-930-120, extension-only AppSec, and both AppSec paths on. Adds a micro benchmark of asm_start_request with the feature off and on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
Use patch.dict so the wrapper tests put back any variable they set, and show the child stderr when the real-WAF test fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
When
DD_APPSEC_AWS_ACCESS_KEY_ID_TAG_ENABLED=true(default false) and the wrapper's AppSec path runs (DD_APPSEC_ENABLED=true),asm_start_requesttags theaws.lambdaspan of every AppSec-monitored HTTP invocation withaws.lambda.access_key_id. The value is the execution environment'sAWS_ACCESS_KEY_ID.datadog_lambda/config.py: newappsec_aws_access_key_id_tag_enabled, parsed withas_bool, default false. Environment variable only, never from Remote Configuration.datadog_lambda/asm.py: the value is read once per process, at the first monitored invocation rather than at import, and cached even when it is missing or invalid. It is used only on a full match of(ASIA|AKIA)[A-Z0-9]{16}, so a value with a trailing newline is rejected. It is never logged. SnapStart functions (AWS_LAMBDA_INITIALIZATION_TYPE=snap-start) are not read and not tagged, because their environment predates the snapshot. The tag is set before theaws_lambda.start_requestdispatch, so it is in place before the WAF runs.wrapper.py.Motivation
Cross-product correlation between AAP signals and CloudTrail activity needs a join key on the invocation span. The execution environment's access key ID stays the same for the environment's life, and CloudTrail records it as
userIdentity.accessKeyId. The feature is off by default because the tag is a credential identifier and has not passed the privacy review yet.When both AppSec paths could run: with the extension v102 wrapper or later,
DD_SERVERLESS_APPSEC_ENABLED=truemakes the wrapper exportDD_APPSEC_ENABLED=false, so this code path does not run and the extension writes the tag. If a custom exec wrapper keeps both paths on, this wrapper still tags, and the extension does not overwrite a value it finds. That extension behavior lands in its own PR.Testing Guidelines
pytest tests: 1043 passed locally (macOS arm64, Python 3.12.8, ddtrace 4.17.0). CI runs Python 3.8 to 3.14.tests/test_asm.py,tests/test_wrapper.pyandtests/test_config.pycover: every monitored HTTP event type (ALB single and multi-value headers, Function URL, API Gateway REST, HTTP and WebSocket); default off and the kill switch; canary secret and token absent from span meta, metrics and the AppSec event; empty, malformed and trailing-newline values (no tag, no log above debug); read once; SnapStart; other initialization types; no tag on SQS, SNS or EventBridge; the tag present at WAF dispatch; the real WAF oncrs-930-120in a fresh interpreter; AppSec off; extension-only AppSec; and both AppSec paths on.tests/test_benchmarks.py::test_asm_start_request_access_key_id, 20,000 rounds with GC off: median 11.71 µs with the feature off and 12.63 µs with it on, so about +0.9 µs per monitored invocation.black --check datadog_lambda/ tests(25.11.0) is clean.flake8on the changed source files is clean. On Python 3.12, flake8 5 still reports pre-existing E231 false positives in f-strings in files this PR does not touch.Additional Notes
aws.lambda.access_key_idstill has to be confirmed by the APM span-tag owners and the privacy review. It is defined in one place (asm.AWS_ACCESS_KEY_ID_TAG).Types of Changes
Check all that apply
🤖 Generated with Claude Code