Skip to content

Commit 1238aea

Browse files
committed
wip move to communication via sidecar
1 parent 7bb186d commit 1238aea

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
@@ -57,7 +57,7 @@ appsec-trigger:
5757
strategy: depend
5858
variables:
5959
PARENT_PIPELINE_ID: $CI_PIPELINE_ID
60-
GIT_SUBMODULE_PATHS: libdatadog appsec/third_party/cpp-base64 appsec/third_party/libddwaf appsec/third_party/libddwaf-rust appsec/third_party/msgpack-c
60+
GIT_SUBMODULE_PATHS: libdatadog appsec/third_party/libddwaf-rust
6161

6262
profiler-trigger:
6363
stage: tests
@@ -94,5 +94,5 @@ package-trigger:
9494
pipeline_variables: true
9595
variables:
9696
PARENT_PIPELINE_ID: $CI_PIPELINE_ID
97-
GIT_SUBMODULE_PATHS: libdatadog appsec/third_party/cpp-base64 appsec/third_party/libddwaf appsec/third_party/libddwaf-rust appsec/third_party/msgpack-c
97+
GIT_SUBMODULE_PATHS: libdatadog appsec/third_party/libddwaf-rust
9898
NIGHTLY_BUILD: $NIGHTLY_BUILD

.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
@@ -111,7 +111,6 @@
111111
KUBERNETES_MEMORY_LIMIT: 30Gi
112112
DOCKER_LOOPBACK_SIZE: 30G
113113
ARCH: amd64
114-
HELPER_RUST_FLAG: ""
115114
GRADLE_USER_HOME: "$CI_PROJECT_DIR/.gradle-home"
116115
DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED: "0"
117116
before_script:
@@ -128,7 +127,7 @@
128127
TERM=dumb ./gradlew loadCaches --info
129128
fi
130129

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

185-
"appsec integration tests (helper-rust)":
186-
extends: .appsec_integration_tests
187-
variables:
188-
HELPER_RUST_FLAG: "-PuseHelperRust"
189-
parallel:
190-
matrix:
191-
- targets:
192-
- test7.4-release
193-
- test8.1-release
194-
- test8.3-debug
195-
196184
"helper-rust build and test":
197185
stage: test
198186
image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/docker:29.4.0-noble
@@ -418,11 +406,6 @@
418406
export PATH=$PATH:$HOME/.cargo/bin
419407
LLVM_PROFILE_FILE="/tmp/cov-ext/%p.profraw" \
420408
VERBOSE=1 make -j 4 xtest
421-
- VERBOSE=1 make -j 4 ddappsec_helper_test
422-
- |
423-
cd ../..
424-
LLVM_PROFILE_FILE="/tmp/cov-helper/%p.profraw" \
425-
./appsec/build/tests/helper/ddappsec_helper_test
426409
- |
427410
cd /tmp/cov-ext
428411
llvm-profdata-17 merge -sparse *.profraw -o default.profdata
@@ -432,15 +415,6 @@
432415
echo "Uploading extension coverage to codecov"
433416
cd "$CI_PROJECT_DIR"
434417
codecov -t "$CODECOV_TOKEN" -n appsec-extension -v -f appsec/build/coverage-ext.lcov
435-
- |
436-
cd /tmp/cov-helper
437-
llvm-profdata-17 merge -sparse *.profraw -o default.profdata
438-
llvm-cov-17 export "$CI_PROJECT_DIR"/appsec/build/tests/helper/ddappsec_helper_test \
439-
-format=lcov -instr-profile=default.profdata \
440-
> "$CI_PROJECT_DIR/appsec/build/coverage-helper.lcov"
441-
echo "Uploading helper coverage to codecov"
442-
cd "$CI_PROJECT_DIR"
443-
codecov -t "$CODECOV_TOKEN" -n appsec-helper -v -f appsec/build/coverage-helper.lcov
444418
- |
445419
echo "Uploading coverage to Datadog"
446420
cd "$CI_PROJECT_DIR"
@@ -514,84 +488,9 @@
514488
-DBOOST_CACHE_PREFIX="$CI_PROJECT_DIR/boost-cache" \
515489
-DCLANG_TIDY=/usr/bin/run-clang-tidy-17 \
516490
-DCLANG_FORMAT=/usr/bin/clang-format-17
517-
- make -j 4 extension ddappsec-helper
491+
- make -j 4 extension
518492
- make format tidy
519493

520-
"test appsec helper asan":
521-
stage: test
522-
extends: .appsec_test
523-
image: registry.ddbuild.io/images/mirror/datadog/dd-trace-ci:bookworm-6
524-
variables:
525-
KUBERNETES_CPU_REQUEST: 3
526-
KUBERNETES_MEMORY_REQUEST: 3Gi
527-
KUBERNETES_MEMORY_LIMIT: 4Gi
528-
parallel:
529-
matrix:
530-
- ARCH: *arch_targets
531-
script:
532-
- cd appsec/build
533-
- |
534-
cmake .. -DCMAKE_BUILD_TYPE=Debug -DDD_APPSEC_BUILD_EXTENSION=OFF \
535-
-DDD_APPSEC_ENABLE_COVERAGE=OFF -DDD_APPSEC_TESTING=ON \
536-
-DCMAKE_CXX_FLAGS="-stdlib=libc++ -fsanitize=address -fsanitize=leak \
537-
-DASAN_BUILD" -DCMAKE_C_FLAGS="-fsanitize=address -fsanitize=leak \
538-
-DASAN_BUILD" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address -fsanitize=leak" \
539-
-DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=address -fsanitize=leak" \
540-
-DBOOST_CACHE_PREFIX="$CI_PROJECT_DIR/boost-cache" \
541-
-DCLANG_TIDY=/usr/bin/run-clang-tidy-17
542-
- make -j 4 ddappsec_helper_test
543-
- cd ../..; ./appsec/build/tests/helper/ddappsec_helper_test
544-
545-
### 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"
546-
#"fuzz appsec helper":
547-
# stage: test
548-
# extends: .appsec_test
549-
# image: registry.ddbuild.io/images/mirror/datadog/dd-trace-ci:bookworm-6
550-
# variables:
551-
# KUBERNETES_CPU_REQUEST: 3
552-
# KUBERNETES_MEMORY_REQUEST: 5Gi
553-
# KUBERNETES_MEMORY_LIMIT: 6Gi
554-
# parallel:
555-
# matrix:
556-
# - ARCH: *arch_targets
557-
# script:
558-
# - curl -LO https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-17.0.6.tar.gz
559-
# - tar xzf llvmorg-17.0.6.tar.gz
560-
# - cd llvm-project-llvmorg-17.0.6/compiler-rt
561-
# - cmake . -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_CXX_LINK_FLAGS="-stdlib=libc++"
562-
# - make -j 4 fuzzer
563-
# - fuzzer=$(realpath lib/linux/libclang_rt.fuzzer_no_main-*.a)
564-
# - cd -
565-
#
566-
# - cd appsec/build
567-
# - 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
568-
# - make -j 4 ddappsec_helper_fuzzer corpus_generator
569-
# - cd ..
570-
# - mkdir -p tests/fuzzer/{corpus,results,logs}
571-
# - rm -f tests/fuzzer/corpus/*
572-
#
573-
# - '# Run fuzzer in nop mode'
574-
# - ./build/tests/fuzzer/corpus_generator tests/fuzzer/corpus 500
575-
# - 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/
576-
# - rm -f tests/fuzzer/corpus/*
577-
#
578-
# - '# Run fuzzer in raw mode'
579-
# - ./build/tests/fuzzer/corpus_generator tests/fuzzer/corpus 500
580-
# - 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/
581-
# - rm -f tests/fuzzer/corpus/*
582-
#
583-
# - '# Run fuzzer in body mode'
584-
# - ./build/tests/fuzzer/corpus_generator tests/fuzzer/corpus 500
585-
# - 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/
586-
#
587-
# - '# Generate coverage'
588-
# - llvm-profdata-17 merge -sparse *.profraw -o default.profdata
589-
# - 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
590-
# - 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
591-
# artifacts:
592-
# paths:
593-
# - appsec/fuzzer-coverage.html
594-
595494
"check libxml2 version":
596495
stage: test
597496
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)