Skip to content

Commit 355b7d6

Browse files
committed
wip move to communication via sidecar
1 parent a52b578 commit 355b7d6

197 files changed

Lines changed: 2206 additions & 23397 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ appsec-trigger:
8282
strategy: depend
8383
variables:
8484
PARENT_PIPELINE_ID: $CI_PIPELINE_ID
85-
GIT_SUBMODULE_PATHS: libdatadog appsec/third_party/cpp-base64 appsec/third_party/libddwaf appsec/third_party/libddwaf-rust appsec/third_party/msgpack-c
85+
GIT_SUBMODULE_PATHS: libdatadog appsec/third_party/libddwaf-rust
8686

8787
profiler-trigger:
8888
stage: tests
@@ -119,7 +119,7 @@ package-trigger:
119119
pipeline_variables: true
120120
variables:
121121
PARENT_PIPELINE_ID: $CI_PIPELINE_ID
122-
GIT_SUBMODULE_PATHS: libdatadog appsec/third_party/cpp-base64 appsec/third_party/libddwaf appsec/third_party/libddwaf-rust appsec/third_party/msgpack-c
122+
GIT_SUBMODULE_PATHS: libdatadog appsec/third_party/libddwaf-rust
123123
NIGHTLY_BUILD: $NIGHTLY_BUILD
124124

125125
# Runs after the full CI completes. Triggered in two situations:

.gitlab/build-appsec-helper-rust.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cargo +nightly-"$RUST_TARGET" build \
2222
--target "$RUST_TARGET"
2323

2424
# Remove musl libc dependency using patchelf (makes binary work on both musl and glibc)
25-
BINARY_PATH="/tmp/cargo-target/$RUST_TARGET/release/libddappsec_helper_rust.so"
25+
BINARY_PATH="/tmp/cargo-target/$RUST_TARGET/release/libddappsec_helper.so"
2626
ARCH=$(uname -m)
2727
if [ "$ARCH" = "x86_64" ]; then
2828
patchelf --remove-needed libc.musl-x86_64.so.1 "$BINARY_PATH" 2>/dev/null || true
@@ -31,7 +31,8 @@ elif [ "$ARCH" = "aarch64" ]; then
3131
fi
3232

3333
# Copy to output
34-
cp -v "$BINARY_PATH" "../../appsec_$(uname -m)/libddappsec-helper-rust.so"
34+
cp -v "$BINARY_PATH" "../../appsec_$(uname -m)/libddappsec-helper.so"
35+
cp -v ../recommended.json "../../appsec_$(uname -m)/"
3536

3637
# Run tests
3738
cargo +nightly-"$RUST_TARGET" test \

.gitlab/build-appsec-helper.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

.gitlab/build-appsec.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ suffix="${1:-}"
1313
echo "Build nts extension"
1414
switch-php "${PHP_VERSION}"
1515
mkdir -p appsec/build ; cd appsec/build
16-
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDD_APPSEC_BUILD_HELPER=OFF \
17-
-DDD_APPSEC_TESTING=OFF -DDD_APPSEC_EXTENSION_STATIC_LIBSTDCXX=ON
16+
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDD_APPSEC_TESTING=OFF -DDD_APPSEC_EXTENSION_STATIC_LIBSTDCXX=ON
1817
make -j $MAKE_JOBS
1918
cp -v ddappsec.so "../../appsec_$(uname -m)/ddappsec-$PHP_API${suffix}.so"
2019
cd "../../"
2120

2221
echo "Build zts extension"
2322
switch-php "${PHP_VERSION}-zts"
2423
mkdir -p appsec/build-zts ; cd appsec/build-zts
25-
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDD_APPSEC_BUILD_HELPER=OFF \
26-
-DDD_APPSEC_TESTING=OFF -DDD_APPSEC_EXTENSION_STATIC_LIBSTDCXX=ON
24+
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDD_APPSEC_TESTING=OFF -DDD_APPSEC_EXTENSION_STATIC_LIBSTDCXX=ON
2725
make -j $MAKE_JOBS
2826
cp -v ddappsec.so "../../appsec_$(uname -m)/ddappsec-$PHP_API${suffix}-zts.so"
2927
cd "../../"

.gitlab/generate-appsec.php

Lines changed: 2 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
KUBERNETES_MEMORY_LIMIT: 30Gi
113113
DOCKER_LOOPBACK_SIZE: 30G
114114
ARCH: amd64
115-
HELPER_RUST_FLAG: ""
116115
GRADLE_USER_HOME: "$CI_PROJECT_DIR/.gradle-home"
117116
DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED: "0"
118117
before_script:
@@ -129,7 +128,7 @@
129128
TERM=dumb ./gradlew loadCaches --info
130129
fi
131130

132-
TERM=dumb ./gradlew $targets --info -Pbuildscan --scan -PcheckCoreDumps $HELPER_RUST_FLAG
131+
TERM=dumb ./gradlew $targets --info -Pbuildscan --scan -PcheckCoreDumps
133132
TERM=dumb ./gradlew saveCaches --info
134133
after_script:
135134
- mkdir -p "${CI_PROJECT_DIR}/artifacts"
@@ -183,17 +182,6 @@
183182
- targets:
184183
- test8.3-release-ssi
185184

186-
"appsec integration tests (helper-rust)":
187-
extends: .appsec_integration_tests
188-
variables:
189-
HELPER_RUST_FLAG: "-PuseHelperRust"
190-
parallel:
191-
matrix:
192-
- targets:
193-
- test7.4-release
194-
- test8.1-release
195-
- test8.3-debug
196-
197185
"helper-rust build and test":
198186
stage: test
199187
image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/docker:29.4.0-noble
@@ -419,11 +407,6 @@
419407
export PATH=$PATH:$HOME/.cargo/bin
420408
LLVM_PROFILE_FILE="/tmp/cov-ext/%p.profraw" \
421409
VERBOSE=1 make -j 4 xtest
422-
- VERBOSE=1 make -j 4 ddappsec_helper_test
423-
- |
424-
cd ../..
425-
LLVM_PROFILE_FILE="/tmp/cov-helper/%p.profraw" \
426-
./appsec/build/tests/helper/ddappsec_helper_test
427410
- |
428411
cd /tmp/cov-ext
429412
llvm-profdata-17 merge -sparse *.profraw -o default.profdata
@@ -433,15 +416,6 @@
433416
echo "Uploading extension coverage to codecov"
434417
cd "$CI_PROJECT_DIR"
435418
codecov -t "$CODECOV_TOKEN" -n appsec-extension -v -f appsec/build/coverage-ext.lcov
436-
- |
437-
cd /tmp/cov-helper
438-
llvm-profdata-17 merge -sparse *.profraw -o default.profdata
439-
llvm-cov-17 export "$CI_PROJECT_DIR"/appsec/build/tests/helper/ddappsec_helper_test \
440-
-format=lcov -instr-profile=default.profdata \
441-
> "$CI_PROJECT_DIR/appsec/build/coverage-helper.lcov"
442-
echo "Uploading helper coverage to codecov"
443-
cd "$CI_PROJECT_DIR"
444-
codecov -t "$CODECOV_TOKEN" -n appsec-helper -v -f appsec/build/coverage-helper.lcov
445419
- |
446420
echo "Uploading coverage to Datadog"
447421
cd "$CI_PROJECT_DIR"
@@ -515,84 +489,9 @@
515489
-DBOOST_CACHE_PREFIX="$CI_PROJECT_DIR/boost-cache" \
516490
-DCLANG_TIDY=/usr/bin/run-clang-tidy-17 \
517491
-DCLANG_FORMAT=/usr/bin/clang-format-17
518-
- make -j 4 extension ddappsec-helper
492+
- make -j 4 extension
519493
- make format tidy
520494

521-
"test appsec helper asan":
522-
stage: test
523-
extends: .appsec_test
524-
image: registry.ddbuild.io/images/mirror/datadog/dd-trace-ci:bookworm-6
525-
variables:
526-
KUBERNETES_CPU_REQUEST: 3
527-
KUBERNETES_MEMORY_REQUEST: 3Gi
528-
KUBERNETES_MEMORY_LIMIT: 4Gi
529-
parallel:
530-
matrix:
531-
- ARCH: *arch_targets
532-
script:
533-
- cd appsec/build
534-
- |
535-
cmake .. -DCMAKE_BUILD_TYPE=Debug -DDD_APPSEC_BUILD_EXTENSION=OFF \
536-
-DDD_APPSEC_ENABLE_COVERAGE=OFF -DDD_APPSEC_TESTING=ON \
537-
-DCMAKE_CXX_FLAGS="-stdlib=libc++ -fsanitize=address -fsanitize=leak \
538-
-DASAN_BUILD" -DCMAKE_C_FLAGS="-fsanitize=address -fsanitize=leak \
539-
-DASAN_BUILD" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address -fsanitize=leak" \
540-
-DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=address -fsanitize=leak" \
541-
-DBOOST_CACHE_PREFIX="$CI_PROJECT_DIR/boost-cache" \
542-
-DCLANG_TIDY=/usr/bin/run-clang-tidy-17
543-
- make -j 4 ddappsec_helper_test
544-
- cd ../..; ./appsec/build/tests/helper/ddappsec_helper_test
545-
546-
### Disabled: "we don't rely on the fuzzer these days as the protocol has been stable for a long time, so feel free to disable those jobs for now"
547-
#"fuzz appsec helper":
548-
# stage: test
549-
# extends: .appsec_test
550-
# image: registry.ddbuild.io/images/mirror/datadog/dd-trace-ci:bookworm-6
551-
# variables:
552-
# KUBERNETES_CPU_REQUEST: 3
553-
# KUBERNETES_MEMORY_REQUEST: 5Gi
554-
# KUBERNETES_MEMORY_LIMIT: 6Gi
555-
# parallel:
556-
# matrix:
557-
# - ARCH: *arch_targets
558-
# script:
559-
# - curl -LO https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-17.0.6.tar.gz
560-
# - tar xzf llvmorg-17.0.6.tar.gz
561-
# - cd llvm-project-llvmorg-17.0.6/compiler-rt
562-
# - cmake . -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_CXX_LINK_FLAGS="-stdlib=libc++"
563-
# - make -j 4 fuzzer
564-
# - fuzzer=$(realpath lib/linux/libclang_rt.fuzzer_no_main-*.a)
565-
# - cd -
566-
#
567-
# - cd appsec/build
568-
# - cmake .. -DCMAKE_BUILD_TYPE=Debug -DDD_APPSEC_BUILD_EXTENSION=OFF -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_CXX_LINK_FLAGS="-stdlib=libc++" -DFUZZER_ARCHIVE_PATH=$fuzzer -DBOOST_CACHE_PREFIX=/boost-cache -DCLANG_TIDY=/usr/bin/run-clang-tidy-17
569-
# - make -j 4 ddappsec_helper_fuzzer corpus_generator
570-
# - cd ..
571-
# - mkdir -p tests/fuzzer/{corpus,results,logs}
572-
# - rm -f tests/fuzzer/corpus/*
573-
#
574-
# - '# Run fuzzer in nop mode'
575-
# - ./build/tests/fuzzer/corpus_generator tests/fuzzer/corpus 500
576-
# - LLVM_PROFILE_FILE=off.profraw ./build/tests/fuzzer/ddappsec_helper_fuzzer --log_level=off --fuzz-mode=off -max_total_time=60 -rss_limit_mb=4096 -artifact_prefix=tests/fuzzer/results/ tests/fuzzer/corpus/
577-
# - rm -f tests/fuzzer/corpus/*
578-
#
579-
# - '# Run fuzzer in raw mode'
580-
# - ./build/tests/fuzzer/corpus_generator tests/fuzzer/corpus 500
581-
# - LLVM_PROFILE_FILE=raw.profraw ./build/tests/fuzzer/ddappsec_helper_fuzzer --log_level=off --fuzz-mode=raw -max_total_time=60 -rss_limit_mb=4096 -artifact_prefix=tests/fuzzer/results/ tests/fuzzer/corpus/
582-
# - rm -f tests/fuzzer/corpus/*
583-
#
584-
# - '# Run fuzzer in body mode'
585-
# - ./build/tests/fuzzer/corpus_generator tests/fuzzer/corpus 500
586-
# - LLVM_PROFILE_FILE=body.profraw ./build/tests/fuzzer/ddappsec_helper_fuzzer --log_level=off --fuzz-mode=body -max_total_time=60 -rss_limit_mb=4096 -artifact_prefix=tests/fuzzer/results/ tests/fuzzer/corpus/
587-
#
588-
# - '# Generate coverage'
589-
# - llvm-profdata-17 merge -sparse *.profraw -o default.profdata
590-
# - llvm-cov-17 show build/tests/fuzzer/ddappsec_helper_fuzzer -instr-profile=default.profdata -ignore-filename-regex="(tests|third_party|build)" -format=html > fuzzer-coverage.html
591-
# - llvm-cov-17 report -instr-profile default.profdata build/tests/fuzzer/ddappsec_helper_fuzzer -ignore-filename-regex="(tests|third_party|build)" -show-region-summary=false
592-
# artifacts:
593-
# paths:
594-
# - appsec/fuzzer-coverage.html
595-
596495
"check libxml2 version":
597496
stage: test
598497
image: registry.ddbuild.io/images/mirror/python:3.12-slim-bullseye

.gitlab/generate-package.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -283,24 +283,6 @@
283283
}
284284
?>
285285

286-
"compile appsec helper":
287-
stage: appsec
288-
image: "registry.ddbuild.io/images/mirror/b1o7r7e0/nginx_musl_toolchain"
289-
tags: [ "arch:$ARCH" ]
290-
needs: [ "prepare code" ]
291-
parallel:
292-
matrix:
293-
- ARCH: ["amd64", "arm64" ]
294-
variables:
295-
MAKE_JOBS: 12
296-
KUBERNETES_CPU_REQUEST: 12
297-
KUBERNETES_MEMORY_REQUEST: 4Gi
298-
KUBERNETES_MEMORY_LIMIT: 8Gi
299-
script: .gitlab/build-appsec-helper.sh
300-
artifacts:
301-
paths:
302-
- "appsec_*"
303-
304286
"compile appsec helper rust":
305287
stage: appsec
306288
image: "registry.ddbuild.io/images/mirror/datadog/dd-appsec-php-ci:nginx-fpm-php-8.5-release-musl"
@@ -631,13 +613,6 @@
631613
}
632614
?>
633615

634-
# Compile appsec helper (C++)
635-
- job: "compile appsec helper"
636-
parallel:
637-
matrix:
638-
- ARCH: "<?= $platform['arch'] ?>"
639-
artifacts: true
640-
641616
# Compile appsec helper (Rust)
642617
- job: "compile appsec helper rust"
643618
parallel:
@@ -710,11 +685,6 @@
710685
needs:
711686
- job: "prepare code"
712687
artifacts: true
713-
- job: "compile appsec helper"
714-
parallel:
715-
matrix:
716-
- ARCH: "<?= $arch ?>"
717-
artifacts: true
718688
- job: "compile appsec helper rust"
719689
parallel:
720690
matrix:

.gitmodules

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22
path = libdatadog
33
url = https://github.com/DataDog/libdatadog
44
branch = main
5-
[submodule "appsec/third_party/cpp-base64"]
6-
path = appsec/third_party/cpp-base64
7-
url = https://github.com/ReneNyffenegger/cpp-base64
8-
[submodule "appsec/third_party/msgpack-c"]
9-
path = appsec/third_party/msgpack-c
10-
url = https://github.com/msgpack/msgpack-c.git
11-
[submodule "appsec/third_party/libddwaf"]
12-
path = appsec/third_party/libddwaf
13-
url = https://github.com/DataDog/libddwaf.git
145
[submodule "tea/benchmarks/google-benchmark"]
156
path = tea/benchmarks/google-benchmark
167
url = https://github.com/google/benchmark.git

Makefile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,16 @@ delete_ini:
148148
$(SUDO) rm $(INI_FILE)
149149

150150
install_appsec:
151-
cmake -S $(APPSEC_SOURCE_DIR) -B $(BUILD_DIR_APPSEC)
152-
cd $(BUILD_DIR_APPSEC);make extension ddappsec-helper
153-
cp $(BUILD_DIR_APPSEC)/ddappsec.so $(PHP_EXTENSION_DIR)/ddappsec.so
154-
cp $(BUILD_DIR_APPSEC)/libddappsec-helper.so $(PHP_EXTENSION_DIR)/libddappsec-helper.so
151+
cmake -S $(APPSEC_SOURCE_DIR) -DCMAKE_BUILD_TYPE=RelWithDebInfo -B $(BUILD_DIR_APPSEC)
152+
$(MAKE) -C $(BUILD_DIR_APPSEC) extension
153+
cp -v $(BUILD_DIR_APPSEC)/ddappsec.so $(PHP_EXTENSION_DIR)/ddappsec.so
154+
cd $(APPSEC_SOURCE_DIR)/helper-rust; cargo build --release
155+
cp $(APPSEC_SOURCE_DIR)/helper-rust/target/release/libddappsec_helper.so $(PHP_EXTENSION_DIR)/libddappsec-helper.so
155156
cp $(APPSEC_SOURCE_DIR)/recommended.json /tmp/recommended.json
156157
$(Q) echo "extension=ddappsec.so" | $(SUDO) tee -a $(INI_FILE)
157158
$(Q) echo "datadog.appsec.cli_start_on_rinit=true" | $(SUDO) tee -a $(INI_FILE)
158159
$(Q) echo "datadog.appsec.helper_path=$(PHP_EXTENSION_DIR)/libddappsec-helper.so" | $(SUDO) tee -a $(INI_FILE)
159160
$(Q) echo "datadog.appsec.rules=/tmp/recommended.json" | $(SUDO) tee -a $(INI_FILE)
160-
$(Q) echo "datadog.appsec.helper_socket_path=/tmp/ddappsec.sock" | $(SUDO) tee -a $(INI_FILE)
161-
$(Q) echo "datadog.appsec.helper_lock_path=/tmp/ddappsec.lock" | $(SUDO) tee -a $(INI_FILE)
162161
$(Q) echo "datadog.appsec.log_file=/tmp/logs/appsec.log" | $(SUDO) tee -a $(INI_FILE)
163162
$(Q) echo "datadog.appsec.helper_log_file=/tmp/logs/helper.log" | $(SUDO) tee -a $(INI_FILE)
164163

appsec/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ if(DD_APPSEC_BUILD_EXTENSION)
5959
endif()
6060

6161
if(DD_APPSEC_BUILD_HELPER)
62-
include ("cmake/helper.cmake")
6362
find_program(CARGO_EXECUTABLE cargo)
6463
find_program(RUSTC_EXECUTABLE rustc)
6564
if(CARGO_EXECUTABLE AND RUSTC_EXECUTABLE)

appsec/README.md

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,11 @@ cd build
7474
cmake ..
7575
make -j
7676
```
77-
This will produce the extension, `ddappsec.so` and the helper library `libddappsec-helper.so`.
77+
This will produce the extension, `ddappsec.so`.
7878
79-
Alternatively, to build the extension but not the helper, you can disable the helper build on the cmake step:
79+
To skip building the extension (e.g. to only run linting), you can disable it on the cmake step:
8080
```
81-
cmake .. -DDD_APPSEC_BUILD_HELPER=OFF
82-
```
83-
Similarly, to build the helper but not the extension:
84-
```
85-
cmake .. DDD_APPSEC_BUILD_EXTENSION=OFF
81+
cmake .. -DDD_APPSEC_BUILD_EXTENSION=OFF
8682
```
8783
8884
#### Testing the extension
@@ -101,27 +97,11 @@ make xtest TESTS="--show-diff --show-mem -m"
10197
```
10298
#### Testing the helper
10399
104-
Helper tests can be located in the `dd-appsec-php/tests/helper` directory, these consist of a set of C++ unit tests written using Google Test and Mock. To build the helper tests, run the following command in the build directory:
105-
```
106-
make ddappsec_helper_test
107-
```
108-
And run the tests by executing the following command, again from the build directory:
109-
```
110-
./tests/helper/ddappsec_helper_test
111-
```
112-
To test the helper with the address and leak sanitizer, you will need to execute the cmake step with a few other options as shown below (note that it's not strictly necessary to disable the extension):
113-
```
114-
cmake .. -DCMAKE_BUILD_TYPE=Debug -DDD_APPSEC_BUILD_EXTENSION=OFF \
115-
-DCMAKE_CXX_FLAGS="-fsanitize=address -fsanitize=leak -DASAN_BUILD" \
116-
-DCMAKE_C_FLAGS="-fsanitize=address -fsanitize=leak -DASAN_BUILD" \
117-
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address -fsanitize=leak" \
118-
-DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=address -fsanitize=leak"
119-
```
120-
After this step has concluded, build and run the helper test as before, if the sanitisers detect anything of relevance, extra output will be produced.
100+
The helper is implemented in Rust and lives in the `helper-rust/` directory. See `helper-rust/CLAUDE.md` for build and test instructions.
121101
122102
### Linting
123103
124-
As part of our workflow, we use `clang-tidy` to lint both the extension and helper, in order to enable it add `-DDD_APPSEC_ENABLE_CLANG_TIDY=ON` to the cmake step and after building you should be able to lint by running `make tidy`.
104+
As part of our workflow, we use `clang-tidy` to lint the extension. To enable it, add `-DDD_APPSEC_ENABLE_CLANG_TIDY=ON` to the cmake step and after building you should be able to lint by running `make tidy`.
125105
126106
## Contributing
127107

0 commit comments

Comments
 (0)