iam.tf 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. resource "aws_iam_instance_profile" "teleport" {
  2. name = "${var.instance_name}-role"
  3. role = aws_iam_role.auth.name
  4. #depends_on = [aws_iam_role_policy.auth_ssm]
  5. }
  6. // Teleport instance profile and roles
  7. resource "aws_iam_role" "auth" {
  8. name = "${var.instance_name}-role"
  9. path = "/instance/"
  10. assume_role_policy = <<EOF
  11. {
  12. "Version": "2012-10-17",
  13. "Statement": [
  14. {
  15. "Effect": "Allow",
  16. "Principal": {"Service": "ec2.amazonaws.com"},
  17. "Action": "sts:AssumeRole"
  18. }
  19. ]
  20. }
  21. EOF
  22. }
  23. # FTD: No ssm in our deployment
  24. #resource "aws_iam_role_policy" "ssm" {
  25. # name = "${var.instance_name}-teleport-ssm"
  26. # role = aws_iam_role.auth.id
  27. #
  28. # policy = <<EOF
  29. #{
  30. # "Version": "2012-10-17",
  31. # "Statement": [
  32. # {
  33. # "Effect": "Allow",
  34. # "Action": [
  35. # "ssm:DescribeParameters",
  36. # "ssm:GetParameters",
  37. # "ssm:GetParametersByPath",
  38. # "ssm:GetParameter",
  39. # "ssm:PutParameter",
  40. # "ssm:DeleteParameter"
  41. # ],
  42. # "Resource": "arn:${var.aws_partition}:ssm:${var.aws_region}:${var.aws_account_id}:parameter/teleport/${var.instance_name}/*"
  43. # },
  44. # {
  45. # "Effect":"Allow",
  46. # "Action":[
  47. # "kms:Decrypt"
  48. # ],
  49. # "Resource":[
  50. # "arn:${var.aws_partition}:kms:${var.aws_region}:${var.aws_account_id}:key/${data.aws_kms_alias.ssm.target_key_id}"
  51. # ]
  52. # }
  53. # ]
  54. #}
  55. #EOF
  56. #
  57. #}
  58. // Auth server uses DynamoDB as a backend, and this is to allow read/write from the dynamo tables
  59. data "aws_iam_policy_document" "policy_auth_dynamo" {
  60. statement {
  61. sid = "AllActionsOnTeleportDB"
  62. effect = "Allow"
  63. resources = ["arn:${var.aws_partition}:dynamodb:${var.aws_region}:${var.aws_account_id}:table/${aws_dynamodb_table.teleport.name}"]
  64. actions = ["dynamodb:*"]
  65. }
  66. statement {
  67. sid = "AllActionsOnTeleportEventsDB"
  68. effect = "Allow"
  69. resources = ["arn:${var.aws_partition}:dynamodb:${var.aws_region}:${var.aws_account_id}:table/${aws_dynamodb_table.teleport_events.name}"]
  70. actions = ["dynamodb:*"]
  71. }
  72. statement {
  73. sid = "AllActionsOnTeleportEventsIndexDB"
  74. effect = "Allow"
  75. resources = ["arn:${var.aws_partition}:dynamodb:${var.aws_region}:${var.aws_account_id}:table/${aws_dynamodb_table.teleport_events.name}/index/*"]
  76. actions = ["dynamodb:*"]
  77. }
  78. statement {
  79. sid = "AllActionsOnTeleportStreamsDB"
  80. effect = "Allow"
  81. resources = ["arn:${var.aws_partition}:dynamodb:${var.aws_region}:${var.aws_account_id}:table/${aws_dynamodb_table.teleport.name}/stream/*"]
  82. actions = ["dynamodb:*"]
  83. }
  84. }
  85. resource "aws_iam_policy" "auth_dynamo" {
  86. name = "${var.instance_name}-auth-dynamo"
  87. policy = data.aws_iam_policy_document.policy_auth_dynamo.json
  88. }
  89. resource "aws_iam_role_policy_attachment" "attach_auth_dynamo" {
  90. role = aws_iam_role.auth.name
  91. policy_arn = aws_iam_policy.auth_dynamo.arn
  92. }
  93. // Allow auth servers to update locks
  94. data "aws_iam_policy_document" "policy_auth_locks" {
  95. statement {
  96. sid = "AllActionsOnLocks"
  97. effect = "Allow"
  98. resources = ["arn:${var.aws_partition}:dynamodb:${var.aws_region}:${var.aws_account_id}:table/${aws_dynamodb_table.locks.name}"]
  99. actions = ["dynamodb:*"]
  100. }
  101. }
  102. resource "aws_iam_policy" "auth_locks" {
  103. name = "${var.instance_name}-auth-locks"
  104. policy = data.aws_iam_policy_document.policy_auth_locks.json
  105. }
  106. resource "aws_iam_role_policy_attachment" "attach_auth_locks" {
  107. role = aws_iam_role.auth.name
  108. policy_arn = aws_iam_policy.auth_locks.arn
  109. }
  110. // S3 is used for letsencrypt, auth servers request certificates from letsencrypt
  111. // and publish to S3 encrypted bucket. SSM is not used, because certificates and private keys
  112. // are too big for SSM.
  113. data "aws_iam_policy_document" "policy_auth_s3" {
  114. statement {
  115. sid = ""
  116. effect = "Allow"
  117. resources = ["arn:${var.aws_partition}:s3:::${aws_s3_bucket.storage.bucket}"]
  118. actions = [
  119. "s3:ListBucket",
  120. "s3:ListBucketVersions",
  121. ]
  122. }
  123. statement {
  124. sid = ""
  125. effect = "Allow"
  126. resources = ["arn:${var.aws_partition}:s3:::${aws_s3_bucket.storage.bucket}/*"]
  127. actions = [
  128. "s3:PutObject",
  129. "s3:GetObject",
  130. "s3:GetObjectVersion",
  131. ]
  132. }
  133. }
  134. resource "aws_iam_policy" "auth_s3" {
  135. name = "${var.instance_name}-auth-s3"
  136. policy = data.aws_iam_policy_document.policy_auth_s3.json
  137. }
  138. resource "aws_iam_role_policy_attachment" "attach_auth_s3" {
  139. role = aws_iam_role.auth.name
  140. policy_arn = aws_iam_policy.auth_s3.arn
  141. }
  142. // Allow use of the key
  143. data "aws_iam_policy_document" "policy_kms" {
  144. statement {
  145. sid = "AllowKMSUse"
  146. effect = "Allow"
  147. resources = [ aws_kms_key.s3.arn ]
  148. actions = [
  149. "kms:Encrypt",
  150. "kms:Decrypt",
  151. "kms:ReEncrypt*",
  152. "kms:GenerateDataKey*",
  153. "kms:DescribeKey"
  154. ]
  155. }
  156. }
  157. resource "aws_iam_policy" "auth_kms" {
  158. name = "${var.instance_name}-kms"
  159. policy = data.aws_iam_policy_document.policy_kms.json
  160. }
  161. resource "aws_iam_role_policy_attachment" "attach_kms" {
  162. role = aws_iam_role.auth.name
  163. policy_arn = aws_iam_policy.auth_kms.arn
  164. }
  165. // FTD: This is for letsencrypt, which we don't (presently) use.
  166. // Auth server uses route53 to get certs for domain, this allows
  167. // read/write operations from the zone.
  168. #resource "aws_iam_role_policy" "auth_route53" {
  169. # name = "${var.instance_name}-auth-route53"
  170. # role = aws_iam_role.auth.id
  171. #
  172. # policy = <<EOF
  173. #{
  174. # "Version": "2012-10-17",
  175. # "Id": "certbot-dns-route53 policy",
  176. # "Statement": [
  177. # {
  178. # "Effect": "Allow",
  179. # "Action": [
  180. # "route53:ListHostedZones",
  181. # "route53:GetChange"
  182. # ],
  183. # "Resource": [
  184. # "*"
  185. # ]
  186. # },
  187. # {
  188. # "Effect" : "Allow",
  189. # "Action" : [
  190. # "route53:ChangeResourceRecordSets"
  191. # ],
  192. # "Resource" : [
  193. # "arn:${var.aws_partition}:route53:::hostedzone/${data.aws_route53_zone.proxy.zone_id}"
  194. # ]
  195. # }
  196. # ]
  197. #}
  198. #EOF
  199. #
  200. #}