policy-mdradmin_tfstate_setup.tf 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. resource "aws_iam_policy" "mdradmin_tfstate_setup" {
  2. name = "mdradmmin_tfstate_setup"
  3. path = "/bootstrap/"
  4. description = "Gives MDRAdmin account rights needed to set up tfstate management"
  5. policy = data.aws_iam_policy_document.mdradmin_tfstate_setup.json
  6. }
  7. data "aws_iam_policy_document" "mdradmin_tfstate_setup" {
  8. # checkov:skip=CKV_AWS_111: see tfsec aws-iam-no-policy-wildcard ignore comment
  9. # tfsec:ignore:aws-iam-no-policy-wildcards - baseline this setting first. We use wildcards in policies
  10. statement {
  11. sid = "DynamoDBTablesAndLocking"
  12. actions = [
  13. "dynamodb:*"
  14. ]
  15. resources = [
  16. "arn:${local.aws_partition}:dynamodb:${local.aws_region}:${local.aws_account}:table/${var.lock_table_name}"
  17. ]
  18. condition {
  19. test = "BoolIfExists"
  20. variable = "aws:MultiFactorAuthPresent"
  21. values = [
  22. true
  23. ]
  24. }
  25. }
  26. # tfsec:ignore:aws-iam-no-policy-wildcards - baseline this setting first. We use wildcards in policies
  27. statement {
  28. sid = "DynamoDBTablesAndLocking2"
  29. actions = [
  30. "dynamodb:ListTables"
  31. ]
  32. resources = [
  33. "arn:${local.aws_partition}:dynamodb:${local.aws_region}:${local.aws_account}:table/*"
  34. ]
  35. condition {
  36. test = "BoolIfExists"
  37. variable = "aws:MultiFactorAuthPresent"
  38. values = [
  39. true
  40. ]
  41. }
  42. }
  43. # tfsec:ignore:aws-iam-no-policy-wildcards - baseline this setting first. We use wildcards in policies
  44. statement {
  45. sid = "KMSKeyCreate"
  46. actions = [
  47. "kms:CreateAlias",
  48. "kms:CreateKey",
  49. "kms:List*",
  50. "kms:DeleteAlias",
  51. "kms:DeleteKey"
  52. ]
  53. # I wish I could scope this down to just specific keys
  54. # But I don't think it's possible
  55. resources = [
  56. "*"
  57. ]
  58. condition {
  59. test = "BoolIfExists"
  60. variable = "aws:MultiFactorAuthPresent"
  61. values = [
  62. true
  63. ]
  64. }
  65. }
  66. # tfsec:ignore:aws-iam-no-policy-wildcards - baseline this setting first. We use wildcards in policies
  67. statement {
  68. sid = "S3ManageStateBucket"
  69. actions = [
  70. "s3:CreateBucket",
  71. "s3:DeleteBucket",
  72. "s3:ListBucket",
  73. "s3:Get*",
  74. "s3:Put*"
  75. ]
  76. resources = [
  77. "arn:${local.aws_partition}:s3:::${var.bucket_name}"
  78. ]
  79. condition {
  80. test = "BoolIfExists"
  81. variable = "aws:MultiFactorAuthPresent"
  82. values = [
  83. true
  84. ]
  85. }
  86. }
  87. # tfsec:ignore:aws-iam-no-policy-wildcards - baseline this setting first. We use wildcards in policies
  88. statement {
  89. sid = "S3ObjectOperations"
  90. actions = [
  91. "s3:PutObject*",
  92. "s3:GetObject*",
  93. "s3:DeleteObject*"
  94. ]
  95. resources = [
  96. "arn:${local.aws_partition}:s3:::${var.bucket_name}/*"
  97. ]
  98. condition {
  99. test = "BoolIfExists"
  100. variable = "aws:MultiFactorAuthPresent"
  101. values = [
  102. true
  103. ]
  104. }
  105. }
  106. }