policy-mdr_terraformer.tf 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 = "AllowPassRoleForLegacyAccountRoles"
  37. effect = "Allow"
  38. actions = [
  39. "iam:PassRole",
  40. ]
  41. resources = [
  42. "arn:${local.aws_partition}:iam::${local.aws_account}:role/vault-instance-role",
  43. "arn:${local.aws_partition}:iam::${local.aws_account}:role/splunk-aws-instance-role",
  44. "arn:${local.aws_partition}:iam::${local.aws_account}:role/salt-master-instance-role",
  45. "arn:${local.aws_partition}:iam::${local.aws_account}:role/portal-instance-role",
  46. "arn:${local.aws_partition}:iam::${local.aws_account}:role/portal-data-sync-lambda-role",
  47. "arn:${local.aws_partition}:iam::${local.aws_account}:role/msoc-default-instance-role",
  48. "arn:${local.aws_partition}:iam::${local.aws_account}:role/ecsFargateTaskExecutionRole",
  49. "arn:${local.aws_partition}:iam::${local.aws_account}:role/dlm-lifecycle-role",
  50. "arn:${local.aws_partition}:iam::${local.aws_account}:role/codebuild_role",
  51. ]
  52. }
  53. statement {
  54. sid = "AssumeThisRoleInOtherAccounts"
  55. effect = "Allow"
  56. actions = [
  57. "sts:AssumeRole"
  58. ]
  59. # tfsec:ignore:aws-iam-no-policy-wildcards - baseline this setting first. Lockdown after baselining IAM permissions
  60. resources = [
  61. "arn:${local.aws_partition}:iam::*:role/user/mdr_terraformer",
  62. # These two are the legacy roles in the older AWS accounts.
  63. # Adding them in the hope we'll be able to get AssumeRole from
  64. # one central place to everything...
  65. "arn:${local.aws_partition}:iam::*:role/mdr_powerusers",
  66. "arn:${local.aws_partition}:iam::*:role/mdr_iam_admins",
  67. ]
  68. }
  69. }
  70. resource "aws_iam_policy" "mdr_terraformer" {
  71. name = "mdr_terraformer"
  72. path = "/user/"
  73. policy = data.aws_iam_policy_document.mdr_terraformer.json
  74. }