iam_phantom_s3_role.tf 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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(local.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. # tfsec:ignore:aws-iam-no-policy-wildcards Allows use by the entire account
  63. resources = [
  64. aws_s3_bucket.bucket.arn,
  65. "${aws_s3_bucket.bucket.arn}/*",
  66. ]
  67. }
  68. statement {
  69. sid = "S3ReadOnlyBucketAccess"
  70. effect = "Allow"
  71. actions = [
  72. "s3:ListBucketVersions",
  73. "s3:ListBucket",
  74. "s3:GetBucketVersioning",
  75. "s3:GetObject",
  76. "s3:GetBucketCORS",
  77. "s3:GetBucketLocation",
  78. "s3:GetObjectVersion",
  79. ]
  80. # tfsec:ignore:aws-iam-no-policy-wildcards Allows use by the entire account
  81. resources = [
  82. aws_s3_bucket.bucket.arn,
  83. "${aws_s3_bucket.bucket.arn}/*",
  84. ]
  85. }
  86. statement {
  87. sid = "KMSKeyAccess"
  88. effect = "Allow"
  89. actions = [
  90. "kms:Decrypt",
  91. "kms:GenerateDataKeyWithoutPlaintext",
  92. "kms:Verify",
  93. "kms:GenerateDataKeyPairWithoutPlaintext",
  94. "kms:GenerateDataKeyPair",
  95. "kms:ReEncryptFrom",
  96. "kms:Encrypt",
  97. "kms:GenerateDataKey",
  98. "kms:ReEncryptTo",
  99. "kms:Sign",
  100. ]
  101. resources = [aws_kms_key.bucketkey.arn]
  102. }
  103. }