securitygroup-server.tf 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. # SG Summary - Server
  2. #
  3. # 22 - From vpc-access
  4. # 23 - From Load Balancers
  5. # 122 - From vpc-access, ghe-backup
  6. # 443-444 - From Load Balancers, vpc-access
  7. # 8443 - From vpc-access, GHE-Backup
  8. # 8444 - From Load Balancers
  9. #
  10. resource "aws_security_group" "ghe_server" {
  11. name_prefix = "ghe_server"
  12. tags = merge( var.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. # Inbound access
  18. #-----------------------------------------------------------------
  19. resource "aws_security_group_rule" "ghe_server_inbound_ssh_cidr" {
  20. security_group_id = aws_security_group.ghe_server.id
  21. type = "ingress"
  22. cidr_blocks = var.cidr_map["vpc-access"]
  23. from_port = 22
  24. to_port = 22
  25. protocol = "tcp"
  26. description = "Inbound ssh (for git)"
  27. }
  28. resource "aws_security_group_rule" "ghe_server_inbound_https_external_elb_23" {
  29. security_group_id = aws_security_group.ghe_server.id
  30. source_security_group_id = aws_security_group.ghe_elb_external.id
  31. type = "ingress"
  32. from_port = 23
  33. to_port = 23
  34. protocol = "tcp"
  35. description = "Inbound tcp/23 (ssh-proxy) from external ELBs"
  36. }
  37. resource "aws_security_group_rule" "ghe_server_inbound_https_internal_elb_23" {
  38. security_group_id = aws_security_group.ghe_server.id
  39. source_security_group_id = aws_security_group.ghe_elb_internal.id
  40. type = "ingress"
  41. from_port = 23
  42. to_port = 23
  43. protocol = "tcp"
  44. description = "Inbound tcp/23 (ssh-proxy) from internal ELBs"
  45. }
  46. resource "aws_security_group_rule" "ghe_server_inbound_external_elb_80" {
  47. security_group_id = aws_security_group.ghe_server.id
  48. source_security_group_id = aws_security_group.ghe_elb_external.id
  49. type = "ingress"
  50. from_port = 80
  51. to_port = 80
  52. protocol = "tcp"
  53. description = "Inbound HTTP from external ELBs for LetsEncrypt"
  54. }
  55. resource "aws_security_group_rule" "ghe_server_inbound_mgmt_ssh_cidr" {
  56. security_group_id = aws_security_group.ghe_server.id
  57. type = "ingress"
  58. cidr_blocks = var.cidr_map["vpc-access"]
  59. from_port = 122
  60. to_port = 122
  61. protocol = "tcp"
  62. description = "Inbound ssh (for mgmt)"
  63. }
  64. resource "aws_security_group_rule" "ghe_server_inbound_mgmt_ssh_sgs" {
  65. security_group_id = aws_security_group.ghe_server.id
  66. source_security_group_id = aws_security_group.ghe_server.id
  67. type = "ingress"
  68. from_port = 122
  69. to_port = 122
  70. protocol = "tcp"
  71. description = "Inbound ssh (for mgmt)"
  72. }
  73. resource "aws_security_group_rule" "ghe_server_inbound_mgmt_ssh_backup_sgs" {
  74. security_group_id = aws_security_group.ghe_server.id
  75. source_security_group_id = aws_security_group.ghe_backup_server.id
  76. type = "ingress"
  77. from_port = 122
  78. to_port = 122
  79. protocol = "tcp"
  80. description = "Inbound ssh (for mgmt)"
  81. }
  82. resource "aws_security_group_rule" "ghe_server_inbound_https_cidr" {
  83. security_group_id = aws_security_group.ghe_server.id
  84. type = "ingress"
  85. cidr_blocks = var.cidr_map["vpc-access"]
  86. from_port = 443
  87. to_port = 444
  88. protocol = "tcp"
  89. description = "Inbound https"
  90. }
  91. resource "aws_security_group_rule" "ghe_server_inbound_https_external_elb" {
  92. security_group_id = aws_security_group.ghe_server.id
  93. source_security_group_id = aws_security_group.ghe_elb_external.id
  94. type = "ingress"
  95. from_port = 443
  96. to_port = 444
  97. protocol = "tcp"
  98. description = "Inbound https from external ELBs"
  99. }
  100. resource "aws_security_group_rule" "ghe_server_inbound_https_internal_elb" {
  101. security_group_id = aws_security_group.ghe_server.id
  102. source_security_group_id = aws_security_group.ghe_elb_internal.id
  103. type = "ingress"
  104. from_port = 443
  105. to_port = 444
  106. protocol = "tcp"
  107. description = "Inbound https from internal ELBs"
  108. }
  109. resource "aws_security_group_rule" "ghe_server_inbound_mgmt_https_cidr" {
  110. security_group_id = aws_security_group.ghe_server.id
  111. type = "ingress"
  112. cidr_blocks = var.cidr_map["vpc-access"]
  113. from_port = 8443
  114. to_port = 8444
  115. protocol = "tcp"
  116. description = "Inbound https (for mgmt)"
  117. }
  118. resource "aws_security_group_rule" "ghe_server_inbound_mgmt_https_sgs" {
  119. security_group_id = aws_security_group.ghe_server.id
  120. source_security_group_id = aws_security_group.ghe_server.id
  121. type = "ingress"
  122. from_port = 8443
  123. to_port = 8444
  124. protocol = "tcp"
  125. description = "Inbound https (for mgmt)"
  126. }
  127. resource "aws_security_group_rule" "ghe_server_inbound_mgmt_https_backup_sgs" {
  128. security_group_id = aws_security_group.ghe_server.id
  129. source_security_group_id = aws_security_group.ghe_backup_server.id
  130. type = "ingress"
  131. from_port = 8443
  132. to_port = 8444
  133. protocol = "tcp"
  134. description = "Inbound https (for mgmt)"
  135. }
  136. resource "aws_security_group_rule" "ghe_server_inbound_https_internal_elb_8444" {
  137. security_group_id = aws_security_group.ghe_server.id
  138. source_security_group_id = aws_security_group.ghe_elb_internal.id
  139. type = "ingress"
  140. from_port = 8443
  141. to_port = 8444
  142. protocol = "tcp"
  143. description = "Inbound https/8444 from internal ELBs"
  144. }
  145. resource "aws_security_group_rule" "ghe_server_inbound_https_external_elb_8444" {
  146. security_group_id = aws_security_group.ghe_server.id
  147. source_security_group_id = aws_security_group.ghe_elb_external.id
  148. type = "ingress"
  149. from_port = 8443
  150. to_port = 8444
  151. protocol = "tcp"
  152. description = "Inbound https/8444 from external ELBs"
  153. }
  154. #-----------------------------------------------------------------
  155. # Outbound access
  156. #-----------------------------------------------------------------
  157. resource "aws_security_group_rule" "ghe_server_outbound_http" {
  158. security_group_id = aws_security_group.ghe_server.id
  159. type = "egress"
  160. cidr_blocks = [ "0.0.0.0/0" ]
  161. from_port = 80
  162. to_port = 80
  163. protocol = "tcp"
  164. description = "Outbound http for letsencrypt"
  165. }
  166. resource "aws_security_group_rule" "ghe_server_outbound_https" {
  167. security_group_id = aws_security_group.ghe_server.id
  168. type = "egress"
  169. cidr_blocks = [ "0.0.0.0/0" ]
  170. from_port = 443
  171. to_port = 443
  172. protocol = "tcp"
  173. description = "Outbound https for letsencrypt"
  174. }
  175. resource "aws_security_group_rule" "ghe_server_outbound_syslog" {
  176. security_group_id = aws_security_group.ghe_server.id
  177. type = "egress"
  178. cidr_blocks = var.cidr_map["vpc-splunk"]
  179. from_port = 1514
  180. to_port = 1514
  181. protocol = "tcp"
  182. description = "Outbound syslog"
  183. }