SG.tf 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. resource "yandex_vpc_security_group" "sg-inet-acc" {
  2. name = "sg-inet-acc"
  3. description = "defines which environments can access NAT-Instance for Internet access"
  4. network_id = yandex_vpc_network.vpc-infra.id
  5. ingress {
  6. protocol = "ICMP"
  7. description = "Allow pings from all networks for tshoot"
  8. v4_cidr_blocks = ["10.0.0.0/8"]
  9. }
  10. ingress {
  11. protocol = "TCP"
  12. description = "CI-CD can only access well-known ports to update packages"
  13. security_group_id = yandex_vpc_security_group.sg-ci-cd.id
  14. port = 443
  15. }
  16. ingress {
  17. protocol = "TCP"
  18. description = "CI-CD can only access well-known ports to update packages"
  19. security_group_id = yandex_vpc_security_group.sg-ci-cd.id
  20. port = 80
  21. }
  22. ingress {
  23. protocol = "TCP"
  24. description = "stage can only access well-known ports to update packages"
  25. security_group_id = yandex_vpc_security_group.sg-stage.id
  26. port = 443
  27. }
  28. ingress {
  29. protocol = "TCP"
  30. description = "stage can only access well-known ports to update packages"
  31. security_group_id = yandex_vpc_security_group.sg-stage.id
  32. port = 80
  33. }
  34. egress {
  35. protocol = "ANY"
  36. description = "NAT-INSTANCE can access internet"
  37. v4_cidr_blocks = ["0.0.0.0/0"]
  38. }
  39. }
  40. resource "yandex_vpc_security_group" "sg-bastion" {
  41. name = "sg-bastion"
  42. description = "allows connecting to bastion only from whitelisted address"
  43. network_id = yandex_vpc_network.vpc-infra.id
  44. labels = {
  45. type = "bastion-whitelist"
  46. }
  47. ingress {
  48. protocol = "TCP"
  49. description = "allow-ssh-from-trusted-ip"
  50. v4_cidr_blocks = var.bastion_whitelist_ip
  51. port = 22
  52. }
  53. ingress {
  54. protocol = "ICMP"
  55. description = "allow-icmp-from-trusted-ip"
  56. v4_cidr_blocks = var.bastion_whitelist_ip
  57. }
  58. egress {
  59. protocol = "ANY"
  60. description = "we allow any egress, since we block on ingress"
  61. v4_cidr_blocks = ["0.0.0.0/0"]
  62. }
  63. }
  64. resource "yandex_vpc_security_group" "sg-ci-cd" {
  65. name = "sg-ci-cd"
  66. description = "allows ci-cd tools to manage stage and prod"
  67. network_id = yandex_vpc_network.vpc-infra.id
  68. ingress {
  69. protocol = "TCP"
  70. description = "allows remote access only through Bastion"
  71. security_group_id = yandex_vpc_security_group.sg-bastion.id
  72. port = 22
  73. }
  74. ingress {
  75. protocol = "ICMP"
  76. description = "allows ping only from bastion"
  77. security_group_id = yandex_vpc_security_group.sg-bastion.id
  78. }
  79. ingress {
  80. protocol = "TCP"
  81. description = "allows for config sync for ci-cd workers"
  82. predefined_target = "self_security_group"
  83. port = 22
  84. }
  85. egress {
  86. protocol = "ANY"
  87. description = "we allow any ingress, since we block prod on ingress"
  88. v4_cidr_blocks = ["0.0.0.0/0"]
  89. }
  90. }
  91. resource "yandex_vpc_security_group" "sg-dev" {
  92. name = "sg-dev"
  93. description = "allows isolated dev environment, can be accesed from whitelisted ip"
  94. network_id = yandex_vpc_network.vpc-infra.id
  95. folder_id = var.dev_folder_id
  96. ingress {
  97. protocol = "TCP"
  98. description = "allow-ssh-from-trusted-ip"
  99. v4_cidr_blocks = var.bastion_whitelist_ip
  100. port = 22
  101. }
  102. ingress {
  103. protocol = "ICMP"
  104. description = "allow-icmp-from-trusted-ip"
  105. v4_cidr_blocks = var.bastion_whitelist_ip
  106. }
  107. egress {
  108. protocol = "ANY"
  109. description = "we allow any egress for sandbox, since we block prod on ingress"
  110. v4_cidr_blocks = ["0.0.0.0/0"]
  111. }
  112. }
  113. resource "yandex_vpc_security_group" "sg-stage" {
  114. name = "sg-stage"
  115. description = "allows ci-cd tools to manage stage and prod"
  116. network_id = yandex_vpc_network.vpc-infra.id
  117. folder_id = var.stage_folder_id
  118. ingress {
  119. protocol = "TCP"
  120. description = "allows remote access through Bastion"
  121. security_group_id = yandex_vpc_security_group.sg-bastion.id
  122. port = 22
  123. }
  124. ingress {
  125. protocol = "ICMP"
  126. description = "allows ping through Bastion"
  127. security_group_id = yandex_vpc_security_group.sg-bastion.id
  128. }
  129. ingress {
  130. protocol = "TCP"
  131. description = "allows deploy from ci-cd"
  132. security_group_id = yandex_vpc_security_group.sg-ci-cd.id
  133. port = 22
  134. }
  135. ingress {
  136. protocol = "ICMP"
  137. description = "allows ping from ci cd"
  138. security_group_id = yandex_vpc_security_group.sg-ci-cd.id
  139. }
  140. egress {
  141. protocol = "ANY"
  142. description = "we allow any egress for stage, since we block prod on ingress"
  143. v4_cidr_blocks = ["0.0.0.0/0"]
  144. }
  145. }
  146. resource "yandex_vpc_security_group" "sg-prod" {
  147. name = "sg-prod"
  148. description = "allows ci-cd tools to manage stage and prod"
  149. network_id = yandex_vpc_network.vpc-infra.id
  150. folder_id = var.prod_folder_id
  151. ingress {
  152. protocol = "TCP"
  153. description = "allows deploy from ci-cd only no manual access"
  154. security_group_id = yandex_vpc_security_group.sg-ci-cd.id
  155. port = 22
  156. }
  157. ingress {
  158. protocol = "icmp"
  159. description = "allows ping from ci cd only"
  160. security_group_id = yandex_vpc_security_group.sg-ci-cd.id
  161. }
  162. egress {
  163. protocol = "ANY"
  164. description = "we allow any egress for stage, since we block prod on ingress"
  165. v4_cidr_blocks = ["0.0.0.0/0"]
  166. }
  167. }