elb-auth.tf 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. resource "aws_lb" "searchhead-auth-alb" {
  2. name = "${local.alb_name}-auth"
  3. internal = false
  4. load_balancer_type = "application"
  5. # Not supported for NLB
  6. security_groups = [aws_security_group.searchhead-auth-alb-sg.id]
  7. # Note, changing subnets results in recreation of the resource
  8. subnets = var.public_subnets
  9. enable_cross_zone_load_balancing = true
  10. access_logs {
  11. bucket = "xdr-elb-${ var.environment }"
  12. enabled = true
  13. }
  14. tags = merge(var.standard_tags, var.tags)
  15. }
  16. #########################
  17. # Listeners
  18. resource "aws_lb_listener" "searchhead-auth-alb-listener-https" {
  19. load_balancer_arn = aws_lb.searchhead-auth-alb.arn
  20. port = "443"
  21. protocol = "HTTPS"
  22. ssl_policy = "ELBSecurityPolicy-FS-1-2-Res-2019-08" # PFS, TLS1.2, most "restrictive" policy (took awhile to find that)
  23. certificate_arn = aws_acm_certificate.cert-auth.arn
  24. default_action {
  25. type = "forward"
  26. target_group_arn = aws_lb_target_group.searchhead-auth-alb-target-10000.arn
  27. }
  28. }
  29. # Redirect HTTP to HTTPS
  30. resource "aws_lb_listener" "searchhead-auth-alb-listener-http" {
  31. load_balancer_arn = aws_lb.searchhead-auth-alb.arn
  32. port = "80"
  33. protocol = "HTTP"
  34. default_action {
  35. type = "redirect"
  36. redirect {
  37. port = "443"
  38. protocol = "HTTPS"
  39. status_code = "HTTP_301"
  40. }
  41. }
  42. }
  43. #########################
  44. # Targets
  45. resource "aws_lb_target_group" "searchhead-auth-alb-target-10000" {
  46. name = "${local.alb_name}-10000"
  47. port = 10000
  48. protocol = "HTTPS"
  49. target_type = "instance"
  50. vpc_id = var.vpc_id
  51. tags = merge(var.standard_tags, var.tags)
  52. health_check {
  53. enabled = true
  54. path = "/Saml2IDP/proxy.xml"
  55. port = 10000
  56. protocol = "HTTPS"
  57. }
  58. # Stickiness is not needed here, but we'll need it if we add SHs
  59. stickiness {
  60. type = "lb_cookie"
  61. cookie_duration = 86400 # 1 day
  62. enabled = true
  63. }
  64. }
  65. resource "aws_lb_target_group_attachment" "searchhead-auth-alb-target-10000-instance" {
  66. target_group_arn = aws_lb_target_group.searchhead-auth-alb-target-10000.arn
  67. target_id = aws_instance.instance.id
  68. port = 10000
  69. }
  70. #########################
  71. # Security Group for ALB
  72. resource "aws_security_group" "searchhead-auth-alb-sg" {
  73. name = "${local.alb_name}-customer-auth-alb-sh"
  74. description = "Security Group for the Customer Searchhead Authorization ALB"
  75. vpc_id = var.vpc_id
  76. tags = merge(var.standard_tags, var.tags)
  77. }
  78. resource "aws_security_group_rule" "searchhead-auth-alb-https-in" {
  79. type = "ingress"
  80. from_port = 443
  81. to_port = 443
  82. protocol = "tcp"
  83. cidr_blocks = local.alb_clients
  84. security_group_id = aws_security_group.searchhead-auth-alb-sg.id
  85. }
  86. resource "aws_security_group_rule" "searchhead-auth-http-in" {
  87. # Port 80 is open as a redirect to 443
  88. type = "ingress"
  89. from_port = 80
  90. to_port = 80
  91. protocol = "tcp"
  92. cidr_blocks = local.alb_clients
  93. security_group_id = aws_security_group.searchhead-auth-alb-sg.id
  94. }
  95. resource "aws_security_group_rule" "searchhead-auth-alb-10000-out" {
  96. type = "egress"
  97. from_port = 10000
  98. to_port = 10000
  99. protocol = "tcp"
  100. # Maybe should limit to the local vpc, but I don't readily have that cidr available
  101. cidr_blocks = [ var.vpc_cidr ]
  102. security_group_id = aws_security_group.searchhead-auth-alb-sg.id
  103. }
  104. #########################
  105. # DNS Entry
  106. module "public_dns_record_cust-auth-elb" {
  107. source = "../../../submodules/dns/public_ALIAS_record"
  108. name = "${local.auth_short_name}"
  109. target_dns_name = aws_lb.searchhead-auth-alb.dns_name
  110. target_zone_id = aws_lb.searchhead-auth-alb.zone_id
  111. dns_info = var.dns_info
  112. providers = {
  113. aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
  114. }
  115. }