securitygroup-server.tf 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. # SG Summary - Server
  2. #
  3. # 22 - From anywhere
  4. # 122 - From vpc-access, ghe-backup
  5. # 443-444 - From Load Balancers, vpc-access
  6. # 8443 - From vpc-access, GHE-Backup
  7. # 8444 - From Load Balancers
  8. #
  9. resource "aws_security_group" "ghe_server" {
  10. name_prefix = "ghe_server"
  11. tags = merge(local.standard_tags, var.tags, { Name = "github-enterprise-server" })
  12. vpc_id = var.vpc_id
  13. description = "GitHub Enterprise Servers and Backup Servers"
  14. }
  15. #-----------------------------------------------------------------
  16. # Inbound access
  17. #-----------------------------------------------------------------
  18. resource "aws_security_group_rule" "ghe_server_inbound_22" {
  19. security_group_id = aws_security_group.ghe_server.id
  20. type = "ingress"
  21. from_port = 22
  22. to_port = 22
  23. protocol = "tcp"
  24. description = "Inbound tcp/22 (ssh) from external IPs (through NLB)"
  25. cidr_blocks = ["0.0.0.0/0"] # tfsec:ignore:aws-vpc-no-public-ingress-sgr Intentionally Open
  26. }
  27. resource "aws_security_group_rule" "ghe_server_inbound_external_elb_80" {
  28. security_group_id = aws_security_group.ghe_server.id
  29. source_security_group_id = module.elb.security_group_id
  30. type = "ingress"
  31. from_port = 80
  32. to_port = 80
  33. protocol = "tcp"
  34. description = "Inbound HTTP from external ELBs for LetsEncrypt"
  35. }
  36. resource "aws_security_group_rule" "ghe_server_inbound_mgmt_ssh_cidr" {
  37. security_group_id = aws_security_group.ghe_server.id
  38. type = "ingress"
  39. cidr_blocks = local.cidr_map["vpc-access"]
  40. from_port = 122
  41. to_port = 122
  42. protocol = "tcp"
  43. description = "Inbound ssh (for mgmt)"
  44. }
  45. resource "aws_security_group_rule" "ghe_server_inbound_mgmt_ssh_sgs" {
  46. security_group_id = aws_security_group.ghe_server.id
  47. source_security_group_id = aws_security_group.ghe_server.id
  48. type = "ingress"
  49. from_port = 122
  50. to_port = 122
  51. protocol = "tcp"
  52. description = "Inbound ssh (for mgmt)"
  53. }
  54. resource "aws_security_group_rule" "ghe_server_inbound_mgmt_ssh_backup_sgs" {
  55. security_group_id = aws_security_group.ghe_server.id
  56. source_security_group_id = aws_security_group.ghe_backup_server.id
  57. type = "ingress"
  58. from_port = 122
  59. to_port = 122
  60. protocol = "tcp"
  61. description = "Inbound ssh (for mgmt)"
  62. }
  63. resource "aws_security_group_rule" "ghe_server_inbound_https_cidr" {
  64. security_group_id = aws_security_group.ghe_server.id
  65. type = "ingress"
  66. cidr_blocks = local.cidr_map["vpc-access"]
  67. from_port = 443
  68. to_port = 444
  69. protocol = "tcp"
  70. description = "Inbound https"
  71. }
  72. resource "aws_security_group_rule" "ghe_server_inbound_https_external_elb" {
  73. security_group_id = aws_security_group.ghe_server.id
  74. source_security_group_id = module.elb.security_group_id
  75. type = "ingress"
  76. from_port = 443
  77. to_port = 444
  78. protocol = "tcp"
  79. description = "Inbound https from external ELBs"
  80. }
  81. resource "aws_security_group_rule" "ghe_server_inbound_https_internal_elb" {
  82. security_group_id = aws_security_group.ghe_server.id
  83. source_security_group_id = aws_security_group.ghe_elb_internal.id
  84. type = "ingress"
  85. from_port = 443
  86. to_port = 444
  87. protocol = "tcp"
  88. description = "Inbound https from internal ELBs"
  89. }
  90. resource "aws_security_group_rule" "ghe_server_inbound_mgmt_https_cidr" {
  91. security_group_id = aws_security_group.ghe_server.id
  92. type = "ingress"
  93. cidr_blocks = local.cidr_map["vpc-access"]
  94. from_port = 8443
  95. to_port = 8444
  96. protocol = "tcp"
  97. description = "Inbound https (for mgmt)"
  98. }
  99. resource "aws_security_group_rule" "ghe_server_inbound_mgmt_https_sgs" {
  100. security_group_id = aws_security_group.ghe_server.id
  101. source_security_group_id = aws_security_group.ghe_server.id
  102. type = "ingress"
  103. from_port = 8443
  104. to_port = 8444
  105. protocol = "tcp"
  106. description = "Inbound https (for mgmt)"
  107. }
  108. resource "aws_security_group_rule" "ghe_server_inbound_mgmt_https_backup_sgs" {
  109. security_group_id = aws_security_group.ghe_server.id
  110. source_security_group_id = aws_security_group.ghe_backup_server.id
  111. type = "ingress"
  112. from_port = 8443
  113. to_port = 8444
  114. protocol = "tcp"
  115. description = "Inbound https (for mgmt)"
  116. }
  117. resource "aws_security_group_rule" "ghe_server_inbound_https_internal_elb_8444" {
  118. security_group_id = aws_security_group.ghe_server.id
  119. source_security_group_id = aws_security_group.ghe_elb_internal.id
  120. type = "ingress"
  121. from_port = 8443
  122. to_port = 8444
  123. protocol = "tcp"
  124. description = "Inbound https/8444 from internal ELBs"
  125. }
  126. resource "aws_security_group_rule" "ghe_server_inbound_https_external_elb_8444" {
  127. security_group_id = aws_security_group.ghe_server.id
  128. source_security_group_id = module.elb.security_group_id
  129. type = "ingress"
  130. from_port = 8443
  131. to_port = 8444
  132. protocol = "tcp"
  133. description = "Inbound https/8444 from external ELBs"
  134. }
  135. #-----------------------------------------------------------------
  136. # Outbound access
  137. #-----------------------------------------------------------------
  138. resource "aws_security_group_rule" "ghe_server_outbound_http" {
  139. security_group_id = aws_security_group.ghe_server.id
  140. type = "egress"
  141. cidr_blocks = ["0.0.0.0/0"] # tfsec:ignore:aws-vpc-no-public-egress-sgr Purposefully accessible
  142. from_port = 80
  143. to_port = 80
  144. protocol = "tcp"
  145. description = "Outbound http for letsencrypt"
  146. }
  147. resource "aws_security_group_rule" "ghe_server_outbound_https" {
  148. security_group_id = aws_security_group.ghe_server.id
  149. type = "egress"
  150. cidr_blocks = ["0.0.0.0/0"] # tfsec:ignore:aws-vpc-no-public-egress-sgr Purposefully accessible
  151. from_port = 443
  152. to_port = 443
  153. protocol = "tcp"
  154. description = "Outbound https for letsencrypt"
  155. }
  156. resource "aws_security_group_rule" "ghe_server_outbound_syslog" {
  157. security_group_id = aws_security_group.ghe_server.id
  158. type = "egress"
  159. cidr_blocks = local.cidr_map["vpc-splunk"]
  160. from_port = 1514
  161. to_port = 1514
  162. protocol = "tcp"
  163. description = "Outbound syslog"
  164. }