iam_phantom_s3_role.tf 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. resource "aws_iam_role" "phantom_s3_role" {
  2. name = "phantom_s3"
  3. path = "/service/"
  4. force_detach_policies = true # causes "DeleteConflict" if not present
  5. # the extra_trusted_salt variable allows the addition of additional
  6. # trusted sources, such as the dev salt master (for dev environments)
  7. # and developer users.
  8. assume_role_policy = <<EOF
  9. {
  10. "Version": "2012-10-17",
  11. "Statement": [
  12. {
  13. "Effect": "Allow",
  14. "Principal": {
  15. "AWS": "arn:${ var.aws_partition }:iam::${ var.aws_account_id }:role/instance/xdr-phantom-instance-role"
  16. },
  17. "Action": "sts:AssumeRole"
  18. }
  19. ]
  20. }
  21. EOF
  22. tags = merge(var.standard_tags, var.tags)
  23. }
  24. resource "aws_iam_role_policy_attachment" "phantom_s3_policy_attach" {
  25. role = aws_iam_role.phantom_s3_role.name
  26. policy_arn = aws_iam_policy.phantom_s3_policy.arn
  27. }
  28. resource "aws_iam_policy" "phantom_s3_policy" {
  29. name = "phantom_s3_policy"
  30. path = "/service/"
  31. description = "Policy which allows phantom to read/write to the S3 bucket"
  32. policy = data.aws_iam_policy_document.phantom_s3_policy_doc.json
  33. }
  34. data "aws_iam_policy_document" "phantom_s3_policy_doc" {
  35. statement {
  36. sid = "GeneralBucketAccess"
  37. effect = "Allow"
  38. actions = [
  39. "s3:ListAllMyBuckets",
  40. "s3:HeadBucket",
  41. ]
  42. resources = [ "*" ]
  43. }
  44. statement {
  45. sid = "S3BucketAccess"
  46. effect = "Allow"
  47. actions = [
  48. "s3:GetLifecycleConfiguration",
  49. "s3:DeleteObjectVersion",
  50. "s3:ListBucketVersions",
  51. "s3:GetBucketLogging",
  52. "s3:RestoreObject",
  53. "s3:ListBuckets",
  54. "s3:ListObjects",
  55. "s3:ListObjectsV2",
  56. "s3:GetBucketVersioning",
  57. "s3:PutObject",
  58. "s3:GetObject",
  59. "s3:PutLifecycleConfiguration",
  60. "s3:GetBucketCORS",
  61. "s3:DeleteObject",
  62. "s3:GetBucketLocation",
  63. "s3:GetObjectVersion",
  64. ]
  65. resources = [
  66. aws_s3_bucket.bucket.arn,
  67. "${aws_s3_bucket.bucket.arn}/*",
  68. ]
  69. }
  70. statement {
  71. sid = "S3ReadOnlyBucketAccess"
  72. effect = "Allow"
  73. actions = [
  74. "s3:ListBucketVersions",
  75. "s3:ListBuckets",
  76. "s3:GetBucketVersioning",
  77. "s3:GetObject",
  78. "s3:GetBucketCORS",
  79. "s3:GetBucketLocation",
  80. "s3:GetObjectVersion",
  81. ]
  82. resources = [
  83. aws_s3_bucket.bucket.arn,
  84. "${aws_s3_bucket.bucket.arn}/*",
  85. ]
  86. }
  87. statement {
  88. sid = "KMSKeyAccess"
  89. effect = "Allow"
  90. actions = [
  91. "kms:Decrypt",
  92. "kms:GenerateDataKeyWithoutPlaintext",
  93. "kms:Verify",
  94. "kms:GenerateDataKeyPairWithoutPlaintext",
  95. "kms:GenerateDataKeyPair",
  96. "kms:ReEncryptFrom",
  97. "kms:Encrypt",
  98. "kms:GenerateDataKey",
  99. "kms:ReEncryptTo",
  100. "kms:Sign",
  101. ]
  102. resources = [ aws_kms_key.bucketkey.arn ]
  103. }
  104. }