securitygroups-load-balancers.tf 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. salt_masters = [
  22. "18.253.198.129/32", # Salt Master Prod - proxy
  23. "18.253.73.251/32", # salt master prod
  24. "18.252.61.81/32", # Salt master dev - proxy
  25. "18.253.226.199/32", # salt aster dev
  26. ]
  27. # Locking down sources on 2021-12-10 due to log4j vulnerability
  28. #allowed_sources = local.zscalar_cidrs
  29. #allowed_sources = concat(var.trusted_ips, local.zscalar_cidrs)
  30. #allowed_sources = concat(local.zscalar_cidrs, var.trusted_ips, local.salt_masters)
  31. # Restored access on 2021-12-14
  32. allowed_sources = [ "0.0.0.0/0" ]
  33. }
  34. resource "aws_security_group" "ghe_elb_external" {
  35. name_prefix = "ghe_elb_external"
  36. tags = merge( var.standard_tags, var.tags, { Name = "github-external-lb" } )
  37. vpc_id = var.vpc_id
  38. description = "External ELB for GitHub Enterprise Server"
  39. }
  40. resource "aws_security_group_rule" "ghe_elb_external_inbound_https_22_cidr" {
  41. security_group_id = aws_security_group.ghe_elb_external.id
  42. type = "ingress"
  43. cidr_blocks = local.allowed_sources
  44. from_port = 22
  45. to_port = 22
  46. protocol = "tcp"
  47. description = "Inbound git"
  48. }
  49. resource "aws_security_group_rule" "ghe_elb_external_inbound_http_cidr" {
  50. security_group_id = aws_security_group.ghe_elb_external.id
  51. type = "ingress"
  52. cidr_blocks = local.allowed_sources
  53. from_port = 80
  54. to_port = 80
  55. protocol = "tcp"
  56. description = "Inbound http to ELB"
  57. }
  58. resource "aws_security_group_rule" "ghe_elb_external_inbound_https_cidr" {
  59. security_group_id = aws_security_group.ghe_elb_external.id
  60. type = "ingress"
  61. cidr_blocks = local.allowed_sources
  62. from_port = 443
  63. to_port = 444
  64. protocol = "tcp"
  65. description = "Inbound https to ELB"
  66. }
  67. # Let the ELB talk to the github server(s)
  68. resource "aws_security_group_rule" "ghe_elb_external_outbound_ssh" {
  69. security_group_id = aws_security_group.ghe_elb_external.id
  70. type = "egress"
  71. source_security_group_id = aws_security_group.ghe_server.id
  72. from_port = 23
  73. to_port = 23
  74. protocol = "tcp"
  75. description = "Outbound ssh (PROXY) from ELB to GH servers"
  76. }
  77. resource "aws_security_group_rule" "ghe_elb_external_outbound_http" {
  78. security_group_id = aws_security_group.ghe_elb_external.id
  79. type = "egress"
  80. source_security_group_id = aws_security_group.ghe_server.id
  81. from_port = 80
  82. to_port = 80
  83. protocol = "tcp"
  84. description = "Outbound HTTP from ELB to GH servers for LetsEncrypt on GHE"
  85. }
  86. resource "aws_security_group_rule" "ghe_elb_external_outbound_https" {
  87. security_group_id = aws_security_group.ghe_elb_external.id
  88. type = "egress"
  89. source_security_group_id = aws_security_group.ghe_server.id
  90. from_port = 443
  91. to_port = 443
  92. protocol = "tcp"
  93. description = "Outbound https from ELB to GH servers"
  94. }
  95. #----------------------------------------------------------------
  96. # SG for the internal ELB
  97. #----------------------------------------------------------------
  98. resource "aws_security_group" "ghe_elb_internal" {
  99. name_prefix = "ghe_elb_internal"
  100. tags = merge( var.standard_tags, var.tags, { Name = "github-internal-lb" } )
  101. vpc_id = var.vpc_id
  102. description = "Internal ELB for GitHub Enterprise Server"
  103. }
  104. resource "aws_security_group_rule" "ghe_elb_internal_inbound_https_cidr" {
  105. security_group_id = aws_security_group.ghe_elb_internal.id
  106. type = "ingress"
  107. cidr_blocks = [ "10.0.0.0/8" ]
  108. from_port = 443
  109. to_port = 443
  110. protocol = "tcp"
  111. description = "Inbound https"
  112. }
  113. resource "aws_security_group_rule" "ghe_elb_internal_inbound_https_8443_cidr" {
  114. security_group_id = aws_security_group.ghe_elb_internal.id
  115. type = "ingress"
  116. cidr_blocks = [ "10.0.0.0/8" ]
  117. from_port = 8443
  118. to_port = 8443
  119. protocol = "tcp"
  120. description = "Inbound https"
  121. }
  122. resource "aws_security_group_rule" "ghe_elb_internal_inbound_https_22_cidr" {
  123. security_group_id = aws_security_group.ghe_elb_internal.id
  124. type = "ingress"
  125. cidr_blocks = [ "10.0.0.0/8" ]
  126. from_port = 22
  127. to_port = 22
  128. protocol = "tcp"
  129. description = "Inbound git"
  130. }
  131. # Let the ELB talk to the github server(s)
  132. resource "aws_security_group_rule" "ghe_elb_internal_outbound_https" {
  133. security_group_id = aws_security_group.ghe_elb_internal.id
  134. type = "egress"
  135. source_security_group_id = aws_security_group.ghe_server.id
  136. from_port = 443
  137. to_port = 443
  138. protocol = "tcp"
  139. description = "Outbound https from ELB to GH Servers"
  140. }
  141. # Let the ELB talk to the github server(s)
  142. resource "aws_security_group_rule" "ghe_elb_internal_outbound_8444_https" {
  143. security_group_id = aws_security_group.ghe_elb_internal.id
  144. type = "egress"
  145. source_security_group_id = aws_security_group.ghe_server.id
  146. from_port = 8443
  147. to_port = 8444
  148. protocol = "tcp"
  149. description = "Outbound https from ELB to GH Servers"
  150. }
  151. resource "aws_security_group_rule" "ghe_elb_internal_outbound_23_https" {
  152. security_group_id = aws_security_group.ghe_elb_internal.id
  153. type = "egress"
  154. source_security_group_id = aws_security_group.ghe_server.id
  155. from_port = 23
  156. to_port = 23
  157. protocol = "tcp"
  158. description = "Outbound https from ELB to GH Servers"
  159. }