iam.tf 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. statement {
  20. sid = ""
  21. effect = "Allow"
  22. resources = ["${aws_s3_bucket.storage.arn}/*"]
  23. actions = [
  24. "s3:PutObject",
  25. "s3:GetObject",
  26. "s3:GetObjectVersion",
  27. ]
  28. }
  29. }
  30. resource "aws_iam_policy" "auth_s3" {
  31. name = "xdr-vmray-auth-s3"
  32. policy = data.aws_iam_policy_document.policy_auth_s3.json
  33. }
  34. resource "aws_iam_role_policy_attachment" "attach_auth_s3" {
  35. role = module.instance_profile.role_id
  36. policy_arn = aws_iam_policy.auth_s3.arn
  37. }
  38. // Allow use of the key
  39. data "aws_iam_policy_document" "policy_kms" {
  40. statement {
  41. sid = "AllowKMSUse"
  42. effect = "Allow"
  43. resources = [aws_kms_key.s3.arn]
  44. actions = [
  45. "kms:Encrypt",
  46. "kms:Decrypt",
  47. "kms:ReEncrypt*",
  48. "kms:GenerateDataKey*",
  49. "kms:DescribeKey"
  50. ]
  51. }
  52. }
  53. resource "aws_iam_policy" "auth_kms" {
  54. name = "xdr-vmray-kms"
  55. policy = data.aws_iam_policy_document.policy_kms.json
  56. }
  57. resource "aws_iam_role_policy_attachment" "attach_kms" {
  58. role = module.instance_profile.role_id
  59. policy_arn = aws_iam_policy.auth_kms.arn
  60. }