security-groups.tf 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Rather than pass in the aws security group, we just look it up. This will
  2. # probably be useful other places, as well.
  3. data "aws_security_group" "typical-host" {
  4. name = "typical-host"
  5. vpc_id = var.vpc_id
  6. }
  7. #----------------------------------------------------------------------------
  8. # Security Group for Teleport
  9. #----------------------------------------------------------------------------
  10. resource "aws_security_group" "instance" {
  11. # checkov:skip=CKV2_AWS_5: this SG is attached to Teleport
  12. # use name_prefix instead of name and create-before-destroy on security groups and alb target groups to make future changes easier,
  13. # otherwise, you get stuck in `destroying` during routine changes.
  14. name_prefix = "instance-${var.instance_name}"
  15. description = "Instances of type ${var.instance_name}"
  16. vpc_id = var.vpc_id
  17. tags = merge(local.standard_tags, var.tags)
  18. lifecycle {
  19. create_before_destroy = true
  20. }
  21. }
  22. #----------------------------------------------------------------------------
  23. # INGRESS
  24. #----------------------------------------------------------------------------
  25. resource "aws_security_group_rule" "instance-http-in-external" {
  26. type = "ingress"
  27. description = "Web Interface from External ALB"
  28. from_port = "3080"
  29. to_port = "3080"
  30. protocol = "tcp"
  31. source_security_group_id = aws_security_group.alb_server_external.id
  32. security_group_id = aws_security_group.instance.id
  33. }
  34. resource "aws_security_group_rule" "instance-http-in-internal" {
  35. type = "ingress"
  36. description = "Web Interface from Internal ALB"
  37. from_port = "3080"
  38. to_port = "3080"
  39. protocol = "tcp"
  40. source_security_group_id = aws_security_group.alb_server_internal.id
  41. security_group_id = aws_security_group.instance.id
  42. }
  43. resource "aws_security_group_rule" "instance-teleport-in-3023-3026" {
  44. type = "ingress"
  45. description = "Teleport Proprietary Ports via NLB"
  46. from_port = "3023"
  47. to_port = "3026"
  48. protocol = "tcp"
  49. cidr_blocks = ["0.0.0.0/0"] # tfsec:ignore:aws-vpc-no-public-ingress-sgr
  50. security_group_id = aws_security_group.instance.id
  51. }
  52. #resource "aws_security_group_rule" "instance-teleport-in-3026" {
  53. # description = "Teleport Proprietary Ports via NLB"
  54. # type = "ingress"
  55. # from_port = "3026"
  56. # to_port = "3026"
  57. # protocol = "tcp"
  58. # cidr_blocks = [ "0.0.0.0/0" ]
  59. # security_group_id = aws_security_group.instance.id
  60. #}
  61. #resource "aws_security_group_rule" "instance-teleport-proxy-in" {
  62. # description = "Teleport - Proxy web server"
  63. # type = "ingress"
  64. # from_port = "3080"
  65. # to_port = "3080"
  66. # protocol = "tcp"
  67. # cidr_blocks = [ "0.0.0.0/0" ]
  68. # security_group_id = aws_security_group.instance.id
  69. #}
  70. #----------------------------------------------------------------------------
  71. # EGRESS
  72. #----------------------------------------------------------------------------
  73. resource "aws_security_group_rule" "instance-teleport-out-ssh" {
  74. type = "egress"
  75. description = "Outbound SSH"
  76. from_port = "22"
  77. to_port = "22"
  78. protocol = "tcp"
  79. cidr_blocks = ["0.0.0.0/0"] # tfsec:ignore:aws-vpc-no-public-egress-sgr
  80. security_group_id = aws_security_group.instance.id
  81. }
  82. resource "aws_security_group_rule" "instance-teleport-out-teleport" {
  83. type = "egress"
  84. description = "Outbound Teleport"
  85. from_port = "3022"
  86. to_port = "3026"
  87. protocol = "tcp"
  88. cidr_blocks = ["0.0.0.0/0"] # tfsec:ignore:aws-vpc-no-public-egress-sgr
  89. security_group_id = aws_security_group.instance.id
  90. }
  91. resource "aws_security_group_rule" "instance-teleport-out-https" {
  92. type = "egress"
  93. description = "HTTPS - Outbound, required for DynamoDB Streams (no vpc endpoint available)"
  94. from_port = "443"
  95. to_port = "443"
  96. protocol = "tcp"
  97. cidr_blocks = ["0.0.0.0/0"] # tfsec:ignore:aws-vpc-no-public-egress-sgr
  98. security_group_id = aws_security_group.instance.id
  99. }