policy-mdr_engineer.tf 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #------------------------------------------------------------------------------------------
  2. # A variant on PowerUserAccess that isn't so damn generous with sts:assumeRole
  3. #------------------------------------------------------------------------------------------
  4. data "aws_iam_policy_document" "mdr_engineer" {
  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. effect = "Allow"
  12. not_actions = [
  13. "sts:*",
  14. "iam:*",
  15. "organizations:*",
  16. ]
  17. resources = [
  18. "*",
  19. ]
  20. }
  21. statement {
  22. effect = "Allow"
  23. actions = [
  24. "iam:CreateServiceLinkedRole",
  25. "iam:DeleteServiceLinkedRole",
  26. "iam:ListRoles",
  27. "iam:ListRolePolicies",
  28. "iam:ListInstanceProfiles",
  29. "iam:ListPolicies",
  30. "iam:GetRole",
  31. "iam:GetRolePolicy",
  32. "iam:GetInstanceProfile",
  33. "iam:GetPolicy",
  34. "iam:GetPolicyVersion",
  35. "iam:ListAttachedRolePolicies",
  36. "organizations:DescribeOrganization",
  37. ]
  38. # tfsec:ignore:aws-iam-no-policy-wildcards - baseline this setting first. We use wildcards in policies
  39. resources = [
  40. "*",
  41. ]
  42. }
  43. statement {
  44. effect = "Allow"
  45. actions = [
  46. "iam:PassRole",
  47. ]
  48. # tfsec:ignore:aws-iam-no-policy-wildcards - baseline this setting first. We use wildcards in policies
  49. resources = [
  50. "arn:${local.aws_partition}:iam::${local.aws_account}:role/instance/*",
  51. "arn:${local.aws_partition}:iam::${local.aws_account}:role/lambda/*",
  52. "arn:${local.aws_partition}:iam::${local.aws_account}:role/aws_services/*",
  53. "arn:${local.aws_partition}:iam::${local.aws_account}:role/fargate/*",
  54. ]
  55. }
  56. statement {
  57. sid = "AssumeThisRoleInOtherAccounts"
  58. effect = "Allow"
  59. actions = [
  60. "sts:AssumeRole"
  61. ]
  62. # tfsec:ignore:aws-iam-no-policy-wildcards - baseline this setting first. We use wildcards in policies
  63. resources = [
  64. "arn:${local.aws_partition}:iam::*:role/user/mdr_engineer",
  65. "arn:${local.aws_partition}:iam::*:role/mdr_engineer",
  66. ]
  67. }
  68. }
  69. resource "aws_iam_policy" "mdr_engineer" {
  70. name = "mdr_engineer"
  71. path = "/user/"
  72. policy = data.aws_iam_policy_document.mdr_engineer.json
  73. }