Skip to content

Commit 3ddbb56

Browse files
authored
Add support for additional S3 CORS origins (#76)
1 parent d504b44 commit 3ddbb56

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ module "services" {
118118
api_handler_reserved_concurrent_executions = var.api_handler_reserved_concurrent_executions
119119
ai_proxy_reserved_concurrent_executions = var.ai_proxy_reserved_concurrent_executions
120120
whitelisted_origins = var.whitelisted_origins
121+
s3_additional_allowed_origins = var.s3_additional_allowed_origins
121122
outbound_rate_limit_window_minutes = var.outbound_rate_limit_window_minutes
122123
outbound_rate_limit_max_requests = var.outbound_rate_limit_max_requests
123124
custom_domain = var.custom_domain

modules/services/s3.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ locals {
44
"https://*.braintrust.dev",
55
"https://*.preview.braintrust.dev"
66
]
7+
8+
all_origins = concat(local.default_origins, var.s3_additional_allowed_origins)
79
}
810

911
resource "aws_s3_bucket" "code_bundle_bucket" {
@@ -37,7 +39,7 @@ resource "aws_s3_bucket_cors_configuration" "code_bundle_bucket" {
3739
cors_rule {
3840
allowed_headers = ["*"]
3941
allowed_methods = ["PUT"]
40-
allowed_origins = local.default_origins
42+
allowed_origins = local.all_origins
4143
max_age_seconds = 3600
4244
}
4345
}
@@ -78,7 +80,7 @@ resource "aws_s3_bucket_cors_configuration" "lambda_responses_bucket" {
7880
cors_rule {
7981
allowed_headers = ["*"]
8082
allowed_methods = ["GET", "HEAD"]
81-
allowed_origins = local.default_origins
83+
allowed_origins = local.all_origins
8284
max_age_seconds = 3600
8385
}
8486
}

modules/services/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ variable "whitelisted_origins" {
138138
description = "List of origins to whitelist for CORS"
139139
}
140140

141+
variable "s3_additional_allowed_origins" {
142+
type = list(string)
143+
description = "Additional origins to allow for S3 bucket CORS configuration. Supports a wildcard in the domain name."
144+
default = []
145+
}
146+
141147
variable "outbound_rate_limit_max_requests" {
142148
type = number
143149
description = "The maximum number of requests per user allowed in the time frame specified by OutboundRateLimitMaxRequests. Setting to 0 will disable rate limits"

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ variable "whitelisted_origins" {
209209
default = []
210210
}
211211

212+
variable "s3_additional_allowed_origins" {
213+
description = "Additional origins to allow for S3 bucket CORS configuration. Supports a wildcard in the domain name."
214+
type = list(string)
215+
default = []
216+
}
217+
212218
variable "outbound_rate_limit_max_requests" {
213219
description = "The maximum number of requests per user allowed in the time frame specified by OutboundRateLimitMaxRequests. Setting to 0 will disable rate limits"
214220
type = number

0 commit comments

Comments
 (0)