policy-mdr_terraformer.tf 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 = "AllowPassRoleForSpecificRoleTypes"
  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/instance/*",
  30. "arn:${local.aws_partition}:iam::${local.aws_account}:role/lambda/*",
  31. "arn:${local.aws_partition}:iam::${local.aws_account}:role/aws_services/*",
  32. "arn:${local.aws_partition}:iam::${local.aws_account}:role/fargate/*",
  33. ]
  34. }
  35. statement {
  36. sid = "AssumeThisRoleInOtherAccounts"
  37. effect = "Allow"
  38. actions = [
  39. "sts:AssumeRole"
  40. ]
  41. # tfsec:ignore:aws-iam-no-policy-wildcards - baseline this setting first. Lockdown after baselining IAM permissions
  42. resources = [
  43. "arn:${local.aws_partition}:iam::*:role/user/mdr_terraformer",
  44. # These two are the legacy roles in the older AWS accounts.
  45. # Adding them in the hope we'll be able to get AssumeRole from
  46. # one central place to everything...
  47. "arn:${local.aws_partition}:iam::*:role/mdr_powerusers",
  48. "arn:${local.aws_partition}:iam::*:role/mdr_iam_admins",
  49. ]
  50. }
  51. }
  52. resource "aws_iam_policy" "mdr_terraformer" {
  53. name = "mdr_terraformer"
  54. path = "/user/"
  55. policy = data.aws_iam_policy_document.mdr_terraformer.json
  56. }