kms.tf 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // KMS key for S3
  2. resource "aws_kms_key" "s3" {
  3. description = "KMS key for Teleport"
  4. enable_key_rotation = true
  5. policy = data.aws_iam_policy_document.kms_key_encryption_policy.json
  6. }
  7. resource "aws_kms_alias" "s3" {
  8. name = "alias/teleport-${var.instance_name}"
  9. target_key_id = aws_kms_key.s3.key_id
  10. }
  11. data "aws_iam_policy_document" "kms_key_encryption_policy" {
  12. #policy_id = "key-consolepolicy-3"
  13. statement {
  14. sid = "Enable IAM User Permissions"
  15. effect = "Allow"
  16. principals {
  17. type = "AWS"
  18. identifiers = [
  19. "arn:${var.aws_partition}:iam::${var.aws_account_id}:role/user/mdr_terraformer",
  20. "arn:${var.aws_partition}:iam::${var.aws_account_id}:user/MDRAdmin"
  21. ]
  22. }
  23. actions = ["kms:*"]
  24. resources = ["*"]
  25. }
  26. statement {
  27. sid = "Allow access for Key Administrators"
  28. effect = "Allow"
  29. principals {
  30. type = "AWS"
  31. identifiers = [
  32. "arn:${var.aws_partition}:iam::${var.aws_account_id}:role/user/mdr_terraformer",
  33. ]
  34. }
  35. actions = [
  36. "kms:Create*",
  37. "kms:Describe*",
  38. "kms:Enable*",
  39. "kms:List*",
  40. "kms:Put*",
  41. "kms:Update*",
  42. "kms:Revoke*",
  43. "kms:Disable*",
  44. "kms:Get*",
  45. "kms:Delete*",
  46. "kms:TagResource",
  47. "kms:UntagResource",
  48. "kms:ScheduleKeyDeletion",
  49. "kms:CancelKeyDeletion"
  50. ]
  51. resources = ["*"]
  52. }
  53. statement {
  54. sid = "Allow use of the key"
  55. effect = "Allow"
  56. principals {
  57. type = "AWS"
  58. identifiers = [
  59. aws_iam_role.auth.arn
  60. ]
  61. }
  62. actions = [
  63. "kms:Encrypt",
  64. "kms:Decrypt",
  65. "kms:ReEncrypt*",
  66. "kms:GenerateDataKey*",
  67. "kms:DescribeKey"
  68. ]
  69. resources = ["*"]
  70. }
  71. statement {
  72. sid = "Allow access through Amazon S3 for all principals in the account that are authorized to use Amazon S3"
  73. effect = "Allow"
  74. principals {
  75. type = "AWS"
  76. identifiers = ["*"]
  77. }
  78. actions = [
  79. "kms:Encrypt",
  80. "kms:Decrypt",
  81. "kms:ReEncrypt*",
  82. "kms:GenerateDataKey*",
  83. "kms:DescribeKey"
  84. ]
  85. resources = ["*"]
  86. condition {
  87. test = "StringEquals"
  88. variable = "kms.ViaService"
  89. values = ["s3.${var.aws_region}.amazonaws.com", "dynamodb.${var.aws_region}.amazonaws.com"]
  90. }
  91. condition {
  92. test = "StringEquals"
  93. variable = "kms.CallerAccount"
  94. values = [var.aws_account_id]
  95. }
  96. }
  97. statement {
  98. sid = "Allow DynamoDB to get information about the CMK"
  99. effect = "Allow"
  100. principals {
  101. type = "Service"
  102. identifiers = ["dynamodb.amazonaws.com"]
  103. }
  104. actions = [
  105. "kms:Describe*",
  106. "kms:Get*",
  107. "kms:List*"
  108. ]
  109. resources = ["*"]
  110. }
  111. }