Skip to content

Commit ee2ab28

Browse files
authored
fix(aap): fallback on .NET runtimes (#809)
# What? Fallbacks on .NET runtimes by checking the `dotnet` binary presence in `/var/lang/bin` # Motivation Provide a fallback + appsec for .NET until runtime is fixed # Notes Reverts #803
1 parent 15c9c83 commit ee2ab28

4 files changed

Lines changed: 38 additions & 10 deletions

File tree

bottlecap/src/config/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::config::{
3232
trace_propagation_style::TracePropagationStyle,
3333
yaml::YamlConfigSource,
3434
};
35+
use crate::proc::has_dotnet_binary;
3536

3637
/// Helper macro to merge Option<String> fields to String fields
3738
///
@@ -451,6 +452,15 @@ fn fallback(config: &Config) -> Result<(), ConfigError> {
451452
));
452453
}
453454

455+
// ASM / .NET
456+
// todo(duncanista): Remove once the .NET runtime is fixed
457+
if config.serverless_appsec_enabled && has_dotnet_binary() {
458+
log_fallback_reason("serverless_appsec_enabled_dotnet");
459+
return Err(ConfigError::UnsupportedField(
460+
"serverless_appsec_enabled_dotnet".to_string(),
461+
));
462+
}
463+
454464
// OTLP
455465
let has_otlp_config = config
456466
.otlp_config_receiver_protocols_grpc_endpoint

bottlecap/src/proc/constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub const PROC_STAT_PATH: &str = "/proc/stat";
33
pub const PROC_UPTIME_PATH: &str = "/proc/uptime";
44
pub const PROC_PATH: &str = "/proc";
55
pub const ETC_PATH: &str = "/etc/os-release";
6+
pub const VAR_LANG_BIN_PATH: &str = "/var/lang/bin";
67

78
pub const LAMBDA_NETWORK_INTERFACE: &str = "vinternal_1";
89
pub const LAMBDA_RUNTIME_NETWORK_INTERFACE: &str = "vint_runtime";

bottlecap/src/proc/mod.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,32 @@ use std::{
99

1010
use constants::{
1111
LAMBDA_NETWORK_INTERFACE, LAMBDA_RUNTIME_NETWORK_INTERFACE, PROC_NET_DEV_PATH, PROC_PATH,
12-
PROC_STAT_PATH, PROC_UPTIME_PATH,
12+
PROC_STAT_PATH, PROC_UPTIME_PATH, VAR_LANG_BIN_PATH,
1313
};
1414
use regex::Regex;
1515
use tracing::{debug, trace};
1616

17+
#[must_use]
18+
pub fn has_dotnet_binary() -> bool {
19+
match fs::read_dir(VAR_LANG_BIN_PATH) {
20+
Ok(mut entries) => entries.any(|entry| match entry {
21+
Ok(entry) => {
22+
let file_name = entry.file_name();
23+
let file_name_str = file_name.to_str().unwrap_or_default();
24+
file_name_str.contains("dotnet")
25+
}
26+
Err(e) => {
27+
debug!("Error reading VAR_LANG_BIN_PATH: {e}");
28+
false
29+
}
30+
}),
31+
Err(e) => {
32+
debug!("Error reading VAR_LANG_BIN_PATH: {e}");
33+
false
34+
}
35+
}
36+
}
37+
1738
#[must_use]
1839
pub fn get_pid_list() -> Vec<i64> {
1940
get_pid_list_from_path(PROC_PATH)

scripts/datadog_wrapper

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@ DD_SERVERLESS_APPSEC_ENABLED=$(echo "$DD_SERVERLESS_APPSEC_ENABLED" | tr '[:uppe
2121

2222
if [ "$DD_EXPERIMENTAL_ENABLE_PROXY" == "true" ] || [[ "$DD_SERVERLESS_APPSEC_ENABLED" =~ ^(1|t|true)$ ]]
2323
then
24-
if [[ "$AWS_EXECUTION_ENV" == *"dotnet"* ]]; then
25-
debug_log "Skipping proxy rerouting for .NET functions due to runtime issue, LWA and AAP won't work correctly."
26-
else
27-
debug_log "Enabling Datadog's Runtime API proxy"
28-
debug_log "The original AWS_LAMBDA_RUNTIME_API value is $AWS_LAMBDA_RUNTIME_API"
24+
debug_log "Enabling Datadog's Runtime API proxy"
25+
debug_log "The original AWS_LAMBDA_RUNTIME_API value is $AWS_LAMBDA_RUNTIME_API"
2926

30-
# Replace the Runtime API address with the proxy address of the extension
31-
export AWS_LAMBDA_RUNTIME_API="127.0.0.1:9000"
27+
# Replace the Runtime API address with the proxy address of the extension
28+
export AWS_LAMBDA_RUNTIME_API="127.0.0.1:9000"
3229

33-
debug_log "Rerouting AWS_LAMBDA_RUNTIME_API to the Datadog extension at $AWS_LAMBDA_RUNTIME_API"
34-
fi
30+
debug_log "Rerouting AWS_LAMBDA_RUNTIME_API to the Datadog extension at $AWS_LAMBDA_RUNTIME_API"
3531
fi
3632

3733
if [[ "$DD_SERVERLESS_APPSEC_ENABLED" =~ ^(1|t|true)$ ]]

0 commit comments

Comments
 (0)