security-groups.tf 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. resource "aws_security_group" "openvpn_security_group" {
  2. name_prefix = "${ var.instance_name }_security_group"
  3. description = "Security Group for OpenVPN Instance(s)"
  4. vpc_id = var.vpc_id
  5. tags = merge(var.standard_tags, var.tags)
  6. }
  7. resource "aws_security_group_rule" "openvpn-in" {
  8. type = "ingress"
  9. from_port = 1194
  10. to_port = 1194
  11. protocol = "udp"
  12. # NOTE: For NLBs, the source IP is the public IP, so the security group must allow public access.
  13. cidr_blocks = [ "0.0.0.0/0" ]
  14. security_group_id = aws_security_group.openvpn_security_group.id
  15. }
  16. resource "aws_security_group_rule" "openvpn-https-in" {
  17. type = "ingress"
  18. from_port = 443
  19. to_port = 443
  20. protocol = "tcp"
  21. # NOTE: For NLBs, the source IP is the public IP, so the security group must allow public access.
  22. cidr_blocks = [ "0.0.0.0/0" ]
  23. security_group_id = aws_security_group.openvpn_security_group.id
  24. }
  25. resource "aws_security_group_rule" "openvpn-permissive-out" {
  26. # We allow all outbound for openvpn
  27. type = "egress"
  28. from_port = -1
  29. to_port = -1
  30. protocol = "all"
  31. cidr_blocks = [ "10.0.0.0/8" ]
  32. security_group_id = aws_security_group.openvpn_security_group.id
  33. }
  34. # We have specific egress rules, as well, but the list may be incomplete.
  35. resource "aws_security_group_rule" "openvpn-splunk-out" {
  36. type = "egress"
  37. from_port = 8000
  38. to_port = 8000
  39. protocol = "tcp"
  40. cidr_blocks = [ "10.0.0.0/8" ]
  41. security_group_id = aws_security_group.openvpn_security_group.id
  42. }
  43. resource "aws_security_group_rule" "openvpn-https-out" {
  44. type = "egress"
  45. from_port = 443
  46. to_port = 443
  47. protocol = "tcp"
  48. cidr_blocks = [ "10.0.0.0/8" ]
  49. security_group_id = aws_security_group.openvpn_security_group.id
  50. }
  51. resource "aws_security_group_rule" "openvpn-https-alt-out" {
  52. type = "egress"
  53. from_port = 8443
  54. to_port = 8443
  55. protocol = "tcp"
  56. cidr_blocks = [ "10.0.0.0/8" ]
  57. security_group_id = aws_security_group.openvpn_security_group.id
  58. }
  59. resource "aws_security_group_rule" "openvpn-phantom-out" {
  60. type = "egress"
  61. from_port = 8888
  62. to_port = 8888
  63. protocol = "tcp"
  64. cidr_blocks = [ "10.0.0.0/8" ]
  65. security_group_id = aws_security_group.openvpn_security_group.id
  66. }
  67. resource "aws_security_group_rule" "openvpn-github-ssh-out" {
  68. type = "egress"
  69. from_port = 122
  70. to_port = 122
  71. protocol = "tcp"
  72. cidr_blocks = [ "10.0.0.0/8" ]
  73. security_group_id = aws_security_group.openvpn_security_group.id
  74. }
  75. resource "aws_security_group_rule" "openvpn-ssh-out" {
  76. type = "egress"
  77. from_port = 22
  78. to_port = 22
  79. protocol = "tcp"
  80. cidr_blocks = [ "10.0.0.0/8" ]
  81. security_group_id = aws_security_group.openvpn_security_group.id
  82. }
  83. resource "aws_security_group_rule" "openvpn-nessus-out" {
  84. type = "egress"
  85. from_port = 8834
  86. to_port = 8835
  87. protocol = "tcp"
  88. cidr_blocks = toset(concat(var.cidr_map["vpc-scanners"], var.cidr_map["vpc-private-services"]))
  89. security_group_id = aws_security_group.openvpn_security_group.id
  90. description = "Access to Nessus"
  91. }
  92. resource "aws_security_group_rule" "openvpn-license-server-out" {
  93. # Needed for license server check-in. Seems to be stable IP.
  94. type = "egress"
  95. from_port = 443
  96. to_port = 443
  97. protocol = "tcp"
  98. cidr_blocks = [ "54.183.149.72/32" ]
  99. security_group_id = aws_security_group.openvpn_security_group.id
  100. }
  101. resource "aws_security_group_rule" "openvpn-ldap-out" {
  102. type = "egress"
  103. from_port = 636
  104. to_port = 636
  105. protocol = "tcp"
  106. # Yes this has to be 0.0.0.0/0 because our SSL ldap server is provided by OKTA behind a NLB in AWS with non static IP
  107. cidr_blocks = [ "0.0.0.0/0" ]
  108. security_group_id = aws_security_group.openvpn_security_group.id
  109. }