Sub topic 5
Authenticating to the provider
This chapter assumes you can read a SecretStore manifest (previous chapter) and know what a ServiceAccount is. The examples use AWS Secrets Manager on EKS, but the same ideas apply to other providers.
What authentication has to solve
A SecretStore tells the operator where the secrets live. It does not prove that the operator may read them. The provider (here AWS) must identify the caller and check its permissions. If you put an access key in the manifest, you have recreated the problem this tutorial started with, a long-lived credential that sits in Git or in a Secret.
Authentication options
| Method | Credential in the cluster | Typical use |
|---|---|---|
| Web identity (`jwt`) | None. A short-lived ServiceAccount token is exchanged for cloud credentials | EKS with IRSA |
| Static keys (`secretRef`) | An access key stored in a Kubernetes Secret | Local clusters, tests |
| Controller identity | None in the store. The ESO Pod's own role is used | Single-tenant clusters |
Prefer the first option whenever the platform supports it.
How web identity works
With jwt authentication, ESO asks Kubernetes for a token for the ServiceAccount named in the store. It presents the token to AWS STS. AWS checks the token against the cluster's OIDC provider and returns temporary credentials for the IAM role linked to that ServiceAccount.
Configuring it
First, create the ServiceAccount and annotate it with the IAM role. The role's trust policy must allow your cluster's OIDC provider and this ServiceAccount as the subject.
apiVersion: v1
kind: ServiceAccount
metadata:
name: eso-reader
namespace: app
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::111122223333:role/eso-readerSecond, give the role only the permissions it needs.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret"
],
"Resource": "arn:aws:secretsmanager:eu-west-1:111122223333:secret:prod/db-*"
}
]
}The trailing -* is needed because AWS appends a random suffix to every secret ARN.
Third, reference the ServiceAccount from the store.
apiVersion: external-secrets.io/v1
kind: SecretStore
metadata:
name: aws-store
namespace: app
spec:
provider:
aws:
service: SecretsManager
region: eu-west-1
auth:
jwt:
serviceAccountRef:
name: eso-readerA namespaced SecretStore looks for the ServiceAccount in its own namespace. Older ESO releases use external-secrets.io/v1beta1.
Common errors
- The store reports
InvalidProviderConfigor a permissions error. Check that the role annotation is on the ServiceAccount the store names, not on the ESO controller's ServiceAccount. AccessDeniedfrom STS. The role's trust policy has the wrong OIDC provider, namespace, or ServiceAccount name in itssubcondition.AccessDeniedonGetSecretValue. The policy's resource ARN is missing the-*suffix, or it names the wrong region.- Works in one namespace only. A namespaced SecretStore cannot see ServiceAccounts in other namespaces. The ClusterSecretStore chapter covers sharing.
Exercise
Why is jwt authentication through a ServiceAccount safer than putting an AWS access key in a Kubernetes Secret that the SecretStore references?
Show answer
No long-lived credential exists in the cluster or in Git. ESO exchanges a short-lived ServiceAccount token for temporary AWS credentials, so there is no static key to leak, rotate, or commit. Access is also limited to the IAM role bound to that one ServiceAccount.