Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

Use a path-style data connector URL for dotted S3 bucket names

shukieshah3b95d1961e85
diff --git a/terraform/aws-s3/main.tf b/terraform/aws-s3/main.tf
index f4a603e6..d0dcec74 100644
--- a/terraform/aws-s3/main.tf
+++ b/terraform/aws-s3/main.tf
@@ -16,6 +16,14 @@ locals {
beacon_objects_arn = "${local.bucket_arn}/${var.prefix}/*"
bucket_region = var.create_bucket ? aws_s3_bucket.this[0].region : data.aws_s3_bucket.existing[0].region
+
+ # S3's certificate for virtual-hosted URLs covers one label, so a dotted bucket name needs path style.
+ s3_host = "s3.${local.bucket_region}.${data.aws_partition.current.dns_suffix}"
+ beacon_reader_source_url = (
+ strcontains(var.bucket_name, ".")
+ ? "https://${local.s3_host}/${var.bucket_name}/${var.prefix}"
+ : "https://${var.bucket_name}.${local.s3_host}/${var.prefix}"
+ )
}
resource "aws_s3_bucket" "this" {
diff --git a/terraform/aws-s3/outputs.tf b/terraform/aws-s3/outputs.tf
index 66b2dd38..8e7580fa 100644
--- a/terraform/aws-s3/outputs.tf
+++ b/terraform/aws-s3/outputs.tf
@@ -77,5 +77,5 @@ output "beacon_reader_secret_access_key" {
output "beacon_reader_source_url" {
description = "The location to give Beacon for the S3 data connector."
- value = "https://${var.bucket_name}.s3.${local.bucket_region}.amazonaws.com/${var.prefix}"
+ value = local.beacon_reader_source_url
}
diff --git a/terraform/aws-s3/tests/module.tftest.hcl b/terraform/aws-s3/tests/module.tftest.hcl
index 40a76d21..70370385 100644
--- a/terraform/aws-s3/tests/module.tftest.hcl
+++ b/terraform/aws-s3/tests/module.tftest.hcl
@@ -3,7 +3,8 @@
mock_provider "aws" {
mock_data "aws_partition" {
defaults = {
- partition = "aws"
+ partition = "aws"
+ dns_suffix = "amazonaws.com"
}
}
@@ -150,6 +151,47 @@ run "forwarder_settings_match_the_helper" {
}
}
+run "source_url_uses_path_style_for_dotted_bucket_names" {
+ command = apply
+
+ variables {
+ bucket_name = "acme.beacon.telemetry"
+ }
+
+ assert {
+ condition = output.beacon_reader_source_url == "https://s3.us-west-2.amazonaws.com/acme.beacon.telemetry/beacon-prod"
+ error_message = "A dotted bucket name fails TLS on a virtual-hosted URL, so the URL must be path style."
+ }
+}
+
+run "source_url_follows_the_partition" {
+ command = apply
+
+ override_data {
+ target = data.aws_partition.current
+ values = {
+ partition = "aws-cn"
+ dns_suffix = "amazonaws.com.cn"
+ }
+ }
+
+ variables {
+ create_bucket = false
+ bucket_name = "acme-security-logs"
+ existing_bucket_region = "cn-north-1"
+ }
+
+ assert {
+ condition = output.beacon_reader_source_url == "https://acme-security-logs.s3.cn-north-1.amazonaws.com.cn/beacon-prod"
+ error_message = "The URL uses the partition's DNS suffix."
+ }
+
+ assert {
+ condition = output.bucket_arn == "arn:aws-cn:s3:::acme-security-logs"
+ error_message = "The bucket ARN uses the partition."
+ }
+}
+
run "kms_key_encrypts_and_is_granted" {
command = plan