policy-mdr_terraformer.tf 1.6 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. resources = [
  23. "arn:${local.aws_partition}:iam::${local.aws_account}:role/instance/*",
  24. "arn:${local.aws_partition}:iam::${local.aws_account}:role/lambda/*",
  25. "arn:${local.aws_partition}:iam::${local.aws_account}:role/aws_services/*",
  26. "arn:${local.aws_partition}:iam::${local.aws_account}:role/fargate/*",
  27. ]
  28. }
  29. statement {
  30. sid = "AssumeThisRoleInOtherAccounts"
  31. effect = "Allow"
  32. actions = [
  33. "sts:AssumeRole"
  34. ]
  35. resources = [
  36. "arn:${local.aws_partition}:iam::*:role/user/mdr_terraformer",
  37. # These two are the legacy roles in the older AWS accounts.
  38. # Adding them in the hope we'll be able to get AssumeRole from
  39. # one central place to everything...
  40. "arn:${local.aws_partition}:iam::*:role/mdr_powerusers",
  41. "arn:${local.aws_partition}:iam::*:role/mdr_iam_admins",
  42. ]
  43. }
  44. }
  45. resource "aws_iam_policy" "mdr_terraformer" {
  46. name = "mdr_terraformer"
  47. path = "/user/"
  48. policy = data.aws_iam_policy_document.mdr_terraformer.json
  49. }