security-groups.tf 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. # From vmray admin installation guide, page 24
  2. # Clients to server on 443
  3. # Server to workers on 5900-5999 (VNC)
  4. # Workers to server on 80 and 443
  5. #----------------------------------------------------------------------------
  6. # VMRAY Server ALB Security Group
  7. #----------------------------------------------------------------------------
  8. resource "aws_security_group" "vmray_server_sg" {
  9. # checkov:skip=CKV2_AWS_5: this SG is attached to VMRAY Server
  10. name = "vmray_server_sg"
  11. description = "Security Rules Specific to VMRay"
  12. vpc_id = var.vpc_id
  13. tags = merge(local.standard_tags, var.tags)
  14. }
  15. #----------------------------------------------------------------------------
  16. # INGRESS
  17. #----------------------------------------------------------------------------
  18. resource "aws_security_group_rule" "vmray_server_http_in_from_workers" {
  19. type = "ingress"
  20. description = "HTTP - Inbound port 80 for redirect from other VMRAY Servers"
  21. from_port = 80
  22. to_port = 80
  23. protocol = "tcp"
  24. source_security_group_id = aws_security_group.vmray_worker_sg.id
  25. security_group_id = aws_security_group.vmray_server_sg.id
  26. }
  27. resource "aws_security_group_rule" "vmray_server_https_in_from_workers" {
  28. type = "ingress"
  29. description = "HTTPS - Inbound for interserver communication from other VMRAY Servers"
  30. from_port = 443
  31. to_port = 443
  32. protocol = "tcp"
  33. source_security_group_id = aws_security_group.vmray_worker_sg.id
  34. security_group_id = aws_security_group.vmray_server_sg.id
  35. }
  36. resource "aws_security_group_rule" "vmray_server_https_in" {
  37. type = "ingress"
  38. description = "HTTPS - Inbound - from the VPN"
  39. from_port = 443
  40. to_port = 443
  41. protocol = "tcp"
  42. #cidr_blocks = local.cidr_map["vpc-access"]
  43. source_security_group_id = aws_security_group.vmray_alb_internal.id
  44. security_group_id = aws_security_group.vmray_server_sg.id
  45. }
  46. #----------------------------------------------------------------------------
  47. # EGRESS
  48. #----------------------------------------------------------------------------
  49. ## VMRay Does DNS Lookups to the Local Network
  50. resource "aws_security_group_rule" "vmray_server_tcpdns_out" {
  51. type = "egress"
  52. description = "DNS TCP - Outbound - lookups to the local DNS server"
  53. from_port = 53
  54. to_port = 53
  55. protocol = "tcp"
  56. cidr_blocks = [var.vpc_info["cidr"]]
  57. security_group_id = aws_security_group.vmray_server_sg.id
  58. }
  59. resource "aws_security_group_rule" "vmray_server_udpdns_out" {
  60. type = "egress"
  61. description = "DNS UDP - Outbound - lookups to the local DNS server"
  62. from_port = 53
  63. to_port = 53
  64. protocol = "udp"
  65. cidr_blocks = [var.vpc_info["cidr"]]
  66. security_group_id = aws_security_group.vmray_server_sg.id
  67. }
  68. resource "aws_security_group_rule" "vmray_server_http_out" {
  69. type = "egress"
  70. description = "HTTP - Outbound - VMRay requirement"
  71. from_port = 80
  72. to_port = 80
  73. protocol = "tcp"
  74. cidr_blocks = ["0.0.0.0/0"] # tfsec:ignore:aws-vpc-no-public-egress-sgr VMRay Requires Direct Internet Access
  75. security_group_id = aws_security_group.vmray_server_sg.id
  76. }
  77. resource "aws_security_group_rule" "vmray_server_https_out" {
  78. type = "egress"
  79. description = "HTTPS - Outbound - VMRay requirement"
  80. from_port = 443
  81. to_port = 443
  82. protocol = "tcp"
  83. cidr_blocks = ["0.0.0.0/0"] # tfsec:ignore:aws-vpc-no-public-egress-sgr VMRay Requires Direct Internet Access
  84. security_group_id = aws_security_group.vmray_server_sg.id
  85. }
  86. resource "aws_security_group_rule" "vmray_server_vnc_to_workers" {
  87. type = "egress"
  88. description = "VMRay uses VNC for client machine access."
  89. from_port = 5900
  90. to_port = 5999
  91. protocol = "tcp"
  92. source_security_group_id = aws_security_group.vmray_worker_sg.id
  93. security_group_id = aws_security_group.vmray_server_sg.id
  94. }
  95. #----------------------------------------------------------------------------
  96. # VMRAY Worker ALB Security Group
  97. #----------------------------------------------------------------------------
  98. resource "aws_security_group" "vmray_worker_sg" {
  99. # checkov:skip=CKV2_AWS_5: this SG is attached to VMRAY worker
  100. name = "vmray_worker_sg"
  101. description = "Security Rules for the VMRay Worker Nodes"
  102. vpc_id = var.vpc_id
  103. tags = merge(local.standard_tags, var.tags)
  104. }
  105. #----------------------------------------------------------------------------
  106. # INGRESS
  107. #----------------------------------------------------------------------------
  108. resource "aws_security_group_rule" "vmwary_worker_vnc_from_server" {
  109. description = "VMRay uses VNC for client machine access."
  110. type = "ingress"
  111. from_port = 5900
  112. to_port = 5999
  113. protocol = "tcp"
  114. source_security_group_id = aws_security_group.vmray_server_sg.id
  115. security_group_id = aws_security_group.vmray_worker_sg.id
  116. }
  117. resource "aws_security_group_rule" "vmwary_worker_vnc_from_access" {
  118. description = "VMRay uses VNC for client machine access."
  119. type = "ingress"
  120. from_port = 5900
  121. to_port = 5999
  122. protocol = "tcp"
  123. cidr_blocks = local.cidr_map["vpc-access"]
  124. security_group_id = aws_security_group.vmray_worker_sg.id
  125. }
  126. #----------------------------------------------------------------------------
  127. # EGRESS
  128. #----------------------------------------------------------------------------
  129. resource "aws_security_group_rule" "vmray_worker_tcpdns_out" {
  130. type = "egress"
  131. description = "VMRay DNS TCP - Outbound to instance in local vpc."
  132. from_port = 53
  133. to_port = 53
  134. protocol = "tcp"
  135. cidr_blocks = [var.vpc_info["cidr"]]
  136. security_group_id = aws_security_group.vmray_worker_sg.id
  137. }
  138. resource "aws_security_group_rule" "vmray_worker_udpdns_out" {
  139. type = "egress"
  140. description = "VMRay DNS UDP - Outbound to instance in local vpc."
  141. from_port = 53
  142. to_port = 53
  143. protocol = "udp"
  144. cidr_blocks = [var.vpc_info["cidr"]]
  145. security_group_id = aws_security_group.vmray_worker_sg.id
  146. }
  147. # tfsec:ignore:aws-vpc-no-public-egress-sgr VMRay Requires Direct Internet Access
  148. resource "aws_security_group_rule" "vmray_worker_http_out" {
  149. type = "egress"
  150. description = "HTTP - Outbound - VMRay requires direct HTTP access."
  151. from_port = 80
  152. to_port = 80
  153. protocol = "tcp"
  154. cidr_blocks = ["0.0.0.0/0"]
  155. security_group_id = aws_security_group.vmray_worker_sg.id
  156. }
  157. # tfsec:ignore:aws-vpc-no-public-egress-sgr VMRay Requires Direct Internet Access
  158. resource "aws_security_group_rule" "vmray_worker_https_out" {
  159. type = "egress"
  160. description = "HTTPS - Outbound - VMRay requires direct HTTPS access."
  161. from_port = 443
  162. to_port = 443
  163. protocol = "tcp"
  164. cidr_blocks = ["0.0.0.0/0"]
  165. security_group_id = aws_security_group.vmray_worker_sg.id
  166. }
  167. resource "aws_security_group_rule" "vmray_worker_http_to_server" {
  168. type = "egress"
  169. description = "HTTP - VMRay worker communicates with the server."
  170. from_port = 80
  171. to_port = 80
  172. protocol = "tcp"
  173. source_security_group_id = aws_security_group.vmray_server_sg.id
  174. security_group_id = aws_security_group.vmray_worker_sg.id
  175. }
  176. resource "aws_security_group_rule" "vmray_worker_https_to_server" {
  177. type = "egress"
  178. description = "HTTPS - VMRay worker communicates with the server."
  179. from_port = 443
  180. to_port = 443
  181. protocol = "tcp"
  182. source_security_group_id = aws_security_group.vmray_server_sg.id
  183. security_group_id = aws_security_group.vmray_worker_sg.id
  184. }