Skip to content

Commit 08b9741

Browse files
committed
working access to secrets manager
1 parent 71a5849 commit 08b9741

2 files changed

Lines changed: 40 additions & 17 deletions

File tree

core-env/eks-clusters/main.tf

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ 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-
}
8076
}
8177

8278

@@ -213,9 +209,10 @@ resource "aws_route53_record" "records" {
213209

214210

215211
#
216-
#
217-
#. TODO: use `output "secrets_policy_name"` to attach to the OIDC role created by irsa=true above.
218-
#
212+
# ESO - External Secrets Operator
213+
#. Creates a policy with access to secrets,
214+
#. a role granting assume permissions from cluster OIDC provider, and a policy attachment connecting them.
215+
#. Service Accounts must specify the role's ARN to gain access. See platform repo's /secrets path
219216

220217
resource "aws_iam_policy" "irsa_policy_eso" {
221218
name = "${var.primary_cluster_name}-irsa-policy-external-secrets"
@@ -233,7 +230,29 @@ resource "aws_iam_policy" "irsa_policy_eso" {
233230

234231
}
235232

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-
# }
233+
resource "aws_iam_role" "eks_service_account_role" {
234+
name = "${var.primary_cluster_name}-irsa-role-external-secrets"
235+
236+
assume_role_policy = jsonencode({
237+
Version = "2012-10-17"
238+
Statement = [
239+
{
240+
Effect = "Allow"
241+
Principal = {
242+
Federated = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/${replace(module.eks.cluster_oidc_issuer_url, "https://", "")}"
243+
}
244+
Action = "sts:AssumeRoleWithWebIdentity"
245+
# Condition = {
246+
# StringEquals = {
247+
# "${replace(module.eks.cluster_oidc_issuer_url, "https://", "")}:sub" = "system:serviceaccount:my-namespace:my-service-account"
248+
# }
249+
# }
250+
}
251+
]
252+
})
253+
}
254+
255+
resource "aws_iam_role_policy_attachment" "irsa_secrets" {
256+
role = aws_iam_role.eks_service_account_role.name
257+
policy_arn = aws_iam_policy.irsa_policy_eso.arn
258+
}

core-env/eks-clusters/outputs.tf

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
output "primary_cluster_name" {
2-
value = module.eks.cluster_name
2+
value = module.eks.cluster_name
33
}
44
output "primary_cluster_endpoint" {
5-
value = module.eks.cluster_endpoint
5+
value = module.eks.cluster_endpoint
66
}
77
output "primary_cluster_ca" {
8-
value = module.eks.cluster_certificate_authority_data
8+
value = module.eks.cluster_certificate_authority_data
99
}
1010
output "demo_domain" {
11-
value = var.root_domain_name
11+
value = var.root_domain_name
1212
}
1313

1414
output "root_zone_id" {
15-
value = data.aws_route53_zone.root_demo_domain_zone.id
15+
value = data.aws_route53_zone.root_demo_domain_zone.id
1616
}
1717

1818
output "irsa_role_arn" {
19-
# needed by SA setup by platform team
19+
# needed by SA setup by platform team
2020
value = module.eks.eks_managed_node_groups.default.iam_role_arn
21+
}
22+
23+
output "secrets_sa_role" {
24+
value = aws_iam_role.eks_service_account_role.arn
2125
}

0 commit comments

Comments
 (0)