Skip to content

Commit 2de18bb

Browse files
Adam Talbotinteon
authored andcommitted
feat: document new IRSA capabilities
Signed-off-by: Adam Talbot <[email protected]>
1 parent 161ef17 commit 2de18bb

File tree

2 files changed

+130
-4
lines changed

2 files changed

+130
-4
lines changed

.spelling

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ Ramlot
253253
RinkiyaKeDad
254254
Robusta
255255
Route53
256+
API_AssumeRoleWithWebIdentity
256257
Runtime
257258
roadmap
258259
SGX

content/docs/configuration/acme/dns01/route53.md

Lines changed: 129 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,18 @@ Note that, as mentioned above, the pod is using `arn:aws:iam::XXXXXXXXXXX:role/c
188188

189189
While [`kiam`](https://github.com/uswitch/kiam) / [`kube2iam`](https://github.com/jtblin/kube2iam) work directly with cert-manager, some special attention is needed for using the [IAM Roles for Service Accounts](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html) feature available on EKS.
190190

191-
### OIDC provider
191+
This feature uses Kubernetes `ServiceAccount` tokens to authenticate with AWS using the [API_AssumeRoleWithWebIdentity](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithWebIdentity.html).
192192

193-
First follow the AWS documentation [Enabling IAM roles for service accounts on your cluster](https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html) to ensure that the OIDC provider for the EKS cluster is enabled. The OIDC information is needed to create the trust relationship for the cert-manager role below.
193+
> **Note**: For using IRSA with cert-manager you must first enable the feature for your cluster. You can do this by
194+
> following the [official documentation(https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html).
194195

195-
### IAM role trust policy
196+
Because `ServiceAccount` tokens are used to authenticate there are two modes of operation, you can either use cert-manager's own `ServiceAccount` to authenticate or you can reference your own `ServiceAccount` within your `Issuer`/`ClusterIssuer` config. Each option is described below.
197+
198+
### Using the cert-manager ServiceAccount
199+
200+
In this configuration an IAM role is mapped to the cert-manager `ServiceAccount` allowing it to authenticate with AWS. The IAM role you map to the `ServiceAccount` will need permissions on any and all Route53 zones cert-manager will be using.
201+
202+
#### IAM role trust policy
196203

197204
The cert-manager role needs the following trust relationship attached to the role in order to use the IRSA method. Replace the following:
198205

@@ -224,7 +231,7 @@ The cert-manager role needs the following trust relationship attached to the rol
224231

225232
**Note:** If you're following the Cross Account example above, this trust policy is attached to the cert-manager role in Account X with ARN `arn:aws:iam::XXXXXXXXXXX:role/cert-manager`. The permissions policy is the same as above.
226233

227-
### Service annotation
234+
#### Service annotation
228235

229236
Annotate the `ServiceAccount` created by cert-manager:
230237

@@ -257,3 +264,121 @@ securityContext:
257264
```
258265

259266
**Note:** If you're following the Cross Account example above, modify the `ClusterIssuer` in the same way as above with the role from Account Y.
267+
268+
### Referencing your own ServiceAccount within Issuer/ClusterIssuer config
269+
270+
In this configuration you can reference your own `ServiceAccounts` within your `Issuer`/`ClusterIssuer` and cert-manager will issue itself temporary credentials using these `ServiceAccounts`. Because each issuer can reference a different `ServiceAccount` you can lock down permissions much more, with each `ServiceAccount` mapped to an IAM role that only has permission on the zones it needs for that particular issuer.
271+
272+
273+
#### Creating a ServiceAccount
274+
275+
In order to reference a `ServiceAccount` it must first exist. Unlike normal IRSA the `eks.amazonaws.com/role-arn` annotation is not required, however you may wish to set it as a reference.
276+
277+
```yaml
278+
apiVersion: v1
279+
kind: ServiceAccount
280+
metadata:
281+
name: <service-account-name>
282+
annotation:
283+
eks.amazonaws.com/role-arn: <iam-role-arn>
284+
```
285+
286+
#### IAM role trust policy
287+
288+
For every `ServiceAccount` you want to use for AWS authentication you must first set up a trust policy. Replace the following:
289+
290+
- `<aws-account-id>` with the AWS account ID of the EKS cluster.
291+
- `<aws-region>` with the region where the EKS cluster is located.
292+
- `<eks-hash>` with the hash in the EKS API URL; this will be a random 32 character hex string (example: `45DABD88EEE3A227AF0FA468BE4EF0B5`)
293+
- `<namespace>` with the namespace of the `ServiceAccount` object.
294+
- `<service-account-name>` with the name of the `ServiceAccount` object.
295+
296+
```json
297+
{
298+
"Version": "2012-10-17",
299+
"Statement": [
300+
{
301+
"Effect": "Allow",
302+
"Action": "sts:AssumeRoleWithWebIdentity",
303+
"Principal": {
304+
"Federated": "arn:aws:iam::<aws-account-id>:oidc-provider/oidc.eks.<aws-region>.amazonaws.com/id/<eks-hash>"
305+
},
306+
"Condition": {
307+
"StringEquals": {
308+
"oidc.eks.<aws-region>.amazonaws.com/id/<eks-hash>:sub": "system:serviceaccount:<namespace>:<service-account-name>"
309+
}
310+
}
311+
}
312+
]
313+
}
314+
```
315+
316+
**Note:** If you're following the Cross Account example above, this trust policy is attached to the cert-manager role in Account X with ARN `arn:aws:iam::XXXXXXXXXXX:role/cert-manager`. The permissions policy is the same as above.
317+
318+
#### RBAC
319+
320+
In order to allow cert-manager to issue a token using your `ServiceAccount` you must deploy some RBAC to the cluster. Replace the following:
321+
322+
- `<service-account-name>` name of the `ServiceAccount` object.
323+
- `<service-account-namespace>` namespace of the `ServiceAccount` object.
324+
- `<cert-manager-service-account-name>` name of cert-managers `ServiceAccount` object, as created during cert-manager installation.
325+
- `<cert-manager-namespace>` namespace that cert-manager is deployed into.
326+
327+
```yaml
328+
apiVersion: rbac.authorization.k8s.io/v1
329+
kind: Role
330+
metadata:
331+
name: <service-account-name>-tokenrequest
332+
namespace: <service-account-namespace>
333+
rules:
334+
- apiGroups: ['']
335+
resources: ['serviceaccounts/token']
336+
resourceNames: ['<service-account-name>']
337+
verbs: ['create']
338+
---
339+
apiVersion: rbac.authorization.k8s.io/v1
340+
kind: RoleBinding
341+
metadata:
342+
name: cert-manager-<service-account-name>-tokenrequest
343+
namespace: <service-account-namespace>
344+
subjects:
345+
- kind: ServiceAccount
346+
name: <cert-manager-service-account-name>
347+
namespace: <cert-manager-namespace>
348+
roleRef:
349+
apiGroup: rbac.authorization.k8s.io
350+
kind: Role
351+
name: <service-account-name>-tokenrequest
352+
```
353+
354+
#### Issuer/ClusterIssuer config
355+
356+
Once you have completed the above you should have:
357+
- An IAM role with permissions required to on the Route53 zone.
358+
- A Kubernetes `ServiceAccount`.
359+
- A trust policy to allow the Kubernetes `ServiceAccount` access to your IAM role.
360+
- RBAC to allow cert-manager to issue a token using the Kubernetes `ServiceAccount`.
361+
362+
You should be ready at this point to configure an Issuer to use the new `ServiceAccount`. You can see example config for this below:
363+
364+
```yaml
365+
apiVersion: cert-manager.io/v1
366+
kind: Issuer
367+
metadata:
368+
name: example
369+
spec:
370+
acme:
371+
...
372+
solvers:
373+
- selector:
374+
dnsZones:
375+
- "example.com"
376+
dns01:
377+
route53:
378+
region: us-east-1
379+
role: <iam-role-arn> # This must be set so cert-manager what role to attempt to authenticate with
380+
auth:
381+
kubernetes:
382+
serviceAccountRef:
383+
name: <service-account-name> # The name of the service account created
384+
```

0 commit comments

Comments
 (0)