securitygroup-server.tf 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # SG Summary - Server
  2. # Ingress:
  3. # 22 - sync from other security centers
  4. # 443 - User access
  5. # Egress:
  6. # 25 - smtp
  7. # 443 - updates
  8. # tcp/1243 - "Communicating with Log Correlation Engine" (unneeded in xdr)
  9. # tcp/8834-8835 - Communicating With Nessus - to vpc-managers
  10. resource "aws_security_group" "nessus_manager" {
  11. name_prefix = "nessus_manager"
  12. tags = merge(local.standard_tags, var.tags, { Name = "nessus_manager" })
  13. vpc_id = var.vpc_id
  14. description = "Nessus Security Scanner"
  15. }
  16. #-----------------------------------------------------------------
  17. # Ingress
  18. #-----------------------------------------------------------------
  19. resource "aws_security_group_rule" "nessus_manager_inbound_nessus" {
  20. security_group_id = aws_security_group.nessus_manager.id
  21. type = "ingress"
  22. description = "Inbound Nessus"
  23. cidr_blocks = ["10.0.0.0/8"]
  24. from_port = 8834
  25. to_port = 8834 # no 8835 according to https://docs.tenable.com/nessusagent/Content/RequirementsDataflow.htm
  26. protocol = "tcp"
  27. }
  28. resource "aws_security_group_rule" "http-in-external-c2-users" {
  29. # Wow. What was I thinking with c2_services_external_ips?
  30. # Regardless, it's not used often to address 'all' customers.
  31. #
  32. # This deserves some explanation. Terraform "for_each" expects to be
  33. # getting as input a map of values to iterate over as part of the foreach.
  34. # The keys of the map are used to name each of these objects created. Looking
  35. # in the terraform plan output of a for_each you'll see things like:
  36. #
  37. # aws_security_group_rule.resource_name["key-value-from-foreach"] will be created
  38. #
  39. # Our c2_services_external_ips is a list of maps, not a map of maps. The for-expression
  40. # makes a new thing that is a map of maps, where the key value is the description with
  41. # blanks removed.
  42. #
  43. # We could have made the variable more natively-friendly to for_each but this seemed
  44. # like a better solution for what we were trying to accomplish.
  45. for_each = { for s in local.c2_services_external_ips : replace(s.description, "/\\s*/", "") => s }
  46. description = "inbound nessus agent - ${each.value.description}"
  47. type = "ingress"
  48. from_port = 8834
  49. to_port = 8834
  50. protocol = "tcp"
  51. cidr_blocks = each.value.cidr_blocks # tfsec:ignore:aws-vpc-no-public-ingress-sgr Intentionally allow inbound
  52. security_group_id = aws_security_group.nessus_manager.id
  53. }
  54. #-----------------------------------------------------------------
  55. # Egress
  56. #-----------------------------------------------------------------
  57. #resource "aws_security_group_rule" "nessus_manager_outbound_all_ports" {
  58. # security_group_id = aws_security_group.nessus_manager.id
  59. # type = "egress"
  60. # cidr_blocks = [ "10.0.0.0/8" ]
  61. # from_port = -1
  62. # to_port = -1
  63. # protocol = "all"
  64. # description = "Outbound to All Ports"
  65. #}