policy-mdr_terraformer.tf 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. # checkov:skip=CKV_AWS_107: IAM policies does not allow credentials exposure for ECR
  6. # checkov:skip=CKV_AWS_108: no data exfiltration allowed; resource constraints implemented
  7. # checkov:skip=CKV_AWS_109: see tfsec aws-iam-no-policy-wildcard ignore comment
  8. # checkov:skip=CKV_AWS_110: IAM policies does not allow privilege escalation
  9. # checkov:skip=CKV_AWS_111: see tfsec aws-iam-no-policy-wildcard ignore comment
  10. statement {
  11. sid = "AllowEverythingButAssumeRoleAndPassRole"
  12. effect = "Allow"
  13. not_actions = [
  14. "sts:AssumeRole",
  15. "iam:PassRole",
  16. ]
  17. resources = [
  18. "*"
  19. ]
  20. }
  21. statement {
  22. sid = "AllowPassRole"
  23. effect = "Allow"
  24. actions = [
  25. "iam:PassRole",
  26. ]
  27. # tfsec:ignore:aws-iam-no-policy-wildcards - baseline this setting first. Lockdown after baselining IAM permissions
  28. resources = [
  29. "arn:${local.aws_partition}:iam::${local.aws_account}:role/*"
  30. ]
  31. }
  32. statement {
  33. sid = "AssumeThisRoleInOtherAccounts"
  34. effect = "Allow"
  35. actions = [
  36. "sts:AssumeRole"
  37. ]
  38. # tfsec:ignore:aws-iam-no-policy-wildcards - baseline this setting first. Lockdown after baselining IAM permissions
  39. resources = [
  40. "arn:${local.aws_partition}:iam::*:role/user/mdr_terraformer",
  41. # These two are the legacy roles in the older AWS accounts.
  42. # Adding them in the hope we'll be able to get AssumeRole from
  43. # one central place to everything...
  44. "arn:${local.aws_partition}:iam::*:role/mdr_powerusers",
  45. "arn:${local.aws_partition}:iam::*:role/mdr_iam_admins",
  46. ]
  47. }
  48. }
  49. resource "aws_iam_policy" "mdr_terraformer" {
  50. name = "mdr_terraformer"
  51. path = "/user/"
  52. policy = data.aws_iam_policy_document.mdr_terraformer.json
  53. }