instance_profile.tf 3.6 KB

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