iam.tf 4.4 KB

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