Skip to content

Commit 0a9d913

Browse files
authored
feat: Add pod identity note for ECR access (#6369)
* Add pod identity note for ECR access * Add tabs for TF and CLI samples * Fix up TAB syntax * Add triple === for content tabs
1 parent 3c6c38b commit 0a9d913

File tree

2 files changed

+120
-2
lines changed

2 files changed

+120
-2
lines changed

contribute-to-docs/getting-started/formatting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ within tabs. Indent the tab content by four spaces to make the tabs display prop
112112

113113
For example:
114114

115-
== "tab1 name"
115+
=== "tab1 name"
116116

117117
This is a stem:
118118

@@ -124,7 +124,7 @@ For example:
124124

125125
1. This is another step.
126126

127-
== "tab2 name"
127+
=== "tab2 name"
128128

129129
This is a stem:
130130

docs/versioned/install/operator/configuring-serving-cr.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,124 @@ spec:
257257
...
258258
```
259259

260+
### Connect to AWS ECR using Pod Identity
261+
262+
The use of AWS ECR as source of images for deployment using knative-serving requires access to digests for images. This can be obtained via a managed policy - `AmazonEC2ContainerRegistryReadOnly` which is attached to an IAM Role - `knative-serving-controller`. This role is then attached to the `controller` ServiceAccount in the `knative-serving` namespace. This will allow the controller pods to retrieve relevant digests for containers from ECR. Samples are provided below as AWS-CLI commands and Terraform module to perform the setup. Please adapt to the relevant IaC tooling your team uses.
263+
264+
=== "Terraform Example"
265+
266+
The terraform sample uses AWS Provider Terraform module to put all the pieces together.
267+
268+
```terraform
269+
module "pod_identity_knative" {
270+
source = "terraform-aws-modules/eks-pod-identity/aws"
271+
version = "~>"2.0.0"
272+
273+
name = "knative-serving-controller"
274+
275+
additional_policy_arns = {
276+
AmazonEC2ContainerRegistryReadOnly = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
277+
}
278+
279+
# Pod Identity Associations
280+
associations = {
281+
knative-serving-controller = {
282+
cluster_name = "some-cluster-name"
283+
namespace = "knative-serving"
284+
service_account = "controller"
285+
}
286+
}
287+
}
288+
```
289+
290+
=== "AWS CLI Example"
291+
292+
The AWS CLI sample uses a bash script to setup the relevant infrastructure
293+
294+
```bash
295+
# Set variables
296+
REGION="<region>"
297+
CLUSTER_NAME="<some-cluster-name>"
298+
ROLE_NAME="knative-serving-controller"
299+
NAMESPACE="knative-serving"
300+
SERVICE_ACCOUNT="controller"
301+
302+
ACCOUNT_ID="$(aws sts get-caller-identity --query 'Account' --output text)"
303+
PARTITION="$(aws sts get-caller-identity --query 'Arn' --output text | cut -d: -f2)"
304+
305+
# Create trust policy for EKS Pod Identity
306+
cat > trust-policy.json <<EOF
307+
{
308+
"Version": "2012-10-17",
309+
"Statement": [
310+
{
311+
"Sid": "EKSPodIdentityTrust",
312+
"Effect": "Allow",
313+
"Principal": { "Service": "pods.eks.amazonaws.com" },
314+
"Action": [ "sts:AssumeRole", "sts:TagSession" ],
315+
"Condition": {
316+
"StringEquals": { "aws:SourceAccount": "${ACCOUNT_ID}" },
317+
"StringLike": {
318+
"aws:SourceArn": "arn:${PARTITION}:eks:${REGION}:${ACCOUNT_ID}:cluster/${CLUSTER_NAME}"
319+
}
320+
}
321+
}
322+
]
323+
}
324+
EOF
325+
326+
# Create IAM role and attach ECR read-only policy
327+
aws iam create-role \
328+
--role-name "${ROLE_NAME}" \
329+
--assume-role-policy-document file://trust-policy.json
330+
331+
aws iam attach-role-policy \
332+
--role-name "${ROLE_NAME}" \
333+
--policy-arn "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
334+
335+
ROLE_ARN="$(aws iam get-role --role-name "${ROLE_NAME}" --query 'Role.Arn' --output text)"
336+
echo "Created role: ${ROLE_ARN}"
337+
338+
# Ensure the EKS Pod Identity Agent add-on is installed
339+
aws eks create-addon \
340+
--region "${REGION}" \
341+
--cluster-name "${CLUSTER_NAME}" \
342+
--addon-name eks-pod-identity-agent \
343+
--resolve-conflicts OVERWRITE || true
344+
345+
# Associate the role with the Knative Serving controller ServiceAccount
346+
aws eks create-pod-identity-association \
347+
--region "${REGION}" \
348+
--cluster-name "${CLUSTER_NAME}" \
349+
--namespace "${NAMESPACE}" \
350+
--service-account "${SERVICE_ACCOUNT}" \
351+
--role-arn "${ROLE_ARN}"
352+
353+
# Optional: verify association
354+
aws eks list-pod-identity-associations \
355+
--region "${REGION}" \
356+
--cluster-name "${CLUSTER_NAME}" \
357+
--query "associations[?namespace=='${NAMESPACE}' && serviceAccount=='${SERVICE_ACCOUNT}']"
358+
359+
# Cleanup local file
360+
rm -f trust-policy.json
361+
```
362+
363+
Expected output is something like :
364+
```json
365+
{
366+
"associations": [
367+
{
368+
"clusterName": "<some-cluster-name>",
369+
"namespace": "knative-serving",
370+
"serviceAccount": "controller",
371+
"associationArn": "<ROLE-ARN>",
372+
"associationId": "<SOME-RANDOM-STRING>"
373+
},
374+
...
375+
}
376+
```
377+
260378
## SSL certificate for controller
261379

262380
To [enable tag to digest resolution](../../serving/tag-resolution.md), the Knative Serving controller needs to access the container registry.

0 commit comments

Comments
 (0)