Commit 05d2265
authored
[DSEC-118] Build and ship Rust shared-library checks in agent packages (#53498)
### What does this PR do?
- Add [`shared_checks_manifest.yaml`](https://github.com/DataDog/datadog-agent/blob/aimene.belfodil/dsec/build-rust-checks/pkg/collector/sharedlibrary/rustchecks/shared_checks_manifest.yaml) and a [`rust-shared-checks.build`](https://github.com/DataDog/datadog-agent/blob/aimene.belfodil/dsec/build-rust-checks/tasks/rust_shared_checks.py) invoke task to build manifest-selected `cdylib` checks and stage them into `checks.d` as `libdatadog-agent-<id>.so` with `0500` permissions (Linux only).
- Wire the task into the omnibus agent build ([`datadog-agent.rb`](https://github.com/DataDog/datadog-agent/blob/aimene.belfodil/dsec/build-rust-checks/omnibus/config/software/datadog-agent.rb#L108-L112)); it runs for Linux only (macOS and Windows excluded).
- Move staged shared libs into the Linux package config during [`datadog-agent-finalize.rb`](https://github.com/DataDog/datadog-agent/blob/aimene.belfodil/dsec/build-rust-checks/omnibus/config/software/datadog-agent-finalize.rb#L99-L103) and enforce owner-only (`0500`) perms.
- Re-apply `0500` on the shared-library checks in the [`agent`](https://github.com/DataDog/datadog-agent/blob/aimene.belfodil/dsec/build-rust-checks/Dockerfiles/agent/Dockerfile#L214) and [`agent-ddot`](https://github.com/DataDog/datadog-agent/blob/aimene.belfodil/dsec/build-rust-checks/Dockerfiles/agent-ddot/Dockerfile#L21) Dockerfiles after the recursive config `chmod`.
- Fix the Rust shared-check FFI macro to resolve types via `$crate::` instead of `core::`.
### Motivation
Rust shared-library checks are not built or shipped in agent packages today. This wires the existing rustchecks workspace into omnibus/Docker so checks listed in the manifest can be included in Linux release artifacts.
### Describe how you validated your changes (with example check [enabled](https://github.com/DataDog/datadog-agent/blob/aimene.belfodil/dsec/build-rust-checks/pkg/collector/sharedlibrary/rustchecks/shared_checks_manifest.yaml#L4))
#### CI image (omnibus build)
Built from CI job [1848750354](https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/1848750354) and ran the agent with:
```yaml
services:
agent:
image: registry.ddbuild.io/ci/datadog-agent/agent:v124269439-678e1467-7-amd64
container_name: new-agent-with-rust-checks
environment:
DD_API_KEY: ***
DD_HOSTNAME: aimene-test-ci-image
DD_SITE: datad0g.com
DD_APM_ENABLED: "true"
DD_APM_NON_LOCAL_TRAFFIC: "true"
DD_LOGS_ENABLED: "true"
DD_DOGSTATSD_NON_LOCAL_TRAFFIC: "true"
DD_LOG_LEVEL: "INFO"
DD_SHARED_LIBRARY_CHECK_ENABLED: "true"
DD_SHARED_LIBRARY_CHECK_LIBRARY_FOLDER_PATH: "/etc/datadog-agent/checks.d"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./conf.d:/etc/datadog-agent/conf.d:ro
```
`conf.d` contains `example.d/conf.yaml`:
```yaml
init_config:
instances:
-
min_collection_interval: 15
```
The example shared-library check ran successfully and events were received in [Event Explorer (`host:aimene-test-ci-image`)](https://dd.datad0g.com/event/explorer?query=host%3Aaimene-test-ci-image&agg_m=count&agg_m_source=base&agg_t=count&clustering_pattern_field_path=message&cols=&messageDisplay=expanded-lg&options=&refresh_mode=paused&sort=DESC&from_ts=1783634400000&to_ts=1783687020000&live=false).
#### Hacky dev image
Also tested locally with:
```bash
dda env dev run -- dda inv agent.hacky-dev-image-build --target-image agent-with-rust-checks
```
Same check config and expected results (example shared-library check runs and [events are received](https://dd.datad0g.com/event/explorer?query=host%3Aaimene-test-hacky-build&agg_m=count&agg_m_source=base&agg_t=count&clustering_pattern_field_path=message&cols=&messageDisplay=expanded-lg&options=&refresh_mode=paused&sort=DESC&from_ts=1783634400000&to_ts=1783687020000&live=false)).
### Actions
- [x] Check selection is driven by [`include_in_build`](https://github.com/DataDog/datadog-agent/blob/aimene.belfodil/dsec/build-rust-checks/pkg/collector/sharedlibrary/rustchecks/shared_checks_manifest.yaml) in the manifest (default `false`). **Before merge:** set `example` to `include_in_build: false` since **the example check should not ship**.
### Question/Response
#### Why Only Linux?
To keep the scope and risk minimal, this PR targets the Linux platform only.
#### Why shipped shared libs need chmod 0500 (according to existing code)?
Shared-library loader rejects libs (rust checks) unless the owner is trusted and group/others have no access ([`CheckOwnerAndPermissionsAreRestricted`](https://github.com/DataDog/datadog-agent/blob/main/pkg/util/filesystem/permission_check.go#L14-L22) → [`CheckRights`](https://github.com/DataDog/datadog-agent/blob/main/pkg/util/filesystem/rights_nix.go#L17-L34), called from [`SharedLibraryLoader.Open`](https://github.com/DataDog/datadog-agent/blob/main/pkg/collector/sharedlibrary/ffi/library_loader.go#L111)). Packaging steps that `chmod` config broadly would otherwise leave libs group/world-readable and unloadable.
Co-authored-by: aimene.belfodil <aimene.belfodil@datadoghq.com>1 parent 06ac9ad commit 05d2265
11 files changed
Lines changed: 224 additions & 9 deletions
File tree
- .github
- Dockerfiles
- agent-ddot
- agent
- omnibus/config/software
- releasenotes/notes
- tasks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
849 | 849 | | |
850 | 850 | | |
851 | 851 | | |
| 852 | + | |
852 | 853 | | |
853 | 854 | | |
854 | 855 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
213 | 216 | | |
214 | 217 | | |
215 | 218 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
97 | 105 | | |
98 | 106 | | |
99 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
112 | 119 | | |
113 | 120 | | |
114 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | | - | |
39 | | - | |
| 38 | + | |
| 39 | + | |
40 | 40 | | |
41 | | - | |
42 | | - | |
| 41 | + | |
| 42 | + | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| |||
252 | 253 | | |
253 | 254 | | |
254 | 255 | | |
| 256 | + | |
255 | 257 | | |
256 | 258 | | |
257 | 259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
448 | 448 | | |
449 | 449 | | |
450 | 450 | | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
451 | 464 | | |
452 | 465 | | |
453 | 466 | | |
| |||
527 | 540 | | |
528 | 541 | | |
529 | 542 | | |
| 543 | + | |
530 | 544 | | |
531 | 545 | | |
532 | 546 | | |
| |||
564 | 578 | | |
565 | 579 | | |
566 | 580 | | |
| 581 | + | |
567 | 582 | | |
568 | 583 | | |
569 | 584 | | |
| |||
0 commit comments