Skip to content

Commit f636cfe

Browse files
chore: add datadog.no_waf build tag (#47)
- [x] Add `datadog.no_waf` build tag in all go:build directives - [x] Add platform section as an excuse to talk about `datadog.no_waf` build tag - [x] Add new file to explain the new reason why the waf could be disabled - [x] Run the CI with the disabled build tag on most cases to extend coverage to the new file - [x] Rename "Unsupported" with "Disabled" for some identifiers as it makes more sense now --------- Signed-off-by: Eliott Bouhana <[email protected]> Co-authored-by: Julio Guerra <[email protected]>
1 parent 9a073d0 commit f636cfe

26 files changed

+255
-76
lines changed

.github/workflows/test.yml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
runs-on: [ macos-13, macos-12, macos-11, ubuntu-22.04, ubuntu-20.04, windows-latest ]
17+
runs-on: [ macos-13, macos-12, macos-11, ubuntu-22.04, ubuntu-20.04 ]
1818
go-version: [ "1.21", "1.20", "1.19" ]
1919
cgo_enabled: [ "0", "1" ] # test it compiles with and without cgo
2020
include:
@@ -30,7 +30,6 @@ jobs:
3030
with:
3131
go-version: ${{ matrix.go-version }}
3232
cache: true
33-
3433
- name: go test
3534
shell: bash
3635
run: |
@@ -39,6 +38,30 @@ jobs:
3938
# Run the tests with gotestsum
4039
env ${{ matrix.env }} CGO_ENABLED=${{ matrix.cgo_enabled }} ./gotestsum -- -v -count=10 -shuffle=on ./...
4140
41+
disabled:
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
runs-on: [ windows-latest, ubuntu-latest, macos-13 ]
46+
go-args: [ "-tags datadog.no_waf", "-tags go1.22" ]
47+
include:
48+
- runs-on: windows-latest
49+
go-args: ""
50+
runs-on: ${{ matrix.runs-on }}
51+
steps:
52+
- uses: actions/checkout@v3
53+
- uses: actions/setup-go@v4
54+
with:
55+
go-version: 'stable' # get latest stable version from https://github.com/actions/go-versions/blob/main/versions-manifest.json
56+
cache: true
57+
- name: go test
58+
shell: bash
59+
run: |
60+
# Install gotestsum
61+
env GOBIN=$PWD go install gotest.tools/gotestsum@latest
62+
# Run the tests with gotestsum
63+
./gotestsum -- -v ${{ matrix.go-tags }} -shuffle=on ./...
64+
4265
# Same tests but on the official golang container for linux
4366
golang-linux-container:
4467
runs-on: ubuntu-latest

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ But with the appearance of `ddwaf_object` tree like structure,
4141
but also with the intention to build CGO-less bindings, this project size has grown to be a fully integrated brick in the DataDog tracer structure.
4242
Which in turn made it necessary to document the project, to maintain it in an orderly fashion.
4343

44+
## Supported platforms
45+
46+
This library currently support the following platform doublets:
47+
48+
| OS | Arch |
49+
| ----- | ------- |
50+
| Linux | amd64 |
51+
| Linux | aarch64 |
52+
| OSX | amd64 |
53+
| OSX | arm64 |
54+
55+
This means that when the platform is not supported, top-level functions will return a `WafDisabledError` error including the purpose of it.
56+
57+
Note that:
58+
* Linux support include for glibc and musl variants
59+
* OSX under 10.9 is not supported
60+
* A build tag named `datadog.no_waf` can be manually added to force the WAF to be disabled.
61+
4462
## Design
4563

4664
The WAF bindings have multiple moving parts that are necessary to understand:

ctypes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Copyright 2016-present Datadog, Inc.
55

66
// Purego only works on linux/macOS with amd64 and arm64 from now
7-
//go:build (linux || darwin) && (amd64 || arm64) && !go1.22
7+
//go:build (linux || darwin) && (amd64 || arm64) && !go1.22 && !datadog.no_waf
88

99
package waf
1010

encoder_decoder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This product includes software developed at Datadog (https://www.datadoghq.com/).
44
// Copyright 2016-present Datadog, Inc.
55

6-
//go:build (amd64 || arm64) && (linux || darwin) && !go1.22
6+
//go:build (amd64 || arm64) && (linux || darwin) && !go1.22 && !datadog.no_waf
77

88
package waf
99

handle_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
func TestNewHandle(t *testing.T) {
16-
if supported, err := supportsTarget(); !supported || err != nil {
16+
if supported, err := Health(); !supported || err != nil {
1717
t.Skip("target is not supported by the WAF")
1818
return
1919
}

internal/lib/lib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This product includes software developed at Datadog (https://www.datadoghq.com/).
44
// Copyright 2016-present Datadog, Inc.
55

6-
//go:build ((darwin && (amd64 || arm64)) || (linux && (amd64 || arm64))) && !go1.22
6+
//go:build ((darwin && (amd64 || arm64)) || (linux && (amd64 || arm64))) && !go1.22 && !datadog.no_waf
77

88
package lib
99

internal/lib/lib_darwin_amd64.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// This product includes software developed at Datadog (https://www.datadoghq.com/).
44
// Copyright 2016-present Datadog, Inc.
55

6-
//go:build darwin && amd64 && !go1.22
6+
//go:build darwin && amd64 && !go1.22 && !datadog.no_waf
7+
78
package lib
89

910
import _ "embed" // Needed for go:embed

internal/lib/lib_darwin_arm64.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// This product includes software developed at Datadog (https://www.datadoghq.com/).
44
// Copyright 2016-present Datadog, Inc.
55

6-
//go:build darwin && arm64 && !go1.22
6+
//go:build darwin && arm64 && !go1.22 && !datadog.no_waf
7+
78
package lib
89

910
import _ "embed" // Needed for go:embed

internal/lib/lib_linux_amd64.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// This product includes software developed at Datadog (https://www.datadoghq.com/).
44
// Copyright 2016-present Datadog, Inc.
55

6-
//go:build linux && amd64 && !go1.22
6+
//go:build linux && amd64 && !go1.22 && !datadog.no_waf
7+
78
package lib
89

910
import _ "embed" // Needed for go:embed

internal/lib/lib_linux_arm64.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// This product includes software developed at Datadog (https://www.datadoghq.com/).
44
// Copyright 2016-present Datadog, Inc.
55

6-
//go:build linux && arm64 && !go1.22
6+
//go:build linux && arm64 && !go1.22 && !datadog.no_waf
7+
78
package lib
89

910
import _ "embed" // Needed for go:embed

0 commit comments

Comments
 (0)