audit_bucket.tf 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. resource "aws_s3_bucket" "audit_reports" {
  2. provider = aws.c2 # The reports go in the c2 bucket
  3. bucket = "xdr-ca-audit-reports"
  4. acl = "private"
  5. versioning {
  6. enabled = true
  7. }
  8. # TODO: Enable S3 logging... everywhere. We don't have a C2 bucket for this.
  9. #logging {
  10. # target_bucket = module.xdr_config_logging_bucket.s3_bucket_name
  11. # target_prefix = "${var.aws_account_id}-${var.aws_region}-awsconfig/"
  12. #}
  13. lifecycle_rule {
  14. id = "CleanUp"
  15. enabled = true
  16. abort_incomplete_multipart_upload_days = 7
  17. # Clean up old versions after a year
  18. noncurrent_version_expiration {
  19. days = 365
  20. }
  21. }
  22. server_side_encryption_configuration {
  23. rule {
  24. apply_server_side_encryption_by_default {
  25. sse_algorithm = "AES256" # Default keys are fine. We don't really need encryption here.
  26. }
  27. }
  28. }
  29. tags = merge(var.standard_tags, var.tags)
  30. }
  31. data "aws_iam_policy_document" "audit_reports_bucket_access" {
  32. statement {
  33. actions = [
  34. "s3:GetBucketAcl",
  35. "s3:GetBucketLocation",
  36. "s3:PutObject",
  37. "s3:PutObjectAcl",
  38. ]
  39. resources = [
  40. aws_s3_bucket.audit_reports.arn,
  41. "${aws_s3_bucket.audit_reports.arn}/*",
  42. ]
  43. principals {
  44. identifiers = ["acm-pca.amazonaws.com"]
  45. type = "Service"
  46. }
  47. # TODO: Consider restricting this to the accounts, but may need to add Get permissions?
  48. # "Condition":{
  49. # "StringEquals":{
  50. # "aws:SourceAccount":"account",
  51. # "aws:SourceArn":"arn:partition:acm-pca:region:account:certificate-authority/CA-ID"
  52. # }
  53. # }
  54. }
  55. }
  56. resource "aws_s3_bucket_policy" "audit_reports" {
  57. provider = aws.c2 # The reports go in the c2 bucket
  58. bucket = aws_s3_bucket.audit_reports.id
  59. policy = data.aws_iam_policy_document.audit_reports_bucket_access.json
  60. depends_on = [ aws_s3_bucket.audit_reports ]
  61. }
  62. resource "aws_s3_bucket_public_access_block" "audit_reports_bucket_block_public_access" {
  63. provider = aws.c2 # The reports go in the c2 bucket
  64. bucket = aws_s3_bucket.audit_reports.id
  65. block_public_acls = true
  66. block_public_policy = true
  67. ignore_public_acls = true
  68. restrict_public_buckets = true
  69. depends_on = [ aws_s3_bucket.audit_reports ]
  70. }