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

Add an IAM user for the Cloud Service Broker and the SMTP brokerpak #1644

Merged
merged 3 commits into from
Apr 22, 2024
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
5 changes: 5 additions & 0 deletions terraform/modules/csb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Module CSB

Resources related to the Cloud Service Broker.

See also https://github.com/cloud-gov/csb.
86 changes: 86 additions & 0 deletions terraform/modules/csb/iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Originally from https://github.com/GSA-TTS/datagov-brokerpak-smtp/blob/main/permission-policies.tf
locals {
this_aws_account_id = data.aws_caller_identity.current.account_id
}

data "aws_caller_identity" "current" {}

data "aws_iam_policy_document" "brokerpak_smtp" {
statement {
effect = "Allow"
actions = ["ses:*"]
resources = ["*"]
}

statement {
effect = "Allow"
actions = [
"iam:CreateUser",
"iam:DeleteUser",
"iam:GetUser",
"iam:CreateAccessKey",
"iam:DeleteAccessKey",
"iam:GetUserPolicy",
"iam:PutUserPolicy",
"iam:DeleteUserPolicy",
"iam:CreatePolicy",
"iam:DeletePolicy",
"iam:GetPolicy",
"iam:AttachUserPolicy",
"iam:DetachUserPolicy",
"iam:List*"
]
resources = ["*"]
}

statement {
effect = "Allow"
actions = ["route53:ListHostedZones"]
resources = ["*"]
}

statement {
effect = "Allow"
actions = [
"sns:CreateTopic",
"sns:DeleteTopic",
"sns:SetTopicAttributes",
"sns:GetTopicAttributes",
"sns:ListTagsForResource",
"sns:Subscribe",
"sns:Unsubscribe",
"sns:GetSubscriptionAttributes"
]
resources = ["*"]
}
}

resource "aws_iam_policy" "brokerpak_smtp" {
name = "brokerpak_smtp"
description = "SMTP broker policy (covers SES, IAM, and supplementary Route53)"
policy = data.aws_iam_policy_document.brokerpak_smtp.json
}

resource "aws_iam_user" "iam_user" {
name = "${var.stack_description}-csb"
}

resource "aws_iam_access_key" "iam_access_key" {
user = aws_iam_user.iam_user.name
}

resource "aws_iam_user_policy_attachment" "csb_policies" {
for_each = toset([
// ACM manager: for aws_acm_certificate, aws_acm_certificate_validation
"arn:aws-us-gov:iam::aws:policy/AWSCertificateManagerFullAccess",

// Route53 manager: for aws_route53_record, aws_route53_zone
"arn:aws-us-gov:iam::aws:policy/AmazonRoute53FullAccess",

// SMTP brokerpak policy defined above
"arn:aws-us-gov:iam::${local.this_aws_account_id}:policy/${aws_iam_policy.brokerpak_smtp.name}",
])

user = aws_iam_user.iam_user.name
policy_arn = each.key
jameshochadel marked this conversation as resolved.
Show resolved Hide resolved
}
22 changes: 22 additions & 0 deletions terraform/modules/csb/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
output "username" {
value = aws_iam_user.iam_user.name
}

output "access_key_id_prev" {
value = ""
}

output "secret_access_key_prev" {
value = ""
}

output "access_key_id_curr" {
value = aws_iam_access_key.iam_access_key.id
sensitive = true
}

output "secret_access_key_curr" {
value = aws_iam_access_key.iam_access_key.secret
sensitive = true
}

3 changes: 3 additions & 0 deletions terraform/modules/csb/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "stack_description" {
description = "Like development, staging, or production."
}
9 changes: 9 additions & 0 deletions terraform/modules/csb/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">= 0.15"
required_providers {
aws = {
source = "hashicorp/aws"
version = "< 6.0.0"
}
}
}
6 changes: 6 additions & 0 deletions terraform/stacks/main/stack.tf
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,9 @@ module "sns" {
sns_cg_platform_slack_notifications_name = "${var.stack_description}-platform-slack-notifications"
sns_cg_platform_slack_notifications_email = var.sns_cg_platform_slack_notifications_email
}

module "cloud_service_broker" {
source = "../../modules/csb"

stack_description = var.stack_description
}
Loading