Skip to content

Commit b971c7b

Browse files
chore: our upstream dependencies use the fips flag
1 parent c975384 commit b971c7b

5 files changed

Lines changed: 131 additions & 31 deletions

File tree

bottlecap-run/runBottlecap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
set -e
3+
set -ex
44
arch=$(uname -a)
55
cd ../bottlecap
66
# build bottlecap in debug mode

bottlecap/Cargo.lock

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

bottlecap/Cargo.toml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ async-trait = { version = "0.1", default-features = false }
99
chrono = { version = "0.4", features = ["serde", "std", "now"], default-features = false }
1010
datadog-protos = { version = "0.1.0", default-features = false, git = "https://github.com/DataDog/saluki/" }
1111
ddsketch-agent = { version = "0.1.0", default-features = false, git = "https://github.com/DataDog/saluki/" }
12-
ddcommon = { git = "https://github.com/DataDog/libdatadog", rev = "a0b92b643dff8bc28d87c974eddf7189c238eaa5" }
13-
datadog-trace-protobuf = { git = "https://github.com/DataDog/libdatadog", rev = "a0b92b643dff8bc28d87c974eddf7189c238eaa5" }
14-
datadog-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "a0b92b643dff8bc28d87c974eddf7189c238eaa5", features = ["compression"] }
15-
datadog-trace-mini-agent = { git = "https://github.com/DataDog/libdatadog", rev = "a0b92b643dff8bc28d87c974eddf7189c238eaa5" }
16-
datadog-trace-normalization = { git = "https://github.com/DataDog/libdatadog", rev = "a0b92b643dff8bc28d87c974eddf7189c238eaa5" }
17-
datadog-trace-obfuscation = { git = "https://github.com/DataDog/libdatadog", rev = "a0b92b643dff8bc28d87c974eddf7189c238eaa5" }
12+
ddcommon = { git = "https://github.com/DataDog/libdatadog", branch = "aleksandr.pasechnik/svls-6242-fips-features-for-bottlecap"}
13+
datadog-trace-protobuf = { git = "https://github.com/DataDog/libdatadog", branch = "aleksandr.pasechnik/svls-6242-fips-features-for-bottlecap" }
14+
datadog-trace-utils = { git = "https://github.com/DataDog/libdatadog", branch = "aleksandr.pasechnik/svls-6242-fips-features-for-bottlecap", features = ["compression"] }
15+
datadog-trace-mini-agent = { git = "https://github.com/DataDog/libdatadog", branch = "aleksandr.pasechnik/svls-6242-fips-features-for-bottlecap" }
16+
datadog-trace-normalization = { git = "https://github.com/DataDog/libdatadog", branch = "aleksandr.pasechnik/svls-6242-fips-features-for-bottlecap"}
17+
datadog-trace-obfuscation = { git = "https://github.com/DataDog/libdatadog", branch = "aleksandr.pasechnik/svls-6242-fips-features-for-bottlecap" }
1818
dogstatsd = { git = "https://github.com/DataDog/serverless-components", rev = "4dfe72ab1850680f41dd79d30a937eb68e7ba6da" }
1919
figment = { version = "0.10", default-features = false, features = ["yaml", "env"] }
2020
hyper = { version = "1.6", default-features = false, features = ["server"] }
@@ -30,7 +30,7 @@ log = { version = "0.4", default-features = false }
3030
nix = { version = "0.26", default-features = false, features = ["feature", "fs"] }
3131
protobuf = { version = "3.5", default-features = false }
3232
regex = { version = "1.10", default-features = false }
33-
reqwest = { version = "0.12.11", features = ["json", "http2", "rustls-tls"], default-features = false }
33+
reqwest = { version = "0.12.11", features = ["json", "http2"], default-features = false }
3434
serde = { version = "1.0", default-features = false, features = ["derive"] }
3535
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
3636
thiserror = { version = "1.0", default-features = false}
@@ -56,6 +56,9 @@ proptest = "1.4"
5656
httpmock = "0.7"
5757
serial_test = "3.1"
5858

59+
[build-dependencies]
60+
# No external dependencies needed for the build script
61+
5962
[[bin]]
6063
name = "bottlecap"
6164

@@ -64,3 +67,12 @@ opt-level = "z" # Optimize for size.
6467
lto = true
6568
codegen-units = 1
6669
strip = true
70+
71+
[features]
72+
default = ["reqwest/rustls-tls"]
73+
fips = [
74+
"ddcommon/fips",
75+
"datadog-trace-utils/fips",
76+
"reqwest/rustls-tls-no-provider",
77+
"rustls/fips",
78+
]

bottlecap/build.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
use std::process::Command;
2+
3+
fn main() {
4+
// Check if the "fips" feature is enabled
5+
let fips_enabled = std::env::var("CARGO_FEATURE_FIPS").is_ok();
6+
7+
if fips_enabled {
8+
println!("cargo:warning=FIPS feature is enabled, checking for ring dependency...");
9+
10+
// First run cargo tree to get dependency on ring with detailed info
11+
let output = Command::new("cargo")
12+
.args(&[
13+
"tree",
14+
"-i",
15+
"ring",
16+
"--format={p} {f}",
17+
"--prefix-depth",
18+
"--features=fips",
19+
"--no-default-features",
20+
])
21+
.output()
22+
.expect("Failed to execute cargo tree command");
23+
24+
// Also get the complete dependency path to help debugging
25+
let path_output = Command::new("cargo")
26+
.args(&[
27+
"tree",
28+
"-i",
29+
"ring",
30+
"--features=fips",
31+
"--no-default-features",
32+
])
33+
.output()
34+
.expect("Failed to execute detailed cargo tree command");
35+
36+
let output_str = String::from_utf8_lossy(&output.stdout);
37+
38+
// Check if ring is in the dependency tree
39+
if output_str.contains("ring v") {
40+
// Get the dependency paths to ring
41+
let ring_deps: Vec<&str> = output_str
42+
.lines()
43+
.filter(|line| line.contains("ring v"))
44+
.collect();
45+
46+
// Get the detailed dependency path
47+
let path_str = String::from_utf8_lossy(&path_output.stdout);
48+
49+
// Print detailed error message with dependency paths
50+
let error_msg = format!(
51+
"\n\nERROR: ring dependency detected with FIPS feature enabled!\n\
52+
FIPS compliance requires eliminating all ring dependencies.\n\
53+
\n\
54+
Ring dependency versions and features:\n{}\n\
55+
\n\
56+
Detailed dependency paths to ring:\n{}\n\
57+
\n\
58+
Ensure all dependencies use aws-lc-rs instead of ring.\n\
59+
Consider updating the following in your Cargo.toml:\n\
60+
1. Ensure all dependencies that use rustls have the 'aws-lc-rs' feature\n\
61+
2. Check transitive dependencies in reqwest, hyper-rustls, etc.\n\
62+
3. Update your dependencies to versions that support FIPS mode\n",
63+
ring_deps.join("\n"),
64+
path_str
65+
);
66+
67+
panic!("{}", error_msg);
68+
} else {
69+
println!("cargo:warning=No ring dependency found. FIPS compliance check passed!");
70+
}
71+
} else {
72+
println!("cargo:warning=FIPS feature is not enabled, skipping ring dependency check.");
73+
}
74+
}

images/Dockerfile.bottlecap.compile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARG PLATFORM
55
ARG FIPS
66

77
# Install dependencies
8-
RUN yum install -y curl gcc gcc-c++ make unzip
8+
RUN yum install -y curl gcc gcc-c++ make unzip cmake3 perl go
99

1010
# Install Protocol Buffers compiler by hand, since AL2 does not have a recent enough version.
1111
COPY ./scripts/install-protoc.sh /
@@ -20,13 +20,21 @@ RUN rustup component add rust-src --toolchain stable-$PLATFORM-unknown-linux-gnu
2020
# Copy source code
2121
RUN mkdir -p /tmp/dd
2222
COPY ./bottlecap/src /tmp/dd/bottlecap/src
23+
COPY ./bottlecap/build.rs /tmp/dd/bottlecap/build.rs
2324
COPY ./bottlecap/Cargo.toml /tmp/dd/bottlecap/Cargo.toml
2425
COPY ./bottlecap/Cargo.lock /tmp/dd/bottlecap/Cargo.lock
2526

2627
# Build the binary
2728
ENV RUSTFLAGS="-C panic=abort"
2829
WORKDIR /tmp/dd/bottlecap
29-
RUN --mount=type=cache,target=/usr/local/cargo/registry cargo +stable build --release --target $PLATFORM-unknown-linux-gnu
30+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
31+
if [ "$FIPS" = "1" ]; then \
32+
export FEATURES=fips; \
33+
else \
34+
export FEATURES=default; \
35+
fi; \
36+
echo FEATURES=$FEATURES; \
37+
cargo +stable build --no-default-features --features $FEATURES --release --target $PLATFORM-unknown-linux-gnu;
3038
RUN cp /tmp/dd/bottlecap/target/$PLATFORM-unknown-linux-gnu/release/bottlecap /tmp/dd/bottlecap/bottlecap
3139

3240
# Use smallest image possible

0 commit comments

Comments
 (0)