Skip to content

Commit df43587

Browse files
authored
Merge pull request #3780 from DataDog/glopes/helper-on-85
Enable rust helper on PHP 8.5
2 parents 5017ea1 + 781d419 commit df43587

7 files changed

Lines changed: 52 additions & 3 deletions

File tree

.gitlab/generate-appsec.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@
191191
- test8.1-release
192192
- test8.3-debug
193193
- test8.4-release-zts
194-
- test8.5-release-musl
195194

196195
"helper-rust build and test":
197196
stage: test

appsec/src/extension/configuration.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ extern bool runtime_config_first_init;
2828

2929
#define DD_BASE(path) "/opt/datadog-php/" path
3030

31+
#if PHP_VERSION_ID >= 80500
32+
#define DD_APPSEC_HELPER_RUST_REDIRECTION_DEFAULT "true"
33+
#else
3134
#define DD_APPSEC_HELPER_RUST_REDIRECTION_DEFAULT "false"
35+
#endif
3236

3337
// clang-format off
3438
#define DD_CONFIGURATION_GENERAL \

appsec/tests/integration/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,9 @@ def runMainTask = { String phpVersion, String variant ->
639639
dependsOn 'buildHelperRustWithCoverage'
640640
} else if (project.hasProperty('useHelperRust')) {
641641
dependsOn 'buildHelperRust'
642+
} else if (phpVersion == '8.5') {
643+
// PHP 8.5+ uses Rust helper by default via DD_APPSEC_HELPER_RUST_REDIRECTION
644+
dependsOn 'buildHelperRust'
642645
}
643646
}
644647
}
@@ -710,6 +713,9 @@ def runMainTask = { String phpVersion, String variant ->
710713
dependsOn 'buildHelperRustWithCoverage'
711714
} else if (project.hasProperty('useHelperRust')) {
712715
dependsOn 'buildHelperRust'
716+
} else if (phpVersion == '8.5') {
717+
// PHP 8.5+ uses Rust helper by default via DD_APPSEC_HELPER_RUST_REDIRECTION
718+
dependsOn 'buildHelperRust'
713719
}
714720

715721
if (phpVersion in ['7.0', '7.1']) {

appsec/tests/integration/src/main/groovy/com/datadog/appsec/php/docker/AppSecContainer.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,11 @@ class AppSecContainer<SELF extends AppSecContainer<SELF>> extends GenericContain
491491
}
492492
}
493493
withEnv 'USE_HELPER_RUST', '1'
494+
} else {
495+
// Mount helper-rust volume so enable_extensions.sh can copy the binary
496+
// for the redirection mechanism (DD_APPSEC_HELPER_RUST_REDIRECTION
497+
// defaults to true on PHP 8.5+)
498+
addVolumeMount('php-helper-rust', '/helper-rust')
494499
}
495500

496501
String fullWorkVolume = "php-workvol-$workVolume-$phpVersion-$phpVariant"

appsec/tests/integration/src/test/bin/enable_extensions.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ HELPER_PATH=/appsec/libddappsec-helper.so
1111
if [[ -n $USE_HELPER_RUST ]]; then
1212
echo "Using Rust helper" >&2
1313
HELPER_PATH=/helper-rust/libddappsec-helper.so
14+
elif [[ -f /helper-rust/libddappsec-helper.so ]]; then
15+
# Copy Rust helper for the redirection mechanism
16+
# (DD_APPSEC_HELPER_RUST_REDIRECTION defaults to true on PHP >= 8.5)
17+
ln -sf /helper-rust/libddappsec-helper.so \
18+
"$(dirname "$HELPER_PATH")/libddappsec-helper-rust.so"
1419
fi
1520

1621
if [[ -n $USE_SSI ]]; then

appsec/tests/integration/src/test/groovy/com/datadog/appsec/php/integration/CommonTests.groovy

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,4 +863,34 @@ trait CommonTests {
863863
assert span.metrics."_dd.appsec.trace.integer" == 1729
864864
assert span.meta."_dd.appsec.trace.agent" == "TraceTagging/v4"
865865
}
866+
867+
@Test
868+
void 'helper runtime default matches PHP version'() {
869+
// This test verifies the default helper selection; skip when explicitly overridden
870+
org.junit.jupiter.api.Assumptions.assumeTrue(
871+
System.getProperty('USE_HELPER_RUST') == null,
872+
'Skipped: helper explicitly overridden via -PuseHelperRust')
873+
874+
def trace = container.traceFromRequest('/phpinfo.php') { HttpResponse<InputStream> resp ->
875+
assert resp.statusCode() == 200
876+
def content = resp.body().text
877+
878+
if (TestParams.phpVersionAtLeast('8.5')) {
879+
assert content.contains('Yes (Rust)') :
880+
"PHP >= 8.5 should use Rust helper by default"
881+
} else {
882+
assert content.contains('Yes (C++)') :
883+
"PHP < 8.5 should use C++ helper by default"
884+
}
885+
}
886+
887+
Span span = trace.first()
888+
if (TestParams.phpVersionAtLeast('8.5')) {
889+
assert span.meta."_dd.appsec.helper_runtime" == 'rust' :
890+
"PHP >= 8.5 should report helper_runtime=rust in span"
891+
} else {
892+
assert span.meta."_dd.appsec.helper_runtime" == null :
893+
"PHP < 8.5 should not set helper_runtime span tag"
894+
}
895+
}
866896
}

metadata/supported-configurations.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@
104104
],
105105
"DD_APPSEC_HELPER_RUST_REDIRECTION": [
106106
{
107-
"implementation": "A",
107+
"implementation": "B",
108108
"type": "boolean",
109-
"default": "false"
109+
"default": "true"
110110
}
111111
],
112112
"DD_APPSEC_HTTP_BLOCKED_TEMPLATE_HTML": [

0 commit comments

Comments
 (0)