-
Notifications
You must be signed in to change notification settings - Fork 25
/
external_secrets_iam.tf
45 lines (40 loc) · 1.9 KB
/
external_secrets_iam.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# IAM role and policy to enable the k8s external-secrets operator to talk to
# AWS APIs to access and manage SecretsManager secrets.
#
# The k8s side of the external-secrets operator is in
# ../cluster-services/external_secrets.tf.
locals {
external_secrets_service_account_name = "external-secrets"
}
module "external_secrets_iam_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
version = "~> 5.0"
create_role = true
role_name = "${local.external_secrets_service_account_name}-${var.cluster_name}"
role_description = "Role for External Secrets addon. Corresponds to ${local.external_secrets_service_account_name} k8s ServiceAccount."
provider_url = module.eks.oidc_provider
role_policy_arns = [aws_iam_policy.external_secrets.arn]
oidc_fully_qualified_subjects = ["system:serviceaccount:${local.cluster_services_namespace}:${local.external_secrets_service_account_name}"]
}
resource "aws_iam_policy" "external_secrets" {
name = "EKSExternalSecrets-${var.cluster_name}"
description = "EKS ${local.external_secrets_service_account_name} policy for cluster ${module.eks.cluster_name}"
policy = data.aws_iam_policy_document.external_secrets.json
}
# Policy as documented here:
# https://external-secrets.io/provider-aws-secrets-manager/#iam-policy
data "aws_iam_policy_document" "external_secrets" {
statement {
sid = "externalSecretsSecretsManager"
effect = "Allow"
actions = [
"secretsmanager:GetResourcePolicy",
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret",
"secretsmanager:ListSecretVersionIds"
]
resources = [
"arn:aws:secretsmanager:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:secret:${local.secrets_prefix}/*",
]
}
}