In this GitHub repository, we will provide step by step guidance to deploy a Amazon CloudFormation (CFN) template to automatically create all the resources and settings required to enable KMS encryption on Amazon Elastic Container Registry (ECR) with cross-region or cross-account replication.
For Cross-Region replication, but within same account, please follow steps below for deploying the Cloudformation into your AWS account:
- Clone this Git repository to your local machine (if you haven't already done)
- Navigate to the
cross-region-same-account/primary-region
folder on this repo - Open the AWS Console on the primary account and region (i.e us-east-1)
- Choose
Create stack
- Under
Specify Template
, do the following:- Choose
Upload a template file
- Rhen choose
Choose file
- Navigate to the folder on your local machine where you cloned this repository
- Select the
primary-region-template.yaml
file
- Choose
- Choose
Next
- Under
Stack Name
enter a name for your stack (i.e. "Primary ECR Repo") - Under
Parameters
do the following:- For
ECRDestiationRegion
enter the AWS region you'd like ECR to replicate your images. This will also be the region where you'll run the second CloudFormation Tempalte. - For
ECRRepositoryName
, enter the name of the ECR repository. The name must start with a letter and can only contain lowercase letters, numbers, hyphens, underscores, periods and forward slashes - For
KMSKeyAdmin
enter the IAM Principal ARN that you'd like to be the KMS Admin - For
KMSKeyUser
enter the IAM Principal ARN that you'd like to consume the KMS key (i.e. push/pull images from ECR)
- For
- Choose
Next
- Choose
Next
again - Finally, choose
Submit
- Your CloudFormation template will deploy all the required resources for your primary region
Now, it is very important that before we push any images to our ECR repository that we create the ECR repository in our secondary region.
Do NOT push an image to your primary repository before following steps below. If you push an image to the primary ECR repository region without creating the ECR repository destination, the ECR destination repository will NOT have KMS encyrption)
- Clone this Git repository to your local machine (if you haven't already done)
- Navigate to the
cross-region-same-account/secondary-regions
folder on this repo - Open the AWS Console on the primary account and region (i.e us-east-1)
- Choose
Create stack
- Under
Specify Template
, do the following:- Choose
Upload a template file
- Rhen choose
Choose file
- Navigate to the folder on your local machine where you cloned this repository
- Select the
secondary-region-template.yaml
file
- Choose
- Choose
Next
- Under
Stack Name
enter a name for your stack (i.e. "Secondary Destination ECR Repo") - Under
Parameters
do the following:- For
ECRRepositoryName
, enter the name of the ECR repository. The name must start with a letter and can only contain lowercase letters, numbers, hyphens, underscores, periods and forward slashes The name MUST be exactly the same as your primary region, if they don't match, replication with KMS encryption will NOT work - For
KMSKeyAdmin
enter the IAM Principal ARN that you'd like to be the KMS Admin - For
KMSKeyUser
enter the IAM Principal ARN that you'd like to consume the KMS key (i.e. push/pull images from ECR)
- For
- Choose
Next
- Choose
Next
again - Finally, choose
Submit
- Your CloudFormation template will deploy all the required resources for your primary region
You can now test your ECR replication with KMS encryption enabled on both repositories. Just push a container image to the primary repository region (in this example us-east-1). After the image is pushed, you can navigate to the secondary ECR repository region (in this example us-west-2), and you will see the image automatically replicated and with KMS key encryption.
For Cross-Region and Cross-Account replication, please follow steps below for deploying the Cloudformation into your AWS account and in the primary account and region:
- Clone this Git repository to your local machine (if you haven't already done)
- Navigate to the
cross-region-cross-account/primary-account
folder on this repo - Open the AWS Console on the primary account and region (i.e us-east-1)
- Choose
Create stack
- Under
Specify Template
, do the following:- Choose
Upload a template file
- Rhen choose
Choose file
- Navigate to the folder on your local machine where you cloned this repository
- Select the
primary-region-cross-account-template.yaml
file
- Choose
- Choose
Next
- Under
Stack Name
enter a name for your stack (i.e. "Primary ECR Repo") - Under
Parameters
do the following:- For
ECRDestiationRegion
enter the AWS region you'd like ECR to replicate your images. This will also be the region where you'll run the second CloudFormation Tempalte. - For
ECRRepositoryName
, enter the name of the ECR repository. The name must start with a letter and can only contain lowercase letters, numbers, hyphens, underscores, periods and forward slashes - For
KMSKeyAdmin
enter the IAM Principal ARN that you'd like to be the KMS Admin - For
KMSKeyUser
enter the IAM Principal ARN that you'd like to consume the KMS key (i.e. push/pull images from ECR) - For
DestinationAWSAccount
enter the AWS account that you would like ECR to replicate container images to
- For
- Choose
Next
- Choose
Next
again - Finally, choose
Submit
- Your CloudFormation template will deploy all the required resources for your primary region
For Cross-Region and Cross-Account replication, please follow steps below for deploying the Cloudformation into your AWS account and in the primary account and region:
Do NOT push an image to your primary repository before following steps below. If you push an image to the primary ECR repository region without creating the ECR repository destination, the ECR destination repository will NOT have KMS encyrption
- Clone this Git repository to your local machine (if you haven't already done)
- Navigate to the
cross-region-cross-account/secondary-accounts
folder on this repo - Open the AWS Console on the primary account and region (i.e us-east-1)
- Choose
Create stack
- Under
Specify Template
, do the following:- Choose
Upload a template file
- Rhen choose
Choose file
- Navigate to the folder on your local machine where you cloned this repository
- Select the
secondary-region-cross-account-template.yaml
file
- Choose
- Choose
Next
- Under
Stack Name
enter a name for your stack (i.e. "Secondary Destination ECR Repo") - Under
Parameters
do the following:- For
ECRRepositoryName
, enter the name of the ECR repository. The name must start with a letter and can only contain lowercase letters, numbers, hyphens, underscores, periods and forward slashe - For
KMSKeyAdmin
enter the IAM Principal ARN that you'd like to be the KMS Admin - For
KMSKeyUser
enter the IAM Principal ARN that you'd like to consume the KMS key (i.e. push/pull images from ECR) - For
ECRSourceAWSAccount
enter the AWS account that is the source/primary account for your ECR replication
- For
- Choose
Next
- Choose
Next
again - Finally, choose
Submit
- Your CloudFormation template will deploy all the required resources for your primary region
You can now test your ECR replication with KMS encryption cross-account and cross-region enabled on both repositories. Just push a container image to the primary repository region (in this example us-east-1) in the primary AWS account. After the image is pushed, you can navigate to the second AWS account in the secondary ECR repository region (in this example us-west-2), and you will see the image automatically replicated and with KMS key encryption.
Once you have deployed the CloudFormation resources and wish to delete from your accounts. Just navigate to the CloudFormation service on your AWS console, and then select the stack(s) that you'd like to remove and click on the Delete
button.
This library is licensed under the MIT-0 License. See the LICENSE file.