Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVLS-6128 fix: set right domain and arn by region on secrets manager #511

Merged
merged 6 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bottlecap/src/bin/bottlecap/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#![deny(missing_copy_implementations)]
#![deny(missing_debug_implementations)]

use bottlecap::config::get_aws_partition_by_region;
alexgallotta marked this conversation as resolved.
Show resolved Hide resolved
use bottlecap::{
base_url,
config::{self, flush_strategy::FlushStrategy, AwsConfig, Config},
Expand Down Expand Up @@ -156,7 +157,8 @@ async fn register(client: &reqwest::Client) -> Result<RegisterResponse> {
}

fn build_function_arn(account_id: &str, region: &str, function_name: &str) -> String {
format!("arn:aws:lambda:{region}:{account_id}:function:{function_name}")
let aws_partition = get_aws_partition_by_region(region);
format!("arn:{aws_partition}:lambda:{region}:{account_id}:function:{function_name}")
}

#[tokio::main]
Expand Down
9 changes: 9 additions & 0 deletions bottlecap/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ pub struct AwsConfig {
pub sandbox_init_time: Instant,
}

#[must_use]
pub fn get_aws_partition_by_region(region: &str) -> String {
match region {
r if r.starts_with("us-gov-") => "aws-us-gov".to_string(),
r if r.starts_with("cn-") => "aws-cn".to_string(),
_ => "aws".to_string(),
}
}

#[cfg(test)]
pub mod tests {
use super::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use crate::config::get_aws_partition_by_region;
use crate::lifecycle::invocation::{
processor::MS_TO_NS,
triggers::{lowercase_key, ServiceNameResolver, Trigger, FUNCTION_TRIGGER_EVENT_SOURCE_TAG},
};
alexgallotta marked this conversation as resolved.
Show resolved Hide resolved
use datadog_trace_protobuf::pb::Span;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
use tracing::debug;

use crate::lifecycle::invocation::{
processor::MS_TO_NS,
triggers::{
get_aws_partition_by_region, lowercase_key, ServiceNameResolver, Trigger,
FUNCTION_TRIGGER_EVENT_SOURCE_TAG,
},
};

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct APIGatewayHttpEvent {
#[serde(rename = "routeKey")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use crate::config::get_aws_partition_by_region;
use crate::lifecycle::invocation::{
processor::MS_TO_NS,
triggers::{lowercase_key, ServiceNameResolver, Trigger, FUNCTION_TRIGGER_EVENT_SOURCE_TAG},
};
alexgallotta marked this conversation as resolved.
Show resolved Hide resolved
use datadog_trace_protobuf::pb::Span;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
use tracing::debug;

use crate::lifecycle::invocation::{
processor::MS_TO_NS,
triggers::{
get_aws_partition_by_region, lowercase_key, ServiceNameResolver, Trigger,
FUNCTION_TRIGGER_EVENT_SOURCE_TAG,
},
};

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct APIGatewayRestEvent {
#[serde(deserialize_with = "lowercase_key")]
Expand Down
9 changes: 0 additions & 9 deletions bottlecap/src/lifecycle/invocation/triggers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ pub trait Trigger: ServiceNameResolver {
}
}

#[must_use]
pub fn get_aws_partition_by_region(region: &str) -> String {
match region {
r if r.starts_with("us-gov-") => "aws-us-gov".to_string(),
r if r.starts_with("cn-") => "aws-cn".to_string(),
_ => "aws".to_string(),
}
}

/// Serialize a `HashMap` with lowercase keys
///
pub fn lowercase_key<'de, D, V>(deserializer: D) -> Result<HashMap<String, V>, D::Error>
Expand Down
13 changes: 6 additions & 7 deletions bottlecap/src/lifecycle/invocation/triggers/sqs_event.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
use datadog_trace_protobuf::pb::Span;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
use tracing::debug;

use crate::config::get_aws_partition_by_region;
use crate::lifecycle::invocation::{
processor::MS_TO_NS,
triggers::{
event_bridge_event::EventBridgeEvent,
get_aws_partition_by_region,
sns_event::{SnsEntity, SnsRecord},
ServiceNameResolver, Trigger, DATADOG_CARRIER_KEY, FUNCTION_TRIGGER_EVENT_SOURCE_TAG,
},
};
use crate::traces::context::{Sampling, SpanContext};
use datadog_trace_protobuf::pb::Span;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
use tracing::debug;

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct SqsEvent {
Expand Down
12 changes: 8 additions & 4 deletions bottlecap/src/secrets/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,14 @@ fn build_get_secret_signed_headers(
) -> Result<HeaderMap, Box<dyn std::error::Error>> {
let amz_date = header_values.time.format("%Y%m%dT%H%M%SZ").to_string();
let date_stamp = header_values.time.format("%Y%m%d").to_string();
let host = format!(
"{}.{}.amazonaws.com",
header_values.service, aws_config.region
);

let domain = if aws_config.region.starts_with("cn-") {
"amazonaws.com.cn"
} else {
"amazonaws.com"
};

alexgallotta marked this conversation as resolved.
Show resolved Hide resolved
let host = format!("{}.{}.{}", header_values.service, aws_config.region, domain);

let canonical_uri = "/";
let canonical_querystring = "";
Expand Down
Loading