-
Notifications
You must be signed in to change notification settings - Fork 2
[PLT-1418] Update web module to support DPC, leverage STS headers and cloudfront logging; #358
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
Changes from all commits
ff21375
5645657
2e014bd
c4e03f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| resource "aws_cloudwatch_log_delivery_source" "this" { | ||
| name = "${var.platform.app}-${var.platform.env}" | ||
| log_type = "ACCESS_LOGS" | ||
| resource_arn = aws_cloudfront_distribution.this.arn | ||
| } | ||
|
|
||
| resource "aws_cloudwatch_log_delivery_destination" "this" { | ||
| name = "${var.platform.app}-${var.platform.env}" | ||
| output_format = "parquet" | ||
|
|
||
| delivery_destination_configuration { | ||
| destination_resource_arn = var.platform.splunk_logging_bucket.arn | ||
| } | ||
| } | ||
|
|
||
| resource "aws_cloudwatch_log_delivery" "this" { | ||
| delivery_source_name = aws_cloudwatch_log_delivery_source.this.name | ||
| delivery_destination_arn = aws_cloudwatch_log_delivery_destination.this.arn | ||
|
|
||
| s3_delivery_configuration { | ||
| suffix_path = "/AWSLogs/${data.aws_caller_identity.this.account_id}/Cloudfront/{DistributionId}/{yyyy}/{MM}/{dd}/{HH}" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,44 @@ | ||
| data "aws_caller_identity" "this" {} | ||
|
|
||
| data "aws_acm_certificate" "issued" { | ||
| domain = var.domain_name | ||
| statuses = ["ISSUED"] | ||
|
mianava marked this conversation as resolved.
|
||
| } | ||
|
|
||
| resource "aws_cloudfront_function" "redirects" { | ||
| name = "redesign-redirects" | ||
| name = "${var.domain_name}-redirects" | ||
| runtime = "cloudfront-js-2.0" | ||
| comment = "Function that handles cool URIs and redirects." | ||
| code = templatefile("${path.module}/redirects-function.tftpl", { redirects = var.redirects }) | ||
| } | ||
|
|
||
| resource "aws_cloudfront_origin_access_control" "this" { | ||
| name = var.origin_bucket.bucket_regional_domain_name | ||
| name = "${var.domain_name}-s3-origin" | ||
| description = "Manages an AWS CloudFront Origin Access Control, which is used by CloudFront Distributions with an Amazon S3 bucket as the origin." | ||
| origin_access_control_origin_type = "s3" | ||
| signing_behavior = "always" | ||
| signing_protocol = "sigv4" | ||
| } | ||
|
|
||
| resource "aws_cloudfront_response_headers_policy" "this" { | ||
| name = "${var.platform.app}-${var.platform.env}-StsHeaderPolicy" | ||
|
|
||
| security_headers_config { | ||
| strict_transport_security { | ||
| access_control_max_age_sec = 31536000 | ||
| override = false | ||
| include_subdomains = true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource "aws_cloudfront_distribution" "this" { | ||
| aliases = var.certificate == null ? [] : [var.certificate.domain_name] | ||
| aliases = [var.domain_name] | ||
| comment = "Distribution for the ${var.platform.app}-${var.platform.env} website" | ||
| default_root_object = "index.html" | ||
| enabled = var.enabled | ||
| http_version = "http2and3" | ||
| is_ipv6_enabled = true | ||
| price_class = "PriceClass_100" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed because the assignment gets overwritten by institutionalized templates in the AWS accounts. Geographical restrictions are preferred to this setting. |
||
| web_acl_id = var.web_acl.arn | ||
|
|
||
| custom_error_response { | ||
|
|
@@ -41,7 +59,7 @@ resource "aws_cloudfront_distribution" "this" { | |
| allowed_methods = ["GET", "HEAD"] | ||
| cached_methods = ["GET", "HEAD"] | ||
| compress = true | ||
| target_origin_id = "s3_origin" | ||
| target_origin_id = var.s3_origin_id | ||
| viewer_protocol_policy = "redirect-to-https" | ||
|
|
||
| cache_policy_id = ( | ||
|
|
@@ -50,6 +68,8 @@ resource "aws_cloudfront_distribution" "this" { | |
| "4135ea2d-6df8-44a3-9df3-4b5a84be39ad" # CachingDisabled managed policy | ||
| ) | ||
|
|
||
| response_headers_policy_id = aws_cloudfront_response_headers_policy.this.id | ||
|
|
||
| function_association { | ||
| event_type = "viewer_request" | ||
| function_arn = aws_cloudfront_function.redirects.arn | ||
|
|
@@ -59,7 +79,7 @@ resource "aws_cloudfront_distribution" "this" { | |
| origin { | ||
| domain_name = var.origin_bucket.bucket_regional_domain_name | ||
| origin_access_control_id = aws_cloudfront_origin_access_control.this.id | ||
| origin_id = "s3_origin" | ||
| origin_id = var.s3_origin_id | ||
| } | ||
|
|
||
| restrictions { | ||
|
|
@@ -70,29 +90,9 @@ resource "aws_cloudfront_distribution" "this" { | |
| } | ||
|
|
||
| viewer_certificate { | ||
| cloudfront_default_certificate = var.certificate == null ? true : false | ||
| acm_certificate_arn = var.certificate == null ? null : var.certificate.arn | ||
| minimum_protocol_version = var.certificate == null ? null : "TLSv1.2_2021" | ||
| ssl_support_method = var.certificate == null ? null : "sni-only" | ||
| cloudfront_default_certificate = false | ||
|
Comment on lines
-73
to
+93
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gsf this now assumes that a certificate is already issued - as there is no longer a |
||
| acm_certificate_arn = data.aws_acm_certificate.issued.arn | ||
| minimum_protocol_version = "TLSv1.2_2021" | ||
| ssl_support_method = "sni-only" | ||
| } | ||
| } | ||
|
|
||
| resource "aws_cloudwatch_log_delivery_source" "this" { | ||
| name = "${var.platform.app}-${var.platform.env}" | ||
| log_type = "ACCESS_LOGS" | ||
| resource_arn = aws_cloudfront_distribution.this.arn | ||
| } | ||
|
|
||
| resource "aws_cloudwatch_log_delivery_destination" "this" { | ||
| name = "${var.platform.app}-${var.platform.env}" | ||
| output_format = "parquet" | ||
|
|
||
| delivery_destination_configuration { | ||
| destination_resource_arn = "${var.logging_bucket.arn}/${var.origin_bucket.bucket_regional_domain_name}" | ||
| } | ||
| } | ||
|
|
||
| resource "aws_cloudwatch_log_delivery" "this" { | ||
| delivery_source_name = aws_cloudwatch_log_delivery_source.this.name | ||
| delivery_destination_arn = aws_cloudwatch_log_delivery_destination.this.arn | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* To reduce module nesting and adhere to current configurations, S3 buckets are managed outside of this module. | ||
| Permissions for Cloudfront, however, are managed here. */ | ||
|
|
||
| resource "aws_s3_bucket_policy" "allow_cloudfront_access" { | ||
| bucket = var.origin_bucket.id | ||
| policy = data.aws_iam_policy_document.allow_cloudfront_access.json | ||
| } | ||
|
|
||
| # S3 static site host bucket policy document | ||
| data "aws_iam_policy_document" "allow_cloudfront_access" { | ||
| # There are no dev or test environments for the static site | ||
|
|
||
| statement { | ||
| sid = "AllowCloudfrontAccess" | ||
| effect = "Allow" | ||
|
|
||
| principals { | ||
| type = "Service" | ||
| identifiers = ["cloudfront.amazonaws.com"] | ||
| } | ||
|
|
||
| actions = [ | ||
| "s3:GetObject", | ||
| "s3:ListBucket" | ||
| ] | ||
|
|
||
| condition { | ||
| test = "StringEquals" | ||
| variable = "AWS:SourceArn" | ||
| values = [ | ||
| aws_cloudfront_distribution.this.arn | ||
| ] | ||
| } | ||
|
|
||
| resources = [ | ||
| var.origin_bucket.arn | ||
| ] | ||
| } | ||
| statement { | ||
| sid = "AllowSSLRequestsOnly" | ||
| effect = "Deny" | ||
| principals { | ||
| type = "AWS" | ||
| identifiers = ["*"] | ||
| } | ||
| actions = ["s3:*"] | ||
| resources = [ | ||
| var.origin_bucket.arn, | ||
| "${var.origin_bucket.arn}/*", | ||
| ] | ||
| condition { | ||
| test = "Bool" | ||
| variable = "aws:SecureTransport" | ||
| values = ["false"] | ||
| } | ||
| } | ||
| } | ||
|
|
Uh oh!
There was an error while loading. Please reload this page.