@@ -6,41 +6,131 @@ description: Add a private Amazon ECR to Coder.
6
6
This article will show you how to add your private ECR to Coder. If you're using
7
7
a public ECR registry, you do not need to follow the steps below.
8
8
9
- Amazon requires users to [ request temporary login credentials to access a
10
- private Elastic Container Registry (ECR )
11
- registry ] ( https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry_auth.html ) .
12
- When interacting with ECR, Coder will request temporary credentials from the
13
- registry using the AWS credentials linked to the registry.
9
+ Amazon requires users to
10
+ [ request temporary login credentials ] ( https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry_auth.html )
11
+ to access a private Elastic Container Registry (ECR) registry. When interacting
12
+ with ECR, Coder will request temporary credentials from the registry using the
13
+ AWS credentials linked to the registry.
14
14
15
- ## Step 1: Setting up your AWS credentials
15
+ ## Step 1: Setting up authentication for Coder
16
16
17
- To access a private ECR registry, Coder needs AWS credentials (specifically your
18
- ** access key ID** and ** secret access key** ) with authorization to access the
19
- provided registry. You can either use AWS credentials tied to your own AWS
20
- account * or* credentials tied to an IAM user specifically for Coder (we
21
- recommend the latter option).
17
+ To access a private ECR registry, Coder needs to authenticate with AWS. Coder
18
+ supports two methods of authentication with AWS ECR:
22
19
23
- Note that you are not limited to providing one single set of AWS credentials.
24
- For example, you can use a set of credentials with access to all of your ECR
25
- repositories, or you can use individual sets of credentials, each with access to
26
- a single repository.
20
+ - Static credentials
21
+ - ** Alpha:** IAM roles for service accounts
27
22
28
- To provision AWS credentials for Coder:
23
+ ### Option A: Provision static credentials for Coder
29
24
30
- 1 . ** Optional:** [ Create an IAM user for
31
- Coder] ( https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html )
25
+ You can use an ** Access Key ID** and ** Secret Access Key** tied to either your
26
+ own AWS account _ or_ credentials tied to a dedicated IAM user (we recommend the
27
+ latter option).
28
+
29
+ > You are not limited to providing a single set of AWS credentials. For example,
30
+ > you can use a set of credentials with access to all of your ECR repositories,
31
+ > or you can use individual sets of credentials, each with access to a single
32
+ > repository.
33
+
34
+ To provision static credentials for Coder:
35
+
36
+ 1 . ** Optional:**
37
+ [ Create an IAM user for Coder] ( https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html )
32
38
to access ECR. You can either attach the AWS-managed policy
33
- ` AmazonEC2ContainerRegistryReadOnly ` to the user, or you can [ create your
34
- own] ( https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-policy-examples.html ) .
39
+ ` AmazonEC2ContainerRegistryReadOnly ` to the user, or you can
40
+ [ create your own] ( https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-policy-examples.html ) .
35
41
36
- 1 . [ Create an access
37
- key] ( https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html )
42
+ 1 . [ Create an access key] ( https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html )
38
43
for the IAM user to be used with Coder (if one does not already exist).
39
44
45
+ ### Option B: Link an AWS IAM role to the Coder Kubernetes service account (IRSA)
46
+
47
+ ** Note:** This is currently an ** alpha** feature.
48
+
49
+ Coder can use an
50
+ [ IAM role linked to Coder's Kubernetes service account] ( https://aws.amazon.com/blogs/opensource/introducing-fine-grained-iam-roles-service-accounts/ ) ,
51
+ though this is only supported when Coder is running in AWS EKS. This is because
52
+ the
53
+ [ EKS Pod Identity Webhook] ( https://github.com/aws/amazon-eks-pod-identity-webhook/ )
54
+ is required to provision and inject the required token into the ` coderd ` pod.
55
+
56
+ > For more information on IAM Roles for Service Accounts (IRSA), please consult
57
+ > the
58
+ > [ AWS Documentation] ( https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html ) .
59
+
60
+ To link an IAM role to Coder's Kubernetes service account:
61
+
62
+ 1 . Enable the feature under Manage > Admin > Infrastructure > ECR IAM Role
63
+ Authentication.
64
+
65
+ 1 . Create an IAM OIDC Provider for your EKS cluster (if it does not already
66
+ exist).
67
+
68
+ 1 . [ Create the IAM role] ( https://docs.aws.amazon.com/eks/latest/userguide/create-service-account-iam-policy-and-role.html#create-service-account-iam-role )
69
+ to be used by Coder, if it does not already exist.
70
+
71
+ ** Note:** Ensure that you also create and attach a trust policy that permits
72
+ the Coder service account the action ` sts:AssumeRoleWithWebIdentity ` . The
73
+ trust policy will look similar to the following:
74
+
75
+ ``` json
76
+ {
77
+ "Version" : " 2012-10-17" ,
78
+ "Statement" : [
79
+ {
80
+ "Effect" : " Allow" ,
81
+ "Principal" : {
82
+ "Federated" : " arn:aws:iam::${ACCT_ID}:oidc-provider/${OIDC_PROVIDER}"
83
+ },
84
+ "Action" : " sts:AssumeRoleWithWebIdentity" ,
85
+ "Condition" : {
86
+ "StringEquals" : {
87
+ "${OIDC_PROVIDER}:sub" : " system:serviceaccount:${NAMESPACE}:${SERVICE_ACCOUNT}"
88
+ }
89
+ }
90
+ }
91
+ ]
92
+ }
93
+ ```
94
+
95
+ 1 . Annotate the Coder service account with the role ARN:
96
+
97
+ a) Add the following to your ` values.yaml ` for your Coder helm deployment:
98
+
99
+ ``` yaml
100
+ coderd :
101
+ ...
102
+ builtinProviderServiceAccount :
103
+ ...
104
+ annotations :
105
+ eks.amazonaws.com/role-arn : my-role-arn
106
+ ` ` `
107
+
108
+ b) Update the Helm deployment:
109
+
110
+ ` ` ` shell
111
+ helm upgrade coder coder/coder --values values.yaml
112
+ ```
113
+
114
+ c) Verify that the Coder service account now has the correct annotation:
115
+
116
+ ``` shell
117
+ kubectl get serviceaccount coder -o yaml | grep eks.amazonaws.com/role-arn
118
+ eks.amazonaws.com/role-arn: my-role-arn
119
+ ```
120
+
121
+ 1 . Validate that pods created with the ` coder ` service account have permission
122
+ to assume the role:
123
+
124
+ ``` shell
125
+ kubectl run -it --rm awscli --image=amazon/aws-cli \
126
+ --overrides=' {"spec":{"serviceAccount":"coder"}}' \
127
+ --command aws ecr describe-repositories
128
+ ```
129
+
40
130
## Step 2: Add your private ECR registry to Coder
41
131
42
- You can add your private ECR registry at the same time that you [ add your
43
- images] ( ../../images/index.md ) . To import an image:
132
+ You can add your private ECR registry at the same time that you
133
+ [ add your images] ( ../../images/index.md ) . To import an image:
44
134
45
135
1 . In Coder, go to ** Images** and click on ** Import Image** in the upper-right.
46
136
@@ -51,7 +141,9 @@ images](../../images/index.md). To import an image:
51
141
1 . Provide a ** registry name** and the ** registry** .
52
142
53
143
1 . Set the ** registry kind** to ** ECR** and provide your ** Access Key ID** and
54
- ** Secret Access Key** .
144
+ ** Secret Access Key** , if required. If you want to use IRSA instead of static
145
+ credentials, to authenticate with ECR, leave ** Access Key ID** and ** Secret
146
+ Access Key** blank.
55
147
56
148
1 . Continue with the process of [ adding your image] ( ../../images/index.md ) .
57
149
0 commit comments