securitygroups-load-balancers.tf 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #----------------------------------------------------------------
  2. # SG for the external ELB
  3. #----------------------------------------------------------------
  4. locals {
  5. # from https://config.zscaler.com/zscalergov.net/cenr
  6. zscalar_cidrs = [
  7. "165.225.3.0/24",
  8. "136.226.10.0/23",
  9. "136.226.12.0/23",
  10. "136.226.14.0/23",
  11. "165.225.46.0/24",
  12. "136.226.6.0/23",
  13. "136.226.4.0/23",
  14. "136.226.8.0/23",
  15. "136.226.22.0/24",
  16. "165.225.48.0/24",
  17. "136.226.18.0/23",
  18. "136.226.16.0/23",
  19. "136.226.20.0/23",
  20. ]
  21. # Locking down sources on 2021-12-10 due to log4j vulnerability
  22. #allowed_sources = local.zscalar_cidrs
  23. #allowed_sources = concat(var.trusted_ips, local.zscalar_cidrs)
  24. # salt masters only for the weekend
  25. allowed_sources = [ "18.253.198.129/32" ]
  26. #allowed_sources = [ "0.0.0.0/0" ]
  27. }
  28. resource "aws_security_group" "ghe_elb_external" {
  29. name_prefix = "ghe_elb_external"
  30. tags = merge( var.standard_tags, var.tags, { Name = "github-external-lb" } )
  31. vpc_id = var.vpc_id
  32. description = "External ELB for GitHub Enterprise Server"
  33. }
  34. resource "aws_security_group_rule" "ghe_elb_external_inbound_https_22_cidr" {
  35. security_group_id = aws_security_group.ghe_elb_external.id
  36. type = "ingress"
  37. cidr_blocks = local.allowed_sources
  38. from_port = 22
  39. to_port = 22
  40. protocol = "tcp"
  41. description = "Inbound git"
  42. }
  43. resource "aws_security_group_rule" "ghe_elb_external_inbound_http_cidr" {
  44. security_group_id = aws_security_group.ghe_elb_external.id
  45. type = "ingress"
  46. cidr_blocks = local.allowed_sources
  47. from_port = 80
  48. to_port = 80
  49. protocol = "tcp"
  50. description = "Inbound http to ELB"
  51. }
  52. resource "aws_security_group_rule" "ghe_elb_external_inbound_https_cidr" {
  53. security_group_id = aws_security_group.ghe_elb_external.id
  54. type = "ingress"
  55. cidr_blocks = local.allowed_sources
  56. from_port = 443
  57. to_port = 444
  58. protocol = "tcp"
  59. description = "Inbound https to ELB"
  60. }
  61. # Let the ELB talk to the github server(s)
  62. resource "aws_security_group_rule" "ghe_elb_external_outbound_ssh" {
  63. security_group_id = aws_security_group.ghe_elb_external.id
  64. type = "egress"
  65. source_security_group_id = aws_security_group.ghe_server.id
  66. from_port = 23
  67. to_port = 23
  68. protocol = "tcp"
  69. description = "Outbound ssh (PROXY) from ELB to GH servers"
  70. }
  71. resource "aws_security_group_rule" "ghe_elb_external_outbound_http" {
  72. security_group_id = aws_security_group.ghe_elb_external.id
  73. type = "egress"
  74. source_security_group_id = aws_security_group.ghe_server.id
  75. from_port = 80
  76. to_port = 80
  77. protocol = "tcp"
  78. description = "Outbound HTTP from ELB to GH servers for LetsEncrypt on GHE"
  79. }
  80. resource "aws_security_group_rule" "ghe_elb_external_outbound_https" {
  81. security_group_id = aws_security_group.ghe_elb_external.id
  82. type = "egress"
  83. source_security_group_id = aws_security_group.ghe_server.id
  84. from_port = 443
  85. to_port = 443
  86. protocol = "tcp"
  87. description = "Outbound https from ELB to GH servers"
  88. }
  89. #----------------------------------------------------------------
  90. # SG for the internal ELB
  91. #----------------------------------------------------------------
  92. resource "aws_security_group" "ghe_elb_internal" {
  93. name_prefix = "ghe_elb_internal"
  94. tags = merge( var.standard_tags, var.tags, { Name = "github-internal-lb" } )
  95. vpc_id = var.vpc_id
  96. description = "Internal ELB for GitHub Enterprise Server"
  97. }
  98. resource "aws_security_group_rule" "ghe_elb_internal_inbound_https_cidr" {
  99. security_group_id = aws_security_group.ghe_elb_internal.id
  100. type = "ingress"
  101. cidr_blocks = [ "10.0.0.0/8" ]
  102. from_port = 443
  103. to_port = 443
  104. protocol = "tcp"
  105. description = "Inbound https"
  106. }
  107. resource "aws_security_group_rule" "ghe_elb_internal_inbound_https_8443_cidr" {
  108. security_group_id = aws_security_group.ghe_elb_internal.id
  109. type = "ingress"
  110. cidr_blocks = [ "10.0.0.0/8" ]
  111. from_port = 8443
  112. to_port = 8443
  113. protocol = "tcp"
  114. description = "Inbound https"
  115. }
  116. resource "aws_security_group_rule" "ghe_elb_internal_inbound_https_22_cidr" {
  117. security_group_id = aws_security_group.ghe_elb_internal.id
  118. type = "ingress"
  119. cidr_blocks = [ "10.0.0.0/8" ]
  120. from_port = 22
  121. to_port = 22
  122. protocol = "tcp"
  123. description = "Inbound git"
  124. }
  125. # Let the ELB talk to the github server(s)
  126. resource "aws_security_group_rule" "ghe_elb_internal_outbound_https" {
  127. security_group_id = aws_security_group.ghe_elb_internal.id
  128. type = "egress"
  129. source_security_group_id = aws_security_group.ghe_server.id
  130. from_port = 443
  131. to_port = 443
  132. protocol = "tcp"
  133. description = "Outbound https from ELB to GH Servers"
  134. }
  135. # Let the ELB talk to the github server(s)
  136. resource "aws_security_group_rule" "ghe_elb_internal_outbound_8444_https" {
  137. security_group_id = aws_security_group.ghe_elb_internal.id
  138. type = "egress"
  139. source_security_group_id = aws_security_group.ghe_server.id
  140. from_port = 8443
  141. to_port = 8444
  142. protocol = "tcp"
  143. description = "Outbound https from ELB to GH Servers"
  144. }
  145. resource "aws_security_group_rule" "ghe_elb_internal_outbound_23_https" {
  146. security_group_id = aws_security_group.ghe_elb_internal.id
  147. type = "egress"
  148. source_security_group_id = aws_security_group.ghe_server.id
  149. from_port = 23
  150. to_port = 23
  151. protocol = "tcp"
  152. description = "Outbound https from ELB to GH Servers"
  153. }