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

DSOS-2123: add oem secretmanager secrets #3352

Merged
merged 35 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4276310
add resources option to secretmanager policy
drobinson-moj Sep 8, 2023
51f094c
add oem secrets and policy
drobinson-moj Sep 8, 2023
fb1b120
whitespace
drobinson-moj Sep 8, 2023
e74214d
fix
drobinson-moj Sep 8, 2023
9c5cf5e
test
drobinson-moj Sep 8, 2023
4cf3cda
fix
drobinson-moj Sep 8, 2023
de07fdc
rename secret
drobinson-moj Sep 11, 2023
d6e10bc
add EC2 policy for updating secrets
drobinson-moj Sep 11, 2023
2b629ba
update baseline opts
drobinson-moj Sep 11, 2023
77a7436
fix
drobinson-moj Sep 11, 2023
9b7f76b
fix
drobinson-moj Sep 11, 2023
791b2e7
fix
drobinson-moj Sep 11, 2023
f986c68
fix
drobinson-moj Sep 11, 2023
6f315ef
fix
drobinson-moj Sep 11, 2023
c982e6d
fix
drobinson-moj Sep 11, 2023
4fd7a87
update secrets policy
drobinson-moj Sep 11, 2023
229459c
test
drobinson-moj Sep 11, 2023
708c2b3
fix
drobinson-moj Sep 11, 2023
06849c6
fix
drobinson-moj Sep 11, 2023
7529335
test
drobinson-moj Sep 11, 2023
4194488
test
drobinson-moj Sep 11, 2023
484d54d
test
drobinson-moj Sep 11, 2023
a0fa42d
test
drobinson-moj Sep 11, 2023
1f1efd6
test
drobinson-moj Sep 11, 2023
2db9aff
test
drobinson-moj Sep 11, 2023
fa4c5bc
test
drobinson-moj Sep 11, 2023
e9b0cea
add EMREP secret
drobinson-moj Sep 12, 2023
62ce194
add Get Secret and Parameter policies
drobinson-moj Sep 12, 2023
cc0bd3d
allow GetResourcePolicy
drobinson-moj Sep 12, 2023
43c2a87
allow GetResourcePolicy
drobinson-moj Sep 12, 2023
6833c5d
Remove ResourcePolicy permission
drobinson-moj Sep 12, 2023
9326a26
add PutResourcePolicy
drobinson-moj Sep 12, 2023
2ac622b
test
drobinson-moj Sep 13, 2023
2d51d4b
update policy
drobinson-moj Sep 13, 2023
2df692c
update naming
drobinson-moj Sep 13, 2023
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
6 changes: 5 additions & 1 deletion terraform/environments/hmpps-oem/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ locals {
enable_ec2_self_provision = true
enable_oracle_secure_web = true
enable_ec2_put_parameter = true
enable_ec2_put_secret = true
enable_shared_s3 = true # adds permissions to ec2s to interact with devtest or prodpreprod buckets
db_backup_s3 = true # adds db backup buckets
enable_oracle_secure_web = true # allows db to list all buckets
Expand Down Expand Up @@ -54,7 +55,10 @@ locals {
}
}

baseline_secretsmanager_secrets = {}
baseline_secretsmanager_secrets = {
"/oracle/oem" = local.oem_secretsmanager_secrets
"/oracle/database/EMREP" = local.oem_secretsmanager_secrets
}

baseline_security_groups = {
data-oem = local.security_groups.data_oem
Expand Down
48 changes: 48 additions & 0 deletions terraform/environments/hmpps-oem/locals_oem.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,54 @@ locals {
}
}

oem_secret_policy_write = {
effect = "Allow"
actions = [
"secretsmanager:DeleteResourcePolicy",
"secretsmanager:DescribeSecret",
"secretsmanager:GetResourcePolicy",
"secretsmanager:PutResourcePolicy",
"secretsmanager:UpdateSecret",
]
principals = {
type = "AWS"
identifiers = [
"hmpps-oem-${local.environment}",
]
}
resources = [
"arn:aws:secretsmanager:*:*:secret:*"
]
}
oem_secret_policy_read = {
effect = "Allow"
actions = [
"secretsmanager:GetSecretValue",
]
principals = {
type = "AWS"
identifiers = [
"corporate-staff-rostering-${local.environment}",
"hmpps-oem-${local.environment}",
"nomis-${local.environment}",
"nomis-combined-reporting-${local.environment}",
"oasys-${local.environment}",
]
}
resources = [
"arn:aws:secretsmanager:*:*:secret:*"
]
}
oem_secretsmanager_secrets = {
policy = [
local.oem_secret_policy_read,
local.oem_secret_policy_write,
]
secrets = {
passwords = {}
}
}

oem_ec2_default = {

autoscaling_group = module.baseline_presets.ec2_autoscaling_group.default
Expand Down
2 changes: 1 addition & 1 deletion terraform/environments/hmpps-oem/locals_test.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ locals {
})
})
tags = merge(local.oem_ec2_default.tags, {
oracle-sids = "EMREP TRCVCAT"
oracle-sids = "EMREP TRCVCAT"
})
})
}
Expand Down
3 changes: 2 additions & 1 deletion terraform/environments/nomis/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ locals {
enable_ec2_cloud_watch_agent = true
enable_ec2_self_provision = true
enable_oracle_secure_web = true
enable_ec2_put_parameter = false
enable_ec2_get_parameter = false
enable_ec2_get_secret = false
cloudwatch_metric_alarms_default_actions = ["dso_pagerduty"]
route53_resolver_rules = {
outbound-data-and-private-subnets = ["azure-fixngo-domain"]
Expand Down
4 changes: 4 additions & 0 deletions terraform/modules/baseline/iam_policies.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ resource "aws_iam_policy" "this" {
tags = merge(local.tags, {
Name = each.key
})

lifecycle {
create_before_destroy = true
}
}
2 changes: 1 addition & 1 deletion terraform/modules/baseline/secretsmanager.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ data "aws_iam_policy_document" "secretsmanager_secret_policy" {
content {
effect = statement.value.effect
actions = statement.value.actions
resources = ["*"]
resources = statement.value.resources
dynamic "principals" {
for_each = statement.value.principals != null ? [statement.value.principals] : []
content {
Expand Down
5 changes: 3 additions & 2 deletions terraform/modules/baseline/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,9 @@ variable "secretsmanager_secrets" {
postfix = optional(string, "/")
kms_key_id = optional(string, "general")
policy = optional(list(object({
effect = string
actions = list(string)
effect = string
actions = list(string)
resources = list(string)
principals = optional(object({
type = string
identifiers = list(string)
Expand Down
51 changes: 49 additions & 2 deletions terraform/modules/baseline_presets/iam_policies.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ locals {
var.options.enable_ec2_cloud_watch_agent ? ["CloudWatchAgentServerReducedPolicy"] : [],
var.options.enable_ec2_self_provision ? ["Ec2SelfProvisionPolicy"] : [],
var.options.enable_shared_s3 ? ["Ec2AccessSharedS3Policy"] : [],
var.options.enable_ec2_get_parameter ? ["Ec2GetParameterPolicy"] : [],
var.options.enable_ec2_get_secret ? ["Ec2GetSecretPolicy"] : [],
var.options.enable_ec2_put_parameter ? ["Ec2PutParameterPolicy"] : [],
var.options.enable_ec2_put_secret ? ["Ec2PutSecretPolicy"] : [],
var.options.enable_oracle_secure_web ? ["S3ListAllBucketsAndGetLocationPolicy"] : [],
var.options.iam_policies_filter,
])
Expand All @@ -16,7 +19,10 @@ locals {
var.options.enable_ec2_cloud_watch_agent ? ["CloudWatchAgentServerReducedPolicy"] : [],
var.options.enable_ec2_self_provision ? ["Ec2SelfProvisionPolicy"] : [],
var.options.enable_shared_s3 ? ["Ec2AccessSharedS3Policy"] : [],
var.options.enable_ec2_get_parameter ? ["Ec2GetParameterPolicy"] : [],
var.options.enable_ec2_get_secret ? ["Ec2GetSecretPolicy"] : [],
var.options.enable_ec2_put_parameter ? ["Ec2PutParameterPolicy"] : [],
var.options.enable_ec2_put_secret ? ["Ec2PutSecretPolicy"] : [],
var.options.enable_oracle_secure_web ? ["S3ListAllBucketsAndGetLocationPolicy"] : [],
var.options.iam_policies_ec2_default,
])
Expand Down Expand Up @@ -144,15 +150,56 @@ locals {
])
}]
}
Ec2GetParameterPolicy = {
# Not required if AmazonSSMManagedInstanceCore is being used
description = "Permissions to allow EC2 to get SSM parameter(s)"
statements = [{
effect = "Allow"
actions = [
"ssm:GetParameter",
"ssm:GetParameters",
]
resources = [
"arn:aws:ssm:*:*:parameter:/*",
"arn:aws:ssm:*:*:parameter:cloud-watch-config-windows",
"arn:aws:ssm:*:*:parameter:modernisation_platform_account_id",
]
}]
}
Ec2GetSecretPolicy = {
# This doesn't seem to be required. EC2s can access secrets without
description = "Permissions to allow EC2 to get SecretManager Secrets"
statements = [{
effect = "Allow"
actions = [
"secretsmanager:GetSecret",
]
resources = ["arn:aws:secretsmanager:*:*:secret:/*"]
}]
}
Ec2PutParameterPolicy = {
description = "Permissions to allow EC2 to put parameter(s) for retrieval"
statements = [{
effect = "Allow"
actions = [
"ssm:PutParameter",
"ssm:PutParameters"
"ssm:PutParameters",
]
resources = ["arn:aws:ssm:*:*:parameter:/*"]
}]
}
Ec2PutSecretPolicy = {
description = "Permissions to allow EC2 to put SecretManager Secrets"
statements = [{
effect = "Allow"
actions = [
"secretsmanager:DeleteResourcePolicy",
"secretsmanager:DescribeSecret",
"secretsmanager:GetResourcePolicy",
"secretsmanager:PutResourcePolicy",
"secretsmanager:UpdateSecret",
]
resources = ["arn:aws:ssm:*:*:parameter/*"]
resources = ["arn:aws:secretsmanager:*:*:secret:/*"]
}]
}

Expand Down
3 changes: 3 additions & 0 deletions terraform/modules/baseline_presets/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ variable "options" {
enable_image_builder = optional(bool, false)
enable_ec2_cloud_watch_agent = optional(bool, false)
enable_ec2_self_provision = optional(bool, false)
enable_ec2_get_parameter = optional(bool, false)
enable_ec2_get_secret = optional(bool, false)
enable_ec2_put_parameter = optional(bool, false)
enable_ec2_put_secret = optional(bool, false)
enable_shared_s3 = optional(bool, false)
enable_oracle_secure_web = optional(bool, false)
db_backup_s3 = optional(bool, false)
Expand Down