iam_phantom_s3_role.tf 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. ]
  41. resources = ["*"]
  42. }
  43. statement {
  44. sid = "S3BucketAccess"
  45. effect = "Allow"
  46. actions = [
  47. "s3:GetLifecycleConfiguration",
  48. "s3:DeleteObjectVersion",
  49. "s3:ListBucketVersions",
  50. "s3:GetBucketLogging",
  51. "s3:RestoreObject",
  52. "s3:ListBucket",
  53. "s3:GetBucketVersioning",
  54. "s3:PutObject",
  55. "s3:GetObject",
  56. "s3:PutLifecycleConfiguration",
  57. "s3:GetBucketCORS",
  58. "s3:DeleteObject",
  59. "s3:GetBucketLocation",
  60. "s3:GetObjectVersion",
  61. ]
  62. resources = [
  63. aws_s3_bucket.bucket.arn,
  64. "${aws_s3_bucket.bucket.arn}/*",
  65. ]
  66. }
  67. statement {
  68. sid = "S3ReadOnlyBucketAccess"
  69. effect = "Allow"
  70. actions = [
  71. "s3:ListBucketVersions",
  72. "s3:ListBucket",
  73. "s3:GetBucketVersioning",
  74. "s3:GetObject",
  75. "s3:GetBucketCORS",
  76. "s3:GetBucketLocation",
  77. "s3:GetObjectVersion",
  78. ]
  79. resources = [
  80. aws_s3_bucket.bucket.arn,
  81. "${aws_s3_bucket.bucket.arn}/*",
  82. ]
  83. }
  84. statement {
  85. sid = "KMSKeyAccess"
  86. effect = "Allow"
  87. actions = [
  88. "kms:Decrypt",
  89. "kms:GenerateDataKeyWithoutPlaintext",
  90. "kms:Verify",
  91. "kms:GenerateDataKeyPairWithoutPlaintext",
  92. "kms:GenerateDataKeyPair",
  93. "kms:ReEncryptFrom",
  94. "kms:Encrypt",
  95. "kms:GenerateDataKey",
  96. "kms:ReEncryptTo",
  97. "kms:Sign",
  98. ]
  99. resources = [aws_kms_key.bucketkey.arn]
  100. }
  101. }