Private ECR Repositories
Last updated
Last updated
If you are a self-hosted user, Release automatically integrates with AWS Elastic Container Registry (ECR) and creates a private Docker image repository in your AWS account when you add an AWS integration.
The default ECR image repositories created by Release are private and images are only accessible by your AWS account and by our AWS IAM user. However, you may wish to deploy images from a different ECR repository, or even from an entirely different AWS account, to nodes in your Release environments.
In this guide, we'll add an ECR repository policy that allows Release's IAM user to pull Docker images from a private ECR repository in a different AWS account.
First, you'll need to find Release's AWS IAM user ID and cluster region under Account Settings > Clusters.
Note down your Release AWS IAM ID and your cluster's AWS region.
In the example below, we'll use two example AWS accounts, 111111111111
as Release's IAM user, and 222222222222
as an external AWS account from which we'll pull an image.
This abridged application template shows how you could use an image from AWS ECR for one of your services in Release:
By looking at the example image URL, you might notice that the image belongs to the AWS IAM user 222222222222
in the AWS region eu-west-2
.
For cross-account ECR access to work, the ECR repository must be in the same AWS region as your Release cluster. If your image repository is in a different region, you can use image replication in ECR to copy images from one AWS region to another.
To grant 111111111111
permissions to pull images from 222222222222
's ECR repository, 222222222222
should add an ECR repository policy by following the steps below.
Log in to AWS using IAM ID 222222222222
.
Navigate to Amazon Elastic Container Registry.
Click on Repositories in the sidebar.
Select the repository that contains the image you would like to use.
Click the Actions dropdown.
Click Permissions.
Click Edit policy JSON.
Paste the following JSON (change 111111111111
to Release's IAM user ID):
Click Save.
If AWS successfully validates your policy JSON, the permissions screen should look like this:
Now you can try to deploy your application again and Release's IAM user should have the required permissions to pull the image.
To allow the private registry to be used as a FROM
image in a Dockerfile built by Release, you'll also need to configure an ECR registry integration:
Navigate to Account Settings > Integrations
Click Setup under the AWS ECR private registry integration
Enter the ECR private registry hostname (e.g. 222222222222.dkr.ecr.eu-west-2.amazonaws.com
).
Choose the same cloud integration used in the policy above.
Click Save.
Now you can try to build your image again the release builder should have the required permissions to pull the base image.
As with any AWS IAM policy update, it is important to make sure you understand what a policy does before applying it to your resources. This means making sure that you apply the policy to the correct ECR repository, using the correct external IAM user ID, and allowing only the necessary actions.
For convenience, we've listed the Actions from our recommended policy, with links to relevant documentation:
BatchCheckLayerAvailability - Checks the availability of one or more image layers in a repository.
BatchGetImage - Gets detailed information for an image.
DescribeImages - Returns metadata about the images in a repository.
DescribeRepositories - Describes image repositories in a registry.
GetAuthorizationToken - Retrieves an authorization token.
GetDownloadUrlForLayer - Retrieves the pre-signed Amazon S3 download URL corresponding to an image layer.
GetRepositoryPolicy - Retrieves the repository policy for the specified repository.
ListImage - Lists all the image IDs for the specified repository.
We also recommend reading the AWS documentation about Private repository policies.