iam.tf 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. resource "aws_iam_role" "codebuild_splunk_apps_role" {
  2. name = "codebuild_splunk_apps_role"
  3. path = "/aws_services/"
  4. assume_role_policy = <<EOF
  5. {
  6. "Version": "2012-10-17",
  7. "Statement": [
  8. {
  9. "Effect": "Allow",
  10. "Principal": {
  11. "Service": [
  12. "codebuild.amazonaws.com"
  13. ]
  14. },
  15. "Action": "sts:AssumeRole"
  16. }
  17. ]
  18. }
  19. EOF
  20. }
  21. resource "aws_iam_role_policy_attachment" "codebuild_splunk_apps_role_policy_attach" {
  22. role = aws_iam_role.codebuild_splunk_apps_role.name
  23. policy_arn = aws_iam_policy.codebuild_splunk_apps_policy.arn
  24. }
  25. # Some things about this policy I'm not perfectly sure about, like
  26. # should the account number be hardcoded? Also, it reads like we'll have to
  27. # update it each time we have a new repository added to codecommit - that
  28. # or we'll need to authorize the codebuild role to be able to pull from any
  29. # codecommit repo. Which may be fine?
  30. resource "aws_iam_policy" "codebuild_splunk_apps_policy" {
  31. name = "codebuild_splunk_apps_policy"
  32. description = "Policy for AWS codebuild to build and store artifacts"
  33. path = "/aws_services/"
  34. policy = <<EOF
  35. {
  36. "Version": "2012-10-17",
  37. "Statement": [
  38. {
  39. "Effect": "Allow",
  40. "Resource": [
  41. "arn:${var.aws_partition}:logs:${var.aws_region}:${var.aws_account_id}:log-group:/aws/codebuild/*"
  42. ],
  43. "Action": [
  44. "logs:CreateLogGroup",
  45. "logs:CreateLogStream",
  46. "logs:PutLogEvents"
  47. ]
  48. },
  49. {
  50. "Effect": "Allow",
  51. "Resource": [
  52. "arn:${var.aws_partition}:s3:::codepipeline-${var.aws_region}-*"
  53. ],
  54. "Action": [
  55. "s3:PutObject",
  56. "s3:GetObject",
  57. "s3:GetObjectVersion"
  58. ]
  59. },
  60. {
  61. "Effect": "Allow",
  62. "Resource": [
  63. "arn:${var.aws_partition}:codecommit:${var.aws_region}:${var.aws_account_id}:*"
  64. ],
  65. "Action": [
  66. "codecommit:GitPull"
  67. ]
  68. },
  69. {
  70. "Effect": "Allow",
  71. "Resource": [
  72. "arn:${var.aws_partition}:s3:::xdr-${var.splunk_prefix}-${var.environment}-splunk-apps/*",
  73. "arn:${var.aws_partition}:s3:::*"
  74. ],
  75. "Action": [
  76. "s3:PutObject",
  77. "s3:GetObject*",
  78. "s3:ListBucket"
  79. ]
  80. },
  81. {
  82. "Sid": "WriteToECR",
  83. "Effect": "Allow",
  84. "Resource": [
  85. "*"
  86. ],
  87. "Action": [
  88. "ecr:GetAuthorizationToken",
  89. "ecr:BatchCheckLayerAvailability",
  90. "ecr:CompleteLayerUpload",
  91. "ecr:GetAuthorizationToken",
  92. "ecr:InitiateLayerUpload",
  93. "ecr:PutImage",
  94. "ecr:UploadLayerPart"
  95. ]
  96. },
  97. {
  98. "Sid": "PullFromECR",
  99. "Effect": "Allow",
  100. "Resource": [
  101. "*"
  102. ],
  103. "Action": [
  104. "ecr:GetDownloadUrlForLayer",
  105. "ecr:BatchGetImage",
  106. "ecr:BatchCheckLayerAvailability"
  107. ]
  108. }
  109. ]
  110. }
  111. EOF
  112. }
  113. # !!!!! RETAINED FOR FUTURE USE !!!!!
  114. # Defines an IAM user that can only download ECR images, intended for
  115. # use in POP nodes where we need containers, but won't necessarily have
  116. # EC2 instance role credentials. Maybe one day this goes to vault, I
  117. # hope. It would be nice.
  118. # data "aws_iam_policy_document" "ecr_policy_pop" {
  119. # statement {
  120. # sid = "AllowECRReadOnly"
  121. # effect = "Allow"
  122. # actions = [
  123. # "ecr:GetAuthorizationToken",
  124. # "ecr:BatchCheckLayerAvailability",
  125. # "ecr:GetDownloadUrlForLayer",
  126. # "ecr:GetRepositoryPolicy",
  127. # "ecr:DescribeRepositories",
  128. # "ecr:ListImages",
  129. # "ecr:DescribeImages",
  130. # "ecr:BatchGetImage"
  131. # ]
  132. # resources = [
  133. # "*"
  134. # ]
  135. # }
  136. # }
  137. # resource "aws_iam_policy" "ecr_policy_pop" {
  138. # name = "ecr_policy_pop"
  139. # path = "/"
  140. # policy = "${data.aws_iam_policy_document.ecr_policy_pop.json}"
  141. # }
  142. # resource "aws_iam_user" "pop_service_account" {
  143. # name = "svc-mdrpop"
  144. # path = "/service/"
  145. # }
  146. # resource "aws_iam_user_policy_attachment" "pop_service_account_1" {
  147. # user = "${aws_iam_user.pop_service_account.name}"
  148. # policy_arn = "${aws_iam_policy.ecr_policy_pop.arn}"
  149. # }
  150. # resource "aws_iam_access_key" "pop_service_account" {
  151. # user = "${aws_iam_user.pop_service_account.name}"
  152. # pgp_key = "${file("../00-organizations-and-iam/duane_waddle.pgp")}"
  153. # }
  154. # output "pop_service_account_key_id" {
  155. # value = "${aws_iam_access_key.pop_service_account.id}"
  156. # }
  157. # output "pop_service_account_secret" {
  158. # value = "${aws_iam_access_key.pop_service_account.encrypted_secret}"
  159. # }
  160. # !!!!! END OF RETAINED FOR FUTURE USE !!!!!