kms.tf 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. resource "aws_kms_key" "tfstate" {
  2. description = "tfstate bucket default S3 SSE-KMS"
  3. deletion_window_in_days = 30
  4. enable_key_rotation = true
  5. policy = data.aws_iam_policy_document.kms_key_policy_tfstate.json
  6. depends_on = [ var.module_depends_on ]
  7. }
  8. resource "aws_kms_alias" "tfstate" {
  9. name = "alias/tfstate"
  10. target_key_id = aws_kms_key.tfstate.key_id
  11. depends_on = [ var.module_depends_on ]
  12. }
  13. data "aws_iam_policy_document" "kms_key_policy_tfstate" {
  14. policy_id = "key-consolepolicy-3"
  15. statement {
  16. sid = "Enable IAM User Permissions"
  17. effect = "Allow"
  18. principals {
  19. type = "AWS"
  20. identifiers = ["arn:${local.aws_partition}:iam::${local.aws_account}:root"]
  21. }
  22. actions = ["kms:*"]
  23. resources = ["*"]
  24. }
  25. statement {
  26. sid = "Allow access for Key Administrators"
  27. effect = "Allow"
  28. principals {
  29. type = "AWS"
  30. identifiers = [
  31. # FIXME: I'm trying to decide if these should be hard-coded or
  32. # parameters, or some mix/match of each.
  33. "arn:${local.aws_partition}:iam::${local.aws_account}:user/MDRAdmin",
  34. #"arn:${local.aws_partition}:iam::${local.aws_account}:role/user/mdr_engineer",
  35. #"arn:${local.aws_partition}:iam::${local.aws_account}:role/user/mdr_iam_admin"
  36. ]
  37. }
  38. actions = [
  39. "kms:Create*",
  40. "kms:Describe*",
  41. "kms:Enable*",
  42. "kms:List*",
  43. "kms:Put*",
  44. "kms:Update*",
  45. "kms:Revoke*",
  46. "kms:Disable*",
  47. "kms:Get*",
  48. "kms:Delete*",
  49. "kms:TagResource",
  50. "kms:UntagResource",
  51. "kms:ScheduleKeyDeletion",
  52. "kms:CancelKeyDeletion"
  53. ]
  54. resources = ["*"]
  55. }
  56. statement {
  57. sid = "Allow use of the key"
  58. effect = "Allow"
  59. principals {
  60. type = "AWS"
  61. identifiers = [
  62. "arn:${local.aws_partition}:iam::${local.aws_account}:user/MDRAdmin",
  63. #"arn:${local.aws_partition}:iam::${local.aws_account}:role/user/mdr_engineer",
  64. #"arn:${local.aws_partition}:iam::${local.aws_account}:role/user/mdr_iam_admin"
  65. ]
  66. }
  67. actions = [
  68. "kms:Encrypt",
  69. "kms:Decrypt",
  70. "kms:ReEncrypt*",
  71. "kms:GenerateDataKey*",
  72. "kms:DescribeKey"
  73. ]
  74. resources = ["*"]
  75. }
  76. statement {
  77. sid = "Allow attachment of persistent resources"
  78. effect = "Allow"
  79. principals {
  80. type = "AWS"
  81. identifiers = [
  82. "arn:${local.aws_partition}:iam::${local.aws_account}:user/MDRAdmin",
  83. #"arn:${local.aws_partition}:iam::${local.aws_account}:role/user/mdr_engineer",
  84. #"arn:${local.aws_partition}:iam::${local.aws_account}:role/user/mdr_iam_admin"
  85. ]
  86. }
  87. actions = [
  88. "kms:CreateGrant",
  89. "kms:ListGrants",
  90. "kms:RevokeGrant"
  91. ]
  92. resources = ["*"]
  93. condition {
  94. test = "Bool"
  95. variable = "kms:GrantIsForAWSResource"
  96. values = ["true"]
  97. }
  98. }
  99. }