instance_profile.tf 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #############################
  2. # GitHub Enterprise instance profile
  3. #
  4. # Includes policies for GitHub Enterprise:
  5. # * Same policies as the default instance profile
  6. module "instance_profile" {
  7. source = "../../submodules/iam/base_instance_profile"
  8. prefix = "xdr-github"
  9. aws_partition = var.aws_partition
  10. aws_account_id = var.aws_account_id
  11. }
  12. # GitHub Enterprise Specific Policy
  13. resource "aws_iam_policy" "github_instance_policy" {
  14. name = "github_instance_policy"
  15. path = "/launchroles/"
  16. description = "This policy allows github-specific functions"
  17. policy = data.aws_iam_policy_document.github_instance_policy_doc.json
  18. }
  19. data "aws_iam_policy_document" "github_instance_policy_doc" {
  20. # checkov:skip=CKV_AWS_111: see tfsec aws-iam-no-policy-wildcard ignore comment
  21. # Allow using S3 for GH Actions
  22. statement {
  23. sid = "GeneralBucketAccess"
  24. effect = "Allow"
  25. actions = [
  26. "s3:ListAllMyBuckets",
  27. ]
  28. resources = ["*"]
  29. }
  30. statement {
  31. sid = "S3BucketAccess"
  32. effect = "Allow"
  33. actions = [
  34. "s3:PutObject",
  35. "s3:GetObject",
  36. "s3:ListBucketMultipartUploads",
  37. "s3:ListMultipartUploadParts",
  38. "s3:AbortMultipartUpload",
  39. "s3:DeleteObject",
  40. "s3:ListBucket",
  41. # "s3:GetLifecycleConfiguration",
  42. # "s3:DeleteObjectVersion",
  43. # "s3:ListBucketVersions",
  44. # "s3:GetBucketLogging",
  45. # "s3:RestoreObject",
  46. # "s3:GetBucketVersioning",
  47. # "s3:PutLifecycleConfiguration",
  48. # "s3:GetBucketCORS",
  49. # "s3:GetBucketLocation",
  50. # "s3:GetObjectVersion",
  51. ]
  52. resources = [
  53. "arn:${var.aws_partition}:s3:::xdr-github-enterprise-${var.environment}-github-actions",
  54. "arn:${var.aws_partition}:s3:::xdr-github-enterprise-${var.environment}-github-actions/*",
  55. ]
  56. }
  57. statement {
  58. sid = "KMSKeyAccess"
  59. effect = "Allow"
  60. actions = [
  61. "kms:Decrypt",
  62. "kms:GenerateDataKeyWithoutPlaintext",
  63. "kms:Verify",
  64. "kms:GenerateDataKeyPairWithoutPlaintext",
  65. "kms:GenerateDataKeyPair",
  66. "kms:ReEncryptFrom",
  67. "kms:Encrypt",
  68. "kms:GenerateDataKey",
  69. "kms:ReEncryptTo",
  70. "kms:Sign",
  71. ]
  72. # tfsec:ignore:aws-iam-no-policy-wildcards Allows use by the entire account
  73. resources = ["*"]
  74. }
  75. }
  76. resource "aws_iam_role_policy_attachment" "github_instance_policy_attach" {
  77. role = module.instance_profile.role_id
  78. policy_arn = aws_iam_policy.github_instance_policy.arn
  79. }