Skip to content

Commit 0358417

Browse files
Add HTTPS support for aws.javabin.no redirect (#112)
## Summary - Adds ACM certificate in us-east-1 with DNS validation for aws.javabin.no - CloudFront distribution fronts the S3 redirect bucket with HTTPS - Route53 alias now points to CloudFront instead of S3 directly - Adds AAAA record for IPv6 support ## Test plan - [ ] CI plan passes - [ ] After apply, `curl -I https://aws.javabin.no` returns 301 to `https://javabin.awsapps.com/start` - [ ] Note: CloudFront distribution takes ~5 min to deploy, ACM cert validation takes a few minutes
1 parent 293b151 commit 0358417

3 files changed

Lines changed: 126 additions & 5 deletions

File tree

terraform/platform/dns/main.tf

Lines changed: 113 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,8 @@ resource "aws_route53_record" "teknologihuset_no_carddav_txt" {
406406
# ==============================================================================
407407
# aws.javabin.no → IAM Identity Center SSO portal redirect
408408
#
409-
# S3 website hosting bucket configured to redirect all requests to the
410-
# Identity Center portal. Route53 alias points to the S3 website endpoint.
411-
# This only handles HTTP — browsers follow the 301 to the HTTPS portal.
409+
# CloudFront + ACM for HTTPS, S3 website hosting for the redirect.
410+
# Both HTTP and HTTPS on aws.javabin.no redirect to the SSO portal.
412411
# ==============================================================================
413412

414413
resource "aws_s3_bucket" "sso_redirect" {
@@ -437,14 +436,123 @@ resource "aws_s3_bucket_public_access_block" "sso_redirect" {
437436
restrict_public_buckets = true
438437
}
439438

439+
# ACM certificate in us-east-1 (required for CloudFront)
440+
resource "aws_acm_certificate" "sso_redirect" {
441+
provider = aws.us_east_1
442+
domain_name = "aws.javabin.no"
443+
validation_method = "DNS"
444+
445+
tags = {
446+
Name = "aws.javabin.no"
447+
}
448+
449+
lifecycle {
450+
create_before_destroy = true
451+
}
452+
}
453+
454+
resource "aws_route53_record" "sso_redirect_cert_validation" {
455+
for_each = {
456+
for dvo in aws_acm_certificate.sso_redirect.domain_validation_options : dvo.domain_name => {
457+
name = dvo.resource_record_name
458+
record = dvo.resource_record_value
459+
type = dvo.resource_record_type
460+
}
461+
}
462+
463+
zone_id = aws_route53_zone.javabin_no.zone_id
464+
name = each.value.name
465+
type = each.value.type
466+
ttl = 300
467+
records = [each.value.record]
468+
allow_overwrite = true
469+
}
470+
471+
resource "aws_acm_certificate_validation" "sso_redirect" {
472+
provider = aws.us_east_1
473+
certificate_arn = aws_acm_certificate.sso_redirect.arn
474+
validation_record_fqdns = [for record in aws_route53_record.sso_redirect_cert_validation : record.fqdn]
475+
}
476+
477+
# CloudFront distribution — forwards to S3 website redirect
478+
resource "aws_cloudfront_distribution" "sso_redirect" {
479+
enabled = true
480+
aliases = ["aws.javabin.no"]
481+
comment = "aws.javabin.no → SSO portal redirect"
482+
is_ipv6_enabled = true
483+
price_class = "PriceClass_100"
484+
485+
origin {
486+
domain_name = aws_s3_bucket_website_configuration.sso_redirect.website_endpoint
487+
origin_id = "s3-redirect"
488+
489+
custom_origin_config {
490+
http_port = 80
491+
https_port = 443
492+
origin_protocol_policy = "http-only"
493+
origin_ssl_protocols = ["TLSv1.2"]
494+
}
495+
}
496+
497+
default_cache_behavior {
498+
target_origin_id = "s3-redirect"
499+
viewer_protocol_policy = "redirect-to-https"
500+
allowed_methods = ["GET", "HEAD"]
501+
cached_methods = ["GET", "HEAD"]
502+
compress = true
503+
504+
forwarded_values {
505+
query_string = false
506+
cookies {
507+
forward = "none"
508+
}
509+
}
510+
511+
min_ttl = 0
512+
default_ttl = 86400
513+
max_ttl = 86400
514+
}
515+
516+
viewer_certificate {
517+
acm_certificate_arn = aws_acm_certificate_validation.sso_redirect.certificate_arn
518+
ssl_support_method = "sni-only"
519+
minimum_protocol_version = "TLSv1.2_2021"
520+
}
521+
522+
restrictions {
523+
geo_restriction {
524+
restriction_type = "none"
525+
}
526+
}
527+
528+
tags = {
529+
Name = "aws.javabin.no-redirect"
530+
}
531+
532+
depends_on = [aws_acm_certificate_validation.sso_redirect]
533+
}
534+
535+
# Route53 alias → CloudFront (instead of S3 directly)
440536
resource "aws_route53_record" "sso_redirect" {
441537
zone_id = aws_route53_zone.javabin_no.zone_id
442538
name = "aws.javabin.no"
443539
type = "A"
444540

445541
alias {
446-
name = aws_s3_bucket_website_configuration.sso_redirect.website_domain
447-
zone_id = aws_s3_bucket.sso_redirect.hosted_zone_id
542+
name = aws_cloudfront_distribution.sso_redirect.domain_name
543+
zone_id = aws_cloudfront_distribution.sso_redirect.hosted_zone_id
544+
evaluate_target_health = false
545+
}
546+
}
547+
548+
resource "aws_route53_record" "sso_redirect_aaaa" {
549+
zone_id = aws_route53_zone.javabin_no.zone_id
550+
name = "aws.javabin.no"
551+
type = "AAAA"
552+
553+
alias {
554+
name = aws_cloudfront_distribution.sso_redirect.domain_name
555+
zone_id = aws_cloudfront_distribution.sso_redirect.hosted_zone_id
448556
evaluate_target_health = false
449557
}
450558
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
configuration_aliases = [aws.us_east_1]
6+
}
7+
}
8+
}

terraform/platform/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,9 @@ module "dns" {
113113
source = "./dns"
114114
project = var.project
115115
region = var.region
116+
117+
providers = {
118+
aws = aws
119+
aws.us_east_1 = aws.us_east_1
120+
}
116121
}

0 commit comments

Comments
 (0)