Skip to content

Commit

Permalink
improve x-allow secret handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jdbass committed Apr 17, 2024
1 parent d5f21a3 commit 5feb90e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions tofu/environments/stage/services/frontend/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ inputs = {
ssl_cert = local.ssl_cert
backend_id = dependency.backend.outputs.alb_id
backend_dns_name = dependency.backend.outputs.dns_name
x_allow_secret = dependency.backend.outputs.x_allow_secret
}
4 changes: 4 additions & 0 deletions tofu/modules/services/backend-infra/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ output "log_group" {

output "cluster_id" {
value = module.ecs_cluster.id
}

output "x_allow_secret" {
value = aws_secretsmanager_secret.x_allow_secret.name
}
8 changes: 2 additions & 6 deletions tofu/modules/services/frontend/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ data "aws_cloudfront_origin_request_policy" "AllViewer" {
}

data "aws_secretsmanager_secret_version" "x_allow_value" {
secret_id = "${var.name_prefix}-x-allow-secret"
secret_id = var.x_allow_secret
}

resource "aws_cloudfront_distribution" "appointment" {
Expand Down Expand Up @@ -199,10 +199,6 @@ resource "aws_cloudfront_function" "rewrite_api" {
if (request.uri.indexOf(apiPath) === 0) {
request.uri = request.uri.replace(apiPath, "");
}
// Remove the index.html default root object added by Cloudfront
//if (request.uri.endsWith('index.html')) {
// request.uri = request.uri.replace('index.html', "");
//}
// else carry on like normal.
return request;
}
Expand All @@ -222,7 +218,7 @@ resource "aws_cloudfront_function" "add_index" {
request.uri += 'index.html';
}
// Check whether the URI is missing a file extension.
else if (uri == '') {
else if (!uri.includes('.')) {
request.uri += '/index.html';
}
Expand Down
5 changes: 5 additions & 0 deletions tofu/modules/services/frontend/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ variable "backend_dns_name" {
description = "Backend DNS name"
type = string
}

variable "x_allow_secret" {
description = "X-Allow header secret"
type = string
}

0 comments on commit 5feb90e

Please sign in to comment.