diff --git a/.gitignore b/.gitignore index 98e2441..f88191c 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,6 @@ override.tf.json # End of https://www.gitignore.io/api/osx,ruby,terraform,visualstudiocode .kitchen/ + +## IDEA based IDEs +.idea diff --git a/modules/iam/main.tf b/modules/iam/main.tf index e8884a1..4b1208b 100644 --- a/modules/iam/main.tf +++ b/modules/iam/main.tf @@ -44,7 +44,6 @@ resource "aws_iam_policy" "segment_data_lake_policy" { path = "/" description = "Gives access to resources in your Data Lake" policy = "${data.aws_iam_policy_document.segment_data_lake_policy_document.json}" - tags = "${local.tags}" } data "aws_iam_policy_document" "segment_data_lake_policy_document" { @@ -125,6 +124,36 @@ data "aws_iam_policy_document" "segment_data_lake_policy_document" { effect = "Allow" } + # Explicitly deny Segment to modify IAM or sensible configuration from the Data Lake S3 bucket. + statement { + sid = "DenyPrivilegedOperations" + actions = [ + "s3:BypassGovernanceRetention", + "s3:CreateAccessPoint", + "s3:DeleteAccessPoint", + "s3:DeleteAccessPointPolicy", + "s3:DeleteBucket", + "s3:DeleteBucketPolicy", + "s3:PutAccessPointPolicy", + "s3:PutAccountPublicAccessBlock", + "s3:PutBucketAcl", + "s3:PutBucketLogging", + "s3:PutBucketPolicy", + "s3:PutBucketPublicAccessBlock", + "s3:PutBucketVersioning", + "s3:PutBucketWebsite", + "s3:PutEncryptionConfiguration", + "s3:PutReplicationConfiguration" + ] + + resources = [ + "arn:aws:s3:::${var.s3_bucket}/*", + "arn:aws:s3:::${var.s3_bucket}", + ] + + effect = "Deny" + } + # Allows Segment to access Athena. statement { actions = [ @@ -182,84 +211,145 @@ EOF tags = "${local.tags}" } -resource "aws_iam_role_policy" "segment_emr_service_policy" { - name = "SegmentEMRServicePolicy${var.suffix}" - role = "${aws_iam_role.segment_emr_service_role.id}" +resource "aws_iam_policy" "segment_emr_service_role_policy" { + name = "SegmentEMRServicePolicy${var.suffix}" + path = "/" + policy = "${data.aws_iam_policy_document.segment_emr_service_policy_document.json}" +} - policy = <