Skip to content

Commit 71a5849

Browse files
committed
create irsa policy granting access to secrets
1 parent ab9d03d commit 71a5849

3 files changed

Lines changed: 57 additions & 6 deletions

File tree

core-env/eks-clusters/main.tf

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module "vpc" {
44

55
name = "${var.primary_cluster_name}-vpc"
66
cidr = "10.0.0.0/16"
7-
azs = formatlist("${data.aws_region.current.name}%s", ["a", "b"])
7+
azs = formatlist("${data.aws_region.current.region}%s", ["a", "b"])
88
#private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
99
public_subnets = ["10.0.4.0/24", "10.0.5.0/24"]
1010
#public_subnet_assign_
@@ -73,9 +73,14 @@ module "eks" {
7373
}
7474

7575
iam_role_attach_cni_policy = true
76+
#iam_role_use_name_prefix = false
77+
iam_role_additional_policies = {
78+
secrets = aws_iam_policy.irsa_policy_eso.arn
79+
}
80+
}
81+
7682

7783

78-
}
7984
}
8085
# Allow kubectl access via AWS SSO credentials
8186
access_entries = {
@@ -212,7 +217,23 @@ resource "aws_route53_record" "records" {
212217
#. TODO: use `output "secrets_policy_name"` to attach to the OIDC role created by irsa=true above.
213218
#
214219

215-
resource "aws_iam_role_policy_attachment" "s3_read_only" {
216-
role = eks.module.oidc_provider_arn
217-
policy_arn = data.terraform_remote_state.arad_aws_state.outputs.secrets_policy_arn
218-
}
220+
resource "aws_iam_policy" "irsa_policy_eso" {
221+
name = "${var.primary_cluster_name}-irsa-policy-external-secrets"
222+
223+
description = "Policy allowing ServiceAccount access to ESO."
224+
225+
policy = templatefile(
226+
"${path.module}/templates/secrets_policy.json.tpl",
227+
{
228+
AWS_ACCOUNT_ID = data.aws_caller_identity.current.id,
229+
}
230+
)
231+
232+
tags = var.common_tags
233+
234+
}
235+
236+
# resource "aws_iam_role_policy_attachment" "s3_read_only" {
237+
# role = module.eks.oidc_provider_arn
238+
# policy_arn = data.terraform_remote_state.arad_aws_state.outputs.secrets_policy_arn
239+
# }

core-env/eks-clusters/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ output "demo_domain" {
1313

1414
output "root_zone_id" {
1515
value = data.aws_route53_zone.root_demo_domain_zone.id
16+
}
17+
18+
output "irsa_role_arn" {
19+
# needed by SA setup by platform team
20+
value = module.eks.eks_managed_node_groups.default.iam_role_arn
1621
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Action" : [
6+
"secretsmanager:ListSecrets",
7+
"secretsmanager:BatchGetSecretValue"
8+
],
9+
"Effect" : "Allow",
10+
"Resource" : "*"
11+
},
12+
{
13+
"Effect": "Allow",
14+
"Action": [
15+
"secretsmanager:GetResourcePolicy",
16+
"secretsmanager:GetSecretValue",
17+
"secretsmanager:DescribeSecret",
18+
"secretsmanager:ListSecretVersionIds"
19+
],
20+
"Resource": [
21+
"arn:aws:secretsmanager:us-west-2:${AWS_ACCOUNT_ID}:secret:kargo-*"
22+
]
23+
}
24+
]
25+
}

0 commit comments

Comments
 (0)