iam.tf 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # VMRay gets access to read/write to its backup bucket and use its s3 key
  2. module "instance_profile" {
  3. source = "../../submodules/iam/base_instance_profile"
  4. prefix = "xdr-vmray"
  5. aws_partition = var.aws_partition
  6. aws_account_id = var.aws_account_id
  7. }
  8. // S3 is used for backups
  9. data "aws_iam_policy_document" "policy_auth_s3" {
  10. statement {
  11. sid = ""
  12. effect = "Allow"
  13. resources = [aws_s3_bucket.storage.arn]
  14. actions = [
  15. "s3:ListBucket",
  16. "s3:ListBucketVersions",
  17. ]
  18. }
  19. # tfsec:ignore:aws-iam-no-policy-wildcards Allows use by the entire account
  20. statement {
  21. sid = ""
  22. effect = "Allow"
  23. resources = ["${aws_s3_bucket.storage.arn}/*"]
  24. actions = [
  25. "s3:PutObject",
  26. "s3:GetObject",
  27. "s3:GetObjectVersion",
  28. ]
  29. }
  30. }
  31. resource "aws_iam_policy" "auth_s3" {
  32. name = "xdr-vmray-auth-s3"
  33. policy = data.aws_iam_policy_document.policy_auth_s3.json
  34. }
  35. resource "aws_iam_role_policy_attachment" "attach_auth_s3" {
  36. role = module.instance_profile.role_id
  37. policy_arn = aws_iam_policy.auth_s3.arn
  38. }
  39. // Allow use of the key
  40. # tfsec:ignore:aws-iam-no-policy-wildcards Allows use by the entire account
  41. data "aws_iam_policy_document" "policy_kms" {
  42. statement {
  43. sid = "AllowKMSUse"
  44. effect = "Allow"
  45. resources = [aws_kms_key.s3.arn]
  46. actions = [
  47. "kms:Encrypt",
  48. "kms:Decrypt",
  49. "kms:ReEncrypt*",
  50. "kms:GenerateDataKey*",
  51. "kms:DescribeKey"
  52. ]
  53. }
  54. }
  55. resource "aws_iam_policy" "auth_kms" {
  56. name = "xdr-vmray-kms"
  57. policy = data.aws_iam_policy_document.policy_kms.json
  58. }
  59. resource "aws_iam_role_policy_attachment" "attach_kms" {
  60. role = module.instance_profile.role_id
  61. policy_arn = aws_iam_policy.auth_kms.arn
  62. }