This demo sets up demo environment for AWS private ECR. Setting up this demo is provisioned by Terraform. In terraform,
- Create VPC (along with IGW, NAT, Subnets, etc)
- Create ECR
- Create sample container image using Docker
- Push the docker image to ECR
- Create ECS cluster
- Run Snyk broker container on Fargate
- Run Snyk Container Registry Agent on Fargate
When terraform successfully provisions, you should have AWS infra as below.
-
Terraform
brew tap hashicorp/tap brew install hashicorp/tap/terraform
Reference: Install Terraform
-
Docker
-
Snyk Broker Token for ECR
-
AWS credentials
git clone https://github.com/masa-snyk/broker_private_ecr.git
or
git clone [email protected]:masa-snyk/broker_private_ecr.git
In your teminal
export AWS_ACCESS_KEY_ID=<access key>
export AWS_SECRET_ACCESS_KEY=<secret_key>
export AWS_DEFAULT_REGION=<aws region>
Note: Never write your credentials in terraform config or use it as terraform variables. It will show up in your terraform state file, which might accicentally pushed to public repos.
Rename terraform.tfvars.example
to terraform.tfvars
.
mv terraform.tfvars.example terraform.tfvars
Modify the contents
prefix = "<replace this with your name>"
broker_token = "<replace this with your broker token>"
prefix
-> Your name or whateverprefix
is prepended to all of your resources, so it won't conflict with others in same AWS region.
broker_token
- Broker token obtained from Snyk UI
terraform init
terraform plan
terraform apply -auto-apply
Now you should have your infrastructure on AWS with ECR, ECS, Broker, agent all set up.
If you go to Snyk's integration page, you should now see the your private private ECR Repo.
Now ECR, broker, CRA are all set up.
Push your favorite container images, and start scanning!
https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html
Don't forget to destroy all of your infrastructure. If you leave it, it will cost you (like running water all the time).
terraform destroy -auto-approve
- If you want to log in to broker or cra (container registry agent) containers for debug purpose, do following:
Note: You need AWS CLI and Session manager plugin installed in your local machine.
-
AWS CLI
-
Session manager plugin
./debug/debug_login_into_broker.sh broker
./debug/debug_login_into_broker.sh cra
[] Using ECS on EC2 version? [] Terraform cloud compatible versioin?