|
@@ -0,0 +1,140 @@
|
|
|
+data "aws_iam_policy_document" "assume_role_policy" {
|
|
|
+ statement {
|
|
|
+ sid = "AllowRoles"
|
|
|
+ effect = "Allow"
|
|
|
+ actions = ["sts:AssumeRole"]
|
|
|
+
|
|
|
+ principals {
|
|
|
+ type = "AWS"
|
|
|
+ identifiers = var.role_assumers
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_iam_role" "role" {
|
|
|
+ name = local.fullname
|
|
|
+ path = "/service/"
|
|
|
+ force_detach_policies = true # causes "DeleteConflict" if not present
|
|
|
+
|
|
|
+ assume_role_policy = data.aws_iam_policy_document.assume_role_policy.json
|
|
|
+
|
|
|
+ tags = merge(var.standard_tags, var.tags)
|
|
|
+}
|
|
|
+
|
|
|
+# Appears the role can automatically create presigned URLs
|
|
|
+#resource "aws_iam_role_policy_attachment" "policy_attach_presigned_url" {
|
|
|
+# count = var.allow_presigned ? 1 : 0
|
|
|
+#
|
|
|
+# role = aws_iam_role.role.name
|
|
|
+# policy_arn = aws_iam_policy.policy_presigned_url.arn
|
|
|
+#}
|
|
|
+#
|
|
|
+#resource "aws_iam_policy" "policy_presigned_url" {
|
|
|
+# count = var.allow_presigned ? 1 : 0
|
|
|
+#
|
|
|
+# name_prefix = var.name
|
|
|
+# path = "/service/"
|
|
|
+# description = "Policy to allow signing of URLs for the ${local.fullname} bucket"
|
|
|
+# policy = data.aws_iam_policy_document.policy_doc_presigned_url.json
|
|
|
+#}
|
|
|
+#
|
|
|
+#data "aws_iam_policy_document" "policy_doc_presigned_url" {
|
|
|
+# count = var.allow_presigned ? 1 : 0
|
|
|
+#
|
|
|
+# statement {
|
|
|
+# sid = "TODO"
|
|
|
+# effect = "Allow"
|
|
|
+# actions = [
|
|
|
+# "s3:ListAllMyBuckets",
|
|
|
+# "s3:HeadBucket",
|
|
|
+# ]
|
|
|
+# resources = [ "*" ]
|
|
|
+# }
|
|
|
+#}
|
|
|
+
|
|
|
+resource "aws_iam_role_policy_attachment" "policy_attach" {
|
|
|
+ role = aws_iam_role.role.name
|
|
|
+ policy_arn = aws_iam_policy.policy.arn
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_iam_policy" "policy" {
|
|
|
+ name_prefix = var.name
|
|
|
+ path = "/service/"
|
|
|
+ description = "Policy to allow use of the ${local.fullname} bucket"
|
|
|
+ policy = data.aws_iam_policy_document.policy_doc.json
|
|
|
+}
|
|
|
+
|
|
|
+data "aws_iam_policy_document" "policy_doc" {
|
|
|
+ statement {
|
|
|
+ sid = "GeneralBucketAccess"
|
|
|
+ effect = "Allow"
|
|
|
+ actions = [
|
|
|
+ "s3:ListAllMyBuckets",
|
|
|
+ "s3:HeadBucket",
|
|
|
+ ]
|
|
|
+ resources = [ "*" ]
|
|
|
+ }
|
|
|
+
|
|
|
+ statement {
|
|
|
+ sid = "S3BucketAccess"
|
|
|
+ effect = "Allow"
|
|
|
+ actions = [
|
|
|
+ "s3:GetLifecycleConfiguration",
|
|
|
+ "s3:DeleteObjectVersion",
|
|
|
+ "s3:ListBucketVersions",
|
|
|
+ "s3:GetBucketLogging",
|
|
|
+ "s3:RestoreObject",
|
|
|
+ "s3:ListBuckets",
|
|
|
+ "s3:ListObjects",
|
|
|
+ "s3:ListObjectsV2",
|
|
|
+ "s3:GetBucketVersioning",
|
|
|
+ "s3:PutObject",
|
|
|
+ "s3:GetObject",
|
|
|
+ "s3:PutLifecycleConfiguration",
|
|
|
+ "s3:GetBucketCORS",
|
|
|
+ "s3:DeleteObject",
|
|
|
+ "s3:GetBucketLocation",
|
|
|
+ "s3:GetObjectVersion",
|
|
|
+ ]
|
|
|
+ resources = [
|
|
|
+ aws_s3_bucket.bucket.arn,
|
|
|
+ "${aws_s3_bucket.bucket.arn}/*",
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
+ statement {
|
|
|
+ sid = "S3ReadOnlyBucketAccess"
|
|
|
+ effect = "Allow"
|
|
|
+ actions = [
|
|
|
+ "s3:ListBucketVersions",
|
|
|
+ "s3:ListBuckets",
|
|
|
+ "s3:GetBucketVersioning",
|
|
|
+ "s3:GetObject",
|
|
|
+ "s3:GetBucketCORS",
|
|
|
+ "s3:GetBucketLocation",
|
|
|
+ "s3:GetObjectVersion",
|
|
|
+ ]
|
|
|
+ resources = [
|
|
|
+ aws_s3_bucket.bucket.arn,
|
|
|
+ "${aws_s3_bucket.bucket.arn}/*",
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
+ statement {
|
|
|
+ sid = "KMSKeyAccess"
|
|
|
+ effect = "Allow"
|
|
|
+ actions = [
|
|
|
+ "kms:Decrypt",
|
|
|
+ "kms:GenerateDataKeyWithoutPlaintext",
|
|
|
+ "kms:Verify",
|
|
|
+ "kms:GenerateDataKeyPairWithoutPlaintext",
|
|
|
+ "kms:GenerateDataKeyPair",
|
|
|
+ "kms:ReEncryptFrom",
|
|
|
+ "kms:Encrypt",
|
|
|
+ "kms:GenerateDataKey",
|
|
|
+ "kms:ReEncryptTo",
|
|
|
+ "kms:Sign",
|
|
|
+ ]
|
|
|
+ resources = [ aws_kms_key.bucketkey.arn ]
|
|
|
+ }
|
|
|
+}
|