Skip to content

Commit be45f0c

Browse files
authored
Issue146 OIDC plan april (#154)
* Separate Terraform plan and apply roles for incubator * Applying recommended role detail changes for plan and apply * Removed Pull Request condition from incubator_tf_apply * new TF Plan read policy for secrets manager and fixed lines * Executed feedback: generalized custom policy .json and home-unite-us secrets * Previous push rejected for deprecated aws resource. Fixed, and aligned cross-reference. * Add DynamoDB TF Plan policy entries
1 parent 12f3552 commit be45f0c

4 files changed

Lines changed: 64 additions & 5 deletions

File tree

terraform/aws-custom-policies.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ module "aws_custom_policies" {
99
description = "Policy enforcing MFA for devops security users"
1010
filename = "enforce-mfa-for-users-policy.json"
1111
}
12+
"IncubatorTfPlanSecretsRead" = {
13+
description = "Allows incubator tf plan role to read specific Secrets Manager secrets needed for terraform plan"
14+
filename = "tf-plan-scoped.json"
15+
}
1216
}
1317
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Sid": "AllowReadSpecificSecretsForTerraformPlan",
6+
"Effect": "Allow",
7+
"Action": [
8+
"secretsmanager:GetSecretValue"
9+
],
10+
"Resource": [
11+
"arn:aws:secretsmanager:us-west-2:035866691871:secret:*"
12+
]
13+
},
14+
{
15+
"Sid": "AllowS3BackendAccessForTerraformPlan",
16+
"Effect": "Allow",
17+
"Action": [
18+
"s3:GetObject",
19+
"s3:PutObject",
20+
"s3:DeleteObject",
21+
"s3:ListBucket",
22+
"s3:GetBucketLocation"
23+
],
24+
"Resource": [
25+
"arn:aws:s3:::hfla-ops-terraform-state",
26+
"arn:aws:s3:::hfla-ops-terraform-state/*"
27+
]
28+
},
29+
{
30+
"Sid": "AllowDynamoDBLockTableAccessForTerraformPlan",
31+
"Effect": "Allow",
32+
"Action": [
33+
"dynamodb:PutItem",
34+
"dynamodb:DeleteItem",
35+
"dynamodb:GetItem",
36+
"dynamodb:UpdateItem",
37+
"dynamodb:DescribeTable"
38+
],
39+
"Resource": [
40+
"arn:aws:dynamodb:us-west-2:035866691871:table/hfla_ops_terraform_table"
41+
]
42+
}
43+
]
44+
}
45+

terraform/aws-gha-oidc-providers.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ resource "aws_iam_role" "incubator_tf_plan" {
4040
}
4141

4242
resource "aws_iam_role_policy_attachment" "incubator_tf_plan_readonly" {
43-
role = aws_iam_role.incubator_tf_plan.name
43+
role = aws_iam_role.incubator_tf_plan.name
4444
policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess"
4545
}
4646

47+
resource "aws_iam_role_policy_attachment" "incubator_tf_plan_secrets_read" {
48+
role = aws_iam_role.incubator_tf_plan.name
49+
policy_arn = module.aws_custom_policies.policy_arns["IncubatorTfPlanSecretsRead"]
50+
}
51+
4752
resource "aws_iam_role" "incubator_tf_apply" {
4853
name = "incubator-tf-apply"
49-
5054
assume_role_policy = jsonencode({
5155
Version = "2012-10-17"
5256
Statement = [

terraform/modules/aws-gha-oidc-providers/main.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ resource "aws_iam_openid_connect_provider" "github_actions" {
5050

5151
resource "aws_iam_role" "github_actions_oidc" {
5252

53-
name = var.role_name
54-
managed_policy_arns = var.policy_arns
53+
name = var.role_name
5554

5655
assume_role_policy = jsonencode({
5756
"Version" : "2012-10-17",
@@ -71,4 +70,11 @@ resource "aws_iam_role" "github_actions_oidc" {
7170
}
7271
}]
7372
})
74-
}
73+
}
74+
75+
resource "aws_iam_role_policy_attachment" "github_actions_oidc" {
76+
for_each = toset(var.policy_arns)
77+
78+
role = aws_iam_role.github_actions_oidc.name
79+
policy_arn = each.value
80+
}

0 commit comments

Comments
 (0)