iam.tf 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # The moose splunk SH has additional permissions beyond the default instance
  2. resource "aws_iam_instance_profile" "moose_splunk_sh_instance_profile" {
  3. count = local.is_moose ? 1 : 0
  4. name = "moose-splunk-sh-instance-profile"
  5. path = "/instance/"
  6. role = aws_iam_role.moose_splunk_sh_instance_role[count.index].name
  7. }
  8. resource "aws_iam_role" "moose_splunk_sh_instance_role" {
  9. count = local.is_moose ? 1 : 0
  10. name = "moose-splunk-sh-instance-role"
  11. path = "/instance/"
  12. assume_role_policy = jsonencode(
  13. {
  14. "Version": "2012-10-17",
  15. "Statement": [
  16. {
  17. "Sid": "",
  18. "Effect": "Allow",
  19. "Principal": {
  20. "Service": [
  21. "ec2.amazonaws.com"
  22. ]
  23. },
  24. "Action": "sts:AssumeRole"
  25. }
  26. ]
  27. })
  28. }
  29. data "aws_iam_policy_document" "moose_splunk_sh_policy_doc" {
  30. count = local.is_moose ? 1 : 0
  31. # Moose splunk SH can assumerole into the C2 and mdr-prod-root-ca accounts to run the ACM audit report
  32. statement {
  33. sid = "AllowAssumeRole"
  34. effect = "Allow"
  35. actions = [
  36. "sts:AssumeRole"
  37. ]
  38. resources = [
  39. "arn:${var.aws_partition}:iam::*:role/service/run_audit_report_role"
  40. ]
  41. }
  42. # Moose splunk SH can grab the ACM audit reports
  43. statement {
  44. sid = ""
  45. effect = "Allow"
  46. resources = ["arn:${var.aws_partition}:s3:::xdr-ca-audit-reports"]
  47. actions = [
  48. "s3:ListBucket",
  49. "s3:ListBucketVersions",
  50. ]
  51. }
  52. statement {
  53. sid = ""
  54. effect = "Allow"
  55. resources = ["arn:${var.aws_partition}:s3:::xdr-ca-audit-reports/*"]
  56. actions = [
  57. "s3:GetObject",
  58. "s3:GetObjectVersion",
  59. ]
  60. }
  61. }
  62. resource "aws_iam_policy" "moose_splunk_sh_policy" {
  63. count = local.is_moose ? 1 : 0
  64. name = "moose_splunk_sh"
  65. path = "/"
  66. policy = data.aws_iam_policy_document.moose_splunk_sh_policy_doc[count.index].json
  67. }
  68. resource "aws_iam_role_policy_attachment" "moose_splunk_sh_attach" {
  69. count = local.is_moose ? 1 : 0
  70. role = aws_iam_role.moose_splunk_sh_instance_role[count.index].name
  71. policy_arn = aws_iam_policy.moose_splunk_sh_policy[count.index].arn
  72. }
  73. resource "aws_iam_role_policy_attachment" "moose_splunk_sh_AmazonEC2RoleforSSM" {
  74. count = local.is_moose ? 1 : 0
  75. role = aws_iam_role.moose_splunk_sh_instance_role[count.index].name
  76. policy_arn = "arn:${var.aws_partition}:iam::aws:policy/service-role/AmazonEC2RoleforSSM"
  77. }
  78. resource "aws_iam_role_policy_attachment" "moose_splunk_sh_policy_attach_tag_read" {
  79. count = local.is_moose ? 1 : 0
  80. role = aws_iam_role.moose_splunk_sh_instance_role[count.index].name
  81. policy_arn = "arn:${var.aws_partition}:iam::${var.aws_account_id}:policy/launchroles/default_instance_tag_read"
  82. }
  83. resource "aws_iam_role_policy_attachment" "moose_splunk_sh_policy_attach_cloudwatch" {
  84. count = local.is_moose ? 1 : 0
  85. role = aws_iam_role.moose_splunk_sh_instance_role[count.index].name
  86. policy_arn = "arn:${var.aws_partition}:iam::${var.aws_account_id}:policy/cloudwatch_events"
  87. }
  88. #This policy needs to be create prior to creating the Salt Master
  89. resource "aws_iam_role_policy_attachment" "moose_splunk_sh_policy_attach_binaries" {
  90. count = local.is_moose ? 1 : 0
  91. role = aws_iam_role.moose_splunk_sh_instance_role[count.index].name
  92. policy_arn = "arn:${var.aws_partition}:iam::${var.aws_account_id}:policy/launchroles/default_instance_s3_binaries"
  93. }