Repository navigation
Conversation
ava-silver
left a comment
There was a problem hiding this comment.
Automated AI Review (human curated)
Left a few inline comments on simplifying the Java branch in src/env.ts (avoiding src/env-tracker.ts changes and preserving redirectHandler: false), removing the unexecuted Python test script, and adding end-to-end validation evidence once Java layer v31 is published.
| ) { | ||
| setEnvIfUnset(ENABLE_DD_APPSEC_ENV_VAR, "true"); | ||
| if (runtimeType === RuntimeType.JAVA) { | ||
| setEnvIfUnset(AWS_LAMBDA_EXEC_WRAPPER_KEY, AWS_LAMBDA_EXEC_WRAPPER_VAL); |
There was a problem hiding this comment.
Setting AWS_LAMBDA_EXEC_WRAPPER here breaks redirectHandler: false for Java tracer-based AppSec.
When redirectHandler is true (the default), redirectHandlers in src/redirect.ts already sets AWS_LAMBDA_EXEC_WRAPPER=/opt/datadog_wrapper whenever useExtension is true -- and validateProps in src/datadog-lambda.ts already enforces that extensionLayerVersion or extensionLayerArn is set whenever AppSec is enabled. So this line only takes effect when a user explicitly sets redirectHandler: false, clobbering setups where they opt out of the Datadog wrapper (for example, configuring -javaagent via JAVA_TOOL_OPTIONS or setting a custom wrapper via fn.addEnvironment).
Python tracer AppSec respects redirectHandler: false; Java should too by dropping this line.
| // Explicit extension configuration takes precedence over automatic tracer selection. | ||
| const extensionEnabled = /^(1|t|true)$/i.test(getTrackedEnv(lam, ENABLE_DD_SERVERLESS_APPSEC_ENV_VAR) ?? ""); | ||
| if (!extensionEnabled) { | ||
| setEnvIfUnset(ENABLE_DD_APPSEC_ENV_VAR, "true"); | ||
| setEnvIfUnset(ENABLE_DD_SERVERLESS_APPSEC_ENV_VAR, "false"); | ||
| } |
There was a problem hiding this comment.
Do we need this Java-only branch or getTrackedEnv in src/env-tracker.ts?
Unlike datadog-ci (which mutates existing remote Lambda state), CDK synthesizes CloudFormation templates declaratively from scratch, and src/env.ts is the only place DD_SERVERLESS_APPSEC_ENABLED is written. Writing DD_SERVERLESS_APPSEC_ENABLED="false" on every Java tracer-AppSec function:
- Diverges from Python (which only sets
DD_APPSEC_ENABLED="true") and sets both AppSec env vars on every fresh Java Lambda. - Forces adding
getTrackedEnvtosrc/env-tracker.ts(which only exists to avoid readingaws-cdk-lib's privateFunction.environmentfield forsetEnvIfUnset, not to inspect sibling env var values). - Silently suppresses explicit
datadogAppSecMode: DatadogAppSecMode.TRACERas well asONwhenDD_SERVERLESS_APPSEC_ENABLEDis tracked as truthy (even though the comment mentions only automatic selection).
If Java follows the same path as Python -- collapsing lines 149-159 down to setEnvIfUnset(ENABLE_DD_APPSEC_ENV_VAR, "true") -- we keep both runtimes consistent, respect redirectHandler: false, and don't need to touch src/env-tracker.ts.
| """Run against an installed local Python wheel; synthesizes only, never deploys. | ||
|
|
||
| After building and installing the wheel in a virtual environment, run: | ||
| python integration_tests/java_appsec_python.py | ||
| """ |
There was a problem hiding this comment.
Nothing in .github/workflows/tests.yml or scripts/run_integration_tests.sh executes this file (run_integration_tests.sh only synthesizes stacks listed in STACK_CONFIG_PATHS under integration_tests/stacks/ against integration_tests/snapshots/), so it will rot over time.
Since Python bindings are generated from TypeScript via JSII and test/java-appsec.spec.ts already covers the behavior, consider removing this script -- or, if Python JSII coverage for Java AppSec is desired, adding it to the existing snapshot harness under integration_tests/stacks/python/ and scripts/run_integration_tests.sh.
| const javaTracerSupported = | ||
| runtimeType === RuntimeType.JAVA && | ||
| (baseProps.javaLayerVersion ?? 0) >= 31 && | ||
| (baseProps.extensionLayerVersion ?? 0) >= 102; |
There was a problem hiding this comment.
Per the PR description, Java layer v31 is still pending release and no AWS resources have been deployed yet. I'd like to see end-to-end validation with the published v31 layer (for example, the resulting Lambda config and telemetry showing client_tracer_based:true) documented in the PR description before approving.
What does this PR do?
Enable tracer-based App and API Protection for Java Lambda functions. With
datadogAppSecMode: ON, select the tracer whenjavaLayerVersion >= 31andextensionLayerVersion >= 102; otherwise retain extension mode. ExplicitTRACERselects tracer mode without version checks, matching Python behavior.Disable extension AppSec when enabling the Java tracer, while preserving explicit AppSec environment overrides, including extension enablement. Configure the Java execution wrapper even when handler redirection is disabled. Preserve existing Python and legacy extension behavior, and document Java support in the README.
Motivation
Support Java Lambda AppSec onboarding through the existing CDK options and automatically select tracer mode as customers upgrade their configured layers.
Testing Guidelines
Additional Notes
Do not merge until Java layer 31 is published with tracer 1.69.0+ and end-to-end onboarding validation passes.
Types of Changes
Check all that apply