Skip to content

Commit d561651

Browse files
chore: check for DD_LAMBDA_FIPS_MODE mismatch
1 parent 37020f2 commit d561651

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

bottlecap/src/bin/bottlecap/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ async fn main() -> Result<()> {
191191
let (mut aws_config, config) = load_configs(start_time);
192192

193193
enable_logging_subsystem(&config);
194-
log_fips_status();
194+
log_fips_status(&aws_config.region);
195195
let version_without_next = EXTENSION_VERSION.split('-').next().unwrap_or("NA");
196196
debug!("Starting Datadog Extension {version_without_next}");
197197
prepare_client_provider()?;

bottlecap/src/fips/mod.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// mode. This is used in conjunction with the datadog-fips crate to ensure that when we
33
// compile the extension in FIPS mode, everything is built and configured correctly.
44

5+
use std::env;
56
#[cfg(feature = "fips")]
67
use std::io::Error;
78
use std::io::Result;
@@ -10,14 +11,41 @@ use tracing::debug;
1011
#[cfg(all(feature = "default", feature = "fips"))]
1112
compile_error!("When building in fips mode, the default feature must be disabled");
1213

14+
#[must_use]
15+
pub fn runtime_layer_would_enable_fips_mode(region: &str) -> bool {
16+
let is_gov_region = region.starts_with("us-gov-");
17+
18+
env::var("DD_LAMBDA_FIPS_MODE")
19+
.map(|val| val.to_lowercase() == "true")
20+
.unwrap_or(is_gov_region)
21+
}
22+
23+
#[cfg(feature = "fips")]
24+
pub fn check_fips_mode_mismatch(region: &str) {
25+
let runtime_would_enable = runtime_layer_would_enable_fips_mode(region);
26+
if !runtime_would_enable {
27+
debug!("FIPS mode is enabled in this Extension layer but would be disabled in the runtime layer based on region and environment settings. Set DD_LAMBDA_FIPS_MODE=true or deploy the standard (non-FIPS) version of the Extension layer to ensure consistent FIPS behavior.");
28+
}
29+
}
30+
31+
#[cfg(not(feature = "fips"))]
32+
pub fn check_fips_mode_mismatch(region: &str) {
33+
let runtime_would_enable = runtime_layer_would_enable_fips_mode(region);
34+
if runtime_would_enable {
35+
debug!("FIPS mode is disabled in this Extension layer but would be enabled in the runtime layer based on region and environment settings. Deploy the FIPS version of the Extension layer or set DD_LAMBDA_FIPS_MODE=false to ensure consistent FIPS behavior.");
36+
}
37+
}
38+
1339
#[cfg(feature = "fips")]
14-
pub fn log_fips_status() {
40+
pub fn log_fips_status(region: &str) {
1541
debug!("FIPS mode is enabled");
42+
check_fips_mode_mismatch(region);
1643
}
1744

1845
#[cfg(not(feature = "fips"))]
19-
pub fn log_fips_status() {
46+
pub fn log_fips_status(region: &str) {
2047
debug!("FIPS mode is disabled");
48+
check_fips_mode_mismatch(region);
2149
}
2250

2351
/// Sets up the client provider for TLS operations.

0 commit comments

Comments
 (0)