config.tf 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # Approve the aggregator in C2
  2. resource "aws_config_aggregate_authorization" "authorization" {
  3. account_id = local.c2_account
  4. region = var.aws_region
  5. tags = merge(local.standard_tags, var.tags)
  6. }
  7. output "authorizations" {
  8. value = aws_config_aggregate_authorization.authorization
  9. }
  10. ########### IAM Role for AWS Config
  11. data "aws_iam_policy_document" "awsconfig" {
  12. statement {
  13. sid = "PutConfigS3BucketObjects"
  14. effect = "Allow"
  15. actions = ["s3:PutObject"]
  16. resources = [
  17. # tfsec:ignore:aws-iam-no-policy-wildcards Allows use by the entire account
  18. "arn:${var.aws_partition}:s3:::xdr-config-${local.logging_environment}/*",
  19. ]
  20. condition {
  21. test = "StringEquals"
  22. variable = "s3:x-amz-acl"
  23. values = ["bucket-owner-full-control"]
  24. }
  25. }
  26. statement {
  27. sid = "GetConfigS3BucketACL"
  28. effect = "Allow"
  29. actions = ["s3:GetBucketAcl"]
  30. resources = [
  31. # tfsec:ignore:aws-iam-no-policy-wildcards Allows use by the entire account
  32. "arn:${var.aws_partition}:s3:::xdr-config-${local.logging_environment}/*",
  33. ]
  34. }
  35. statement {
  36. sid = "PublishAlertsToSNS"
  37. effect = "Allow"
  38. actions = ["sns:Publish"]
  39. resources = ["arn:${var.aws_partition}:sns:${var.aws_region}:${local.c2_account}:config-notifications"]
  40. }
  41. statement {
  42. sid = "PermissionsForRuleChecks"
  43. effect = "Allow"
  44. actions = [
  45. "kms:DescribeKey"
  46. ]
  47. # tfsec:ignore:aws-iam-no-policy-wildcards Allows use by the entire account
  48. resources = ["*"]
  49. }
  50. }
  51. resource "aws_iam_policy" "awsconfig" {
  52. name_prefix = "awsconfig-"
  53. policy = data.aws_iam_policy_document.awsconfig.json
  54. }
  55. data "aws_iam_policy_document" "assume" {
  56. statement {
  57. effect = "Allow"
  58. actions = ["sts:AssumeRole"]
  59. principals {
  60. type = "Service"
  61. identifiers = ["config.amazonaws.com"]
  62. }
  63. }
  64. }
  65. resource "aws_iam_role" "awsconfig" {
  66. name_prefix = "aws-config-role"
  67. path = "/aws_services/"
  68. assume_role_policy = data.aws_iam_policy_document.assume.json
  69. }
  70. resource "aws_iam_role_policy_attachment" "awsconfig_managed_policy" {
  71. role = aws_iam_role.awsconfig.name
  72. policy_arn = "arn:${var.aws_partition}:iam::aws:policy/service-role/AWS_ConfigRole"
  73. }
  74. resource "aws_iam_role_policy_attachment" "awsconfig_local_policy" {
  75. role = aws_iam_role.awsconfig.name
  76. policy_arn = aws_iam_policy.awsconfig.arn
  77. }
  78. ################ Config Recorder
  79. resource "aws_config_configuration_recorder" "awsconfig_recorder" {
  80. name = "xdr-config-recorder"
  81. role_arn = aws_iam_role.awsconfig.arn
  82. recording_group {
  83. all_supported = true
  84. include_global_resource_types = true
  85. }
  86. }
  87. resource "aws_config_delivery_channel" "awsconfig_delivery_channel" {
  88. name = "xdr-config-delivery-channel"
  89. s3_bucket_name = "xdr-config-${local.logging_environment}"
  90. sns_topic_arn = "arn:${var.aws_partition}:sns:${var.aws_region}:${local.c2_account}:config-notifications"
  91. snapshot_delivery_properties {
  92. delivery_frequency = "One_Hour"
  93. }
  94. depends_on = [aws_config_configuration_recorder.awsconfig_recorder]
  95. }
  96. resource "aws_config_configuration_recorder_status" "awsconfig_recorder_status" {
  97. name = "xdr-config-recorder"
  98. is_enabled = true
  99. depends_on = [aws_config_delivery_channel.awsconfig_delivery_channel]
  100. }