securitygroup-server.tf 6.9 KB

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