Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance hub - landing bucket policy for AP jobs #4079

Merged
merged 6 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 24 additions & 41 deletions terraform/environments/performance-hub/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,35 @@
#
#------------------------------------------------------------------------------


# S3 bucket access policy for AP landing bucket (data pushed from
# Performance Hub to a bucket in the AP account - hence hard-coded bucket name)
# Legacy account was arn:aws:iam::677012035582:policy/read-ap-ppas
resource "aws_iam_policy" "s3_ap_landing_policy" {
name = "${local.application_name}-s3-ap-landing-policy"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "MOJAnalyticalPlatformListBucket",
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource": "arn:aws:s3:::hmpps-performance-hub-landing"
},
{
"Sid": "MOJAnalyticalPlatformWriteBucket",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:PutObjectAcl",
"s3:GetObject"
],
"Resource": "arn:aws:s3:::hmpps-performance-hub-landing/*"
}
]
}
EOF
}

# resource "aws_iam_role" "s3_ap_landing_role" {
# name = "${local.application_name}-s3-ap-landing-role"
# assume_role_policy = data.aws_iam_policy_document.s3-access-policy.json
# assume_role_policy = jsonencode({
# Version = "2012-10-17"
# Statement = [
# {
# Sid: "MOJAnalyticalPlatformListBucket",
# Effect: "Allow",
# Action: [
# "s3:ListBucket",
# "s3:GetBucketLocation"
# ],
# "Resource": "arn:aws:s3:::hmpps-performance-hub-landing"
# },
# {
# Sid: "MOJAnalyticalPlatformWriteBucket",
# Effect: "Allow",
# Action: [
# "s3:PutObject",
# "s3:PutObjectAcl",
# "s3:GetObject"
# ],
# Resource: "arn:aws:s3:::hmpps-performance-hub-landing/*"
# }
# ]
# })
# tags = merge(
# local.tags,
# {
Expand All @@ -48,10 +40,6 @@ EOF
# )
# }

# resource "aws_iam_role_policy_attachment" "s3_ap_landing_attachment" {
# role = aws_iam_role.s3_ap_landing_role.name
# policy_arn = aws_iam_policy.s3_ap_landing_policy.arn
# }

# S3 bucket access policy for Performance Hub landing bucket (data pushed from
# AP to a bucket in this account)
Expand Down Expand Up @@ -88,8 +76,3 @@ resource "aws_iam_policy" "s3_hub_Landing_policy" {
}
EOF
}

# IAM user for uploads & content bucket
# resource "aws_iam_user" "uploaduser" {
# name = "uploaduser"
# }
26 changes: 26 additions & 0 deletions terraform/environments/performance-hub/s3.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ resource "aws_s3_bucket_versioning" "upload_files" {
}
}

## was a "grant all" policy attached directy to cicduser
# resource "aws_s3_bucket_policy" "upload_files_policy" {
# bucket = aws_s3_bucket.upload_files.id
# policy = jsonencode({
Expand Down Expand Up @@ -208,6 +209,31 @@ resource "aws_s3_object" "prison_performance" {
key = "prison_performance/"
}

data "aws_iam_policy_document" "allow_ap_write_to_landing" {
statement {
principals {
type = "AWS"
identifiers = [
"arn:aws:iam::593291632749:role/service-role/export_prison_incidents-move",
"arn:aws:iam::593291632749:role/service-role/export_prison_performance-move"
]
}

actions = [
"s3:PutObject",
"s3:PutObjectAcl"
]

resources = [
"arn:aws:s3:::${module.ap_landing_bucket.bucket.id}/*"
]
}
}

resource "aws_s3_bucket_policy" "allow_ap_write_to_landing" {
bucket = module.ap_landing_bucket.bucket.id
policy = data.aws_iam_policy_document.allow_ap_write_to_landing.json
}

#------------------------------------------------------------------------------
# KMS setup for S3
Expand Down