Skip to content

Commit bdf100e

Browse files
feat(datasecurity): emit sdsresult (part 1)
1 parent d72dbbc commit bdf100e

6 files changed

Lines changed: 92 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/collector/sharedlibrary/rustchecks/checks/datasecurity/Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.1.0"
44
edition.workspace = true
55
license.workspace = true
66
rust-version.workspace = true
7+
build = "build.rs"
78

89
[features]
910
default = ["engine-postgres"]
@@ -15,17 +16,24 @@ engine-postgres = [
1516

1617
[dependencies]
1718
anyhow.workspace = true
18-
core = { path = "../../core" }
19+
# Aliased to `shlib_core` so the crate name does not shadow the std `core`
20+
# crate, whose `::core::` paths are referenced by the prost-generated proto code.
21+
shlib_core = { path = "../../core", package = "core" }
1922
# Keep only the `dd-sds` feature and disable default features so we pull in just
2023
# the necessary dependencies and avoid shipping the third-party checkers.
2124
dd_sds = { package = "dd-sensitive-data-scanner", version = "=0.1.0-20260715-fcd8f9716b61", default-features = false, features = ["dd-sds"] }
2225
libc.workspace = true
2326
serde.workspace = true
2427
serde_json.workspace = true
28+
prost.workspace = true
29+
prost-types.workspace = true
2530

2631
# postgres engine (gated behind the `engine-postgres` feature)
2732
postgres = { version = "0.19", optional = true }
2833

34+
[build-dependencies]
35+
prost-build = "0.14"
36+
2937
[dev-dependencies]
3038
serde_yaml = "0.9.34"
3139

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2026-present Datadog, Inc.
5+
6+
// Compiles the canonical SDS result proto with prost-build so the check can
7+
// serialize `SdsResultPayload` messages. The crate is built with cargo.
8+
//
9+
// Canonical source: pkg/proto/datadog/sds/sds_result.proto
10+
// Requires `protoc` on PATH (e.g. `brew install protobuf`).
11+
12+
fn main() -> Result<(), Box<dyn std::error::Error>> {
13+
let proto_root = "../../../../../proto";
14+
let proto_file = "../../../../../proto/datadog/sds/sds_result.proto";
15+
16+
println!("cargo:rerun-if-changed={proto_file}");
17+
18+
prost_build::compile_protos(&[proto_file], &[proto_root])?;
19+
20+
Ok(())
21+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//! Agent metadata constants for SDS result payloads.
2+
3+
/// Event platform track type for SDS results (matches Go `EventTypeSDSResult`).
4+
pub const SDS_RESULT_EVENT_TYPE: &str = "sds-result";

pkg/collector/sharedlibrary/rustchecks/checks/datasecurity/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ mod check;
55
use check::check;
66

77
mod config;
8+
mod constants;
89
mod payload;
10+
mod proto;
911
mod scanning;
1012
mod version;
1113
use version::VERSION;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//! Protobuf construction for SDS results.
2+
//!
3+
//! The crate is built with cargo: `build.rs` compiles
4+
//! `pkg/proto/datadog/sds/sds_result.proto` with prost-build and this module
5+
//! includes the generated code from `OUT_DIR`. The check builds these
6+
//! prost-generated types directly (no intermediate structs).
7+
8+
use std::time::SystemTime;
9+
10+
use prost::Message;
11+
use prost_types::Timestamp;
12+
13+
use crate::payload::Match;
14+
15+
pub mod datadog {
16+
pub mod sds {
17+
include!(concat!(env!("OUT_DIR"), "/datadog.sds.rs"));
18+
}
19+
}
20+
21+
// Proto types the check assembles directly.
22+
pub use datadog::sds::{
23+
scanning_source,
24+
sds_result_payload::{
25+
scan_location,
26+
scan_metadata::{scan_task_metadata::Status, ScanTaskMetadata},
27+
PostgresTable, Resource, ScanLocation, ScanMetadata, ScanResult, TableMatch,
28+
},
29+
ScanningSource, SdsResultPayload,
30+
};
31+
32+
/// Convert aggregated scanner matches into proto `TableMatch` entries.
33+
pub fn table_matches(matches: &[Match]) -> Vec<TableMatch> {
34+
matches
35+
.iter()
36+
.map(|m| TableMatch {
37+
rule_id: m.rule_id.clone(),
38+
column_name: m.column_name.clone(),
39+
count_matched_rows: m.count_matched_rows,
40+
..Default::default()
41+
})
42+
.collect()
43+
}
44+
45+
/// Convert a wall-clock time into a proto `Timestamp`.
46+
pub fn to_timestamp(time: SystemTime) -> Timestamp {
47+
Timestamp::from(time)
48+
}
49+
50+
/// Marshal `payload` to protobuf bytes for the `sds-result` event platform track.
51+
pub fn encode(payload: &SdsResultPayload) -> Vec<u8> {
52+
payload.encode_to_vec()
53+
}

0 commit comments

Comments
 (0)