instance_profile.tf 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. resource "aws_iam_instance_profile" "phantom_instance_profile" {
  2. name = "xdr-phantom-instance-profile"
  3. path = "/instance/"
  4. role = aws_iam_role.phantom_instance_role.name
  5. }
  6. resource "aws_iam_role" "phantom_instance_role" {
  7. name = "xdr-phantom-instance-role"
  8. path = "/instance/"
  9. assume_role_policy = <<EOF
  10. {
  11. "Version": "2012-10-17",
  12. "Statement": [
  13. {
  14. "Sid": "",
  15. "Effect": "Allow",
  16. "Principal": {
  17. "Service": [
  18. "ec2.amazonaws.com",
  19. "ssm.amazonaws.com"
  20. ]
  21. },
  22. "Action": "sts:AssumeRole"
  23. }
  24. ]
  25. }
  26. EOF
  27. }
  28. # These 3 are the default profile attachments:
  29. resource "aws_iam_role_policy_attachment" "phantom_instance_AmazonEC2RoleforSSM" {
  30. role = aws_iam_role.phantom_instance_role.name
  31. policy_arn = "arn:${var.aws_partition}:iam::aws:policy/service-role/AmazonEC2RoleforSSM"
  32. }
  33. resource "aws_iam_role_policy_attachment" "phantom_instance_default_policy_attach" {
  34. role = aws_iam_role.phantom_instance_role.name
  35. policy_arn = "arn:${ var.aws_partition }:iam::${ var.aws_account_id }:policy/launchroles/default_instance_tag_read"
  36. }
  37. resource "aws_iam_role_policy_attachment" "phantom_instance_cloudwatch_policy_attach" {
  38. role = aws_iam_role.phantom_instance_role.name
  39. policy_arn = "arn:${ var.aws_partition }:iam::${ var.aws_account_id }:policy/cloudwatch_events"
  40. }
  41. # Phantom Specific Policy
  42. #resource "aws_iam_policy" "phantom_instance_policy" {
  43. # name = "phantom_instance_policy"
  44. # path = "/launchroles/"
  45. # description = "This policy allows phantom-specific functions"
  46. # policy = data.aws_iam_policy_document.phantom_instance_policy_doc.json
  47. #}
  48. #
  49. #data "aws_iam_policy_document" "phantom_instance_policy_doc" {
  50. # # Allow copying to S3 for frozen
  51. # # Allow use of S3 for SmartStore
  52. # statement {
  53. # sid = "GeneralBucketAccess"
  54. # effect = "Allow"
  55. # actions = [
  56. # "s3:ListAllMyBuckets",
  57. # "s3:HeadBucket",
  58. # ]
  59. # resources = [ "*" ]
  60. # }
  61. #
  62. # statement {
  63. # sid = "S3BucketAccess"
  64. # effect = "Allow"
  65. # actions = [
  66. # "s3:GetLifecycleConfiguration",
  67. # "s3:DeleteObjectVersion",
  68. # "s3:ListBucketVersions",
  69. # "s3:GetBucketLogging",
  70. # "s3:RestoreObject",
  71. # "s3:ListBuckets",
  72. # "s3:GetBucketVersioning",
  73. # "s3:PutObject",
  74. # "s3:GetObject",
  75. # "s3:PutLifecycleConfiguration",
  76. # "s3:GetBucketCORS",
  77. # "s3:DeleteObject",
  78. # "s3:GetBucketLocation",
  79. # "s3:GetObjectVersion",
  80. # ]
  81. # resources = [
  82. # "arn:${ var.aws_partition }:s3:::xdr-${ var.prefix }-${ var.environment }-splunk-frozen",
  83. # "arn:${ var.aws_partition }:s3:::xdr-${ var.prefix }-${ var.environment }-splunk-frozen/*",
  84. # "arn:${ var.aws_partition }:s3:::xdr-${ var.prefix }-${ var.environment }-splunk-smartstore",
  85. # "arn:${ var.aws_partition }:s3:::xdr-${ var.prefix }-${ var.environment }-splunk-smartstore/*",
  86. # ]
  87. # }
  88. #
  89. # statement {
  90. # sid = "S3ReadOnlyBucketAccess"
  91. # effect = "Allow"
  92. # actions = [
  93. # "s3:ListBucketVersions",
  94. # "s3:ListBuckets",
  95. # "s3:GetBucketVersioning",
  96. # "s3:GetObject",
  97. # "s3:GetBucketCORS",
  98. # "s3:GetBucketLocation",
  99. # "s3:GetObjectVersion",
  100. # ]
  101. # resources = [
  102. # "arn:${ var.aws_partition }:s3:::xdr-${ var.prefix }-${ var.environment }-splunk-apps",
  103. # "arn:${ var.aws_partition }:s3:::xdr-${ var.prefix }-${ var.environment }-splunk-apps/*",
  104. # ]
  105. # }
  106. #
  107. # statement {
  108. # sid = "KMSKeyAccess"
  109. # effect = "Allow"
  110. # actions = [
  111. # "kms:Decrypt",
  112. # "kms:GenerateDataKeyWithoutPlaintext",
  113. # "kms:Verify",
  114. # "kms:GenerateDataKeyPairWithoutPlaintext",
  115. # "kms:GenerateDataKeyPair",
  116. # "kms:ReEncryptFrom",
  117. # "kms:Encrypt",
  118. # "kms:GenerateDataKey",
  119. # "kms:ReEncryptTo",
  120. # "kms:Sign",
  121. # ]
  122. # resources = [ "*" ]
  123. # }
  124. #}
  125. #
  126. #resource "aws_iam_role_policy_attachment" "phantom_instance_policy_attach" {
  127. # role = aws_iam_role.phantom_instance_role.name
  128. # policy_arn = aws_iam_policy.phantom_instance_policy.arn
  129. #}