policy-mdr_terraformer.tf 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #------------------------------------------------------------------------------------------
  2. # A variant on PowerUserAccess that isn't so damn generous with sts:assumeRole
  3. #------------------------------------------------------------------------------------------
  4. data "aws_iam_policy_document" "mdr_terraformer" {
  5. statement {
  6. sid = "AllowEverythingButAssumeRoleAndPassRole"
  7. effect = "Allow"
  8. not_actions = [
  9. "sts:AssumeRole",
  10. "iam:PassRole",
  11. ]
  12. resources = [
  13. "*"
  14. ]
  15. }
  16. statement {
  17. sid = "AllowPassRoleForSpecificRoleTypes"
  18. effect = "Allow"
  19. actions = [
  20. "iam:PassRole",
  21. ]
  22. # tfsec:ignore:aws-iam-no-policy-wildcards - baseline this setting first. Lockdown after baselining IAM permissions
  23. resources = [
  24. "arn:${local.aws_partition}:iam::${local.aws_account}:role/instance/*",
  25. "arn:${local.aws_partition}:iam::${local.aws_account}:role/lambda/*",
  26. "arn:${local.aws_partition}:iam::${local.aws_account}:role/aws_services/*",
  27. "arn:${local.aws_partition}:iam::${local.aws_account}:role/fargate/*",
  28. ]
  29. }
  30. statement {
  31. sid = "AssumeThisRoleInOtherAccounts"
  32. effect = "Allow"
  33. actions = [
  34. "sts:AssumeRole"
  35. ]
  36. # tfsec:ignore:aws-iam-no-policy-wildcards - baseline this setting first. Lockdown after baselining IAM permissions
  37. resources = [
  38. "arn:${local.aws_partition}:iam::*:role/user/mdr_terraformer",
  39. # These two are the legacy roles in the older AWS accounts.
  40. # Adding them in the hope we'll be able to get AssumeRole from
  41. # one central place to everything...
  42. "arn:${local.aws_partition}:iam::*:role/mdr_powerusers",
  43. "arn:${local.aws_partition}:iam::*:role/mdr_iam_admins",
  44. ]
  45. }
  46. }
  47. resource "aws_iam_policy" "mdr_terraformer" {
  48. name = "mdr_terraformer"
  49. path = "/user/"
  50. policy = data.aws_iam_policy_document.mdr_terraformer.json
  51. }