kms.tf 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. locals {
  2. kms_users = [aws_iam_role.splunk_apps_s3_role.arn]
  3. }
  4. resource "aws_kms_key" "bucketkey" {
  5. description = "S3 KMS for ${local.bucket_name}."
  6. deletion_window_in_days = 30
  7. enable_key_rotation = true
  8. policy = data.aws_iam_policy_document.kms_key_policy.json
  9. tags = merge(local.standard_tags, var.tags)
  10. }
  11. resource "aws_kms_alias" "bucketkey" {
  12. name = "alias/SplunkApps"
  13. target_key_id = aws_kms_key.bucketkey.key_id
  14. }
  15. data "aws_iam_policy_document" "kms_key_policy" {
  16. policy_id = local.bucket_name
  17. statement {
  18. sid = "Enable IAM User Permissions"
  19. effect = "Allow"
  20. principals {
  21. type = "AWS"
  22. identifiers = [
  23. "arn:${var.aws_partition}:iam::${var.aws_account_id}:root",
  24. "arn:${var.aws_partition}:iam::${var.aws_account_id}:user/MDRAdmin",
  25. ]
  26. }
  27. actions = ["kms:*"]
  28. resources = ["*"]
  29. }
  30. statement {
  31. sid = "Allow access for Engineers"
  32. effect = "Allow"
  33. principals {
  34. type = "AWS"
  35. identifiers = [
  36. "arn:${var.aws_partition}:iam::${var.aws_account_id}:user/MDRAdmin",
  37. "arn:${var.aws_partition}:iam::${var.aws_account_id}:role/user/mdr_terraformer",
  38. ]
  39. }
  40. actions = [
  41. "kms:Create*",
  42. "kms:Describe*",
  43. "kms:Enable*",
  44. "kms:List*",
  45. "kms:Put*",
  46. "kms:Update*",
  47. "kms:Revoke*",
  48. "kms:Disable*",
  49. "kms:Get*",
  50. "kms:Delete*",
  51. "kms:TagResource",
  52. "kms:UntagResource",
  53. "kms:ScheduleKeyDeletion",
  54. "kms:CancelKeyDeletion"
  55. ]
  56. resources = ["*"]
  57. }
  58. statement {
  59. sid = "Allow use of the key to encrypt and decrypt"
  60. effect = "Allow"
  61. principals {
  62. type = "AWS"
  63. identifiers = local.kms_users
  64. }
  65. actions = [
  66. "kms:Encrypt",
  67. "kms:Decrypt",
  68. "kms:ReEncrypt*",
  69. "kms:GenerateDataKey*",
  70. "kms:DescribeKey"
  71. ]
  72. resources = ["*"]
  73. }
  74. statement {
  75. sid = "Allow attachment of persistent resources"
  76. effect = "Allow"
  77. principals {
  78. type = "AWS"
  79. identifiers = [
  80. "arn:${var.aws_partition}:iam::${var.aws_account_id}:user/MDRAdmin",
  81. "arn:${var.aws_partition}:iam::${var.aws_account_id}:role/user/mdr_terraformer",
  82. ]
  83. }
  84. actions = [
  85. "kms:CreateGrant",
  86. "kms:ListGrants",
  87. "kms:RevokeGrant"
  88. ]
  89. resources = ["*"]
  90. condition {
  91. test = "Bool"
  92. variable = "kms:GrantIsForAWSResource"
  93. values = ["true"]
  94. }
  95. }
  96. }