Skip to content

Commit 994e2dc

Browse files
author
Mike Saintcross
committed
added comments, added example code, updated README
1 parent b388533 commit 994e2dc

7 files changed

+28
-16
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This solution builds an [EC2 Image Builder Pipeline](https://docs.aws.amazon.com
44

55
The solution includes two [Cloudwatch Event Rules](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/Create-CloudWatch-Events-Rule.html). One which triggers the start of the Container Image pipeline based on an [Inspector Finding](https://docs.aws.amazon.com/inspector/latest/user/findings-managing.html) of "High" or "Critical" so that insecure images are replaced, if Inspector and [Amazon Elastic Container Registry](https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-create.html) ["Enhanced Scanning"](https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-scanning-enhanced.html) are both enabled. The other Event Rule sends notifications to an [SQS Queue](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html) after a successful Container Image push to the ECR Repository, to better enable consumption of new container images.
66

7+
In January 2023, [EC2 Image Builder added support for AWS Marketplace CIS Pre-Hardened images](https://aws.amazon.com/about-aws/whats-new/2023/01/ec2-image-builder-cis-benchmarks-security-hardening-amis/). This achieves a hardening goal, but is only for AMIs, not Container images, and you must sign-up for a [subscription](https://aws.amazon.com/marketplace/seller-profile?id=dfa1e6a8-0b7b-4d35-a59c-ce272caee4fc) in [AWS Marketplace](https://aws.amazon.com/marketplace) to CIS.
8+
79
## Prerequisites
810

911
* Terraform v.15+. [Download](https://www.terraform.io/downloads.html) and setup Terraform. Refer to the official Terraform [instructions](https://learn.hashicorp.com/collections/terraform/aws-get-started) to get started.

components.tf

+15-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,18 @@ resource "aws_s3_bucket_object" "component_files" {
1313
kms_key_id = aws_kms_key.this.id
1414
}
1515

16-
# Add custom component resources below
16+
/* Add custom component resources below
17+
The YAML file referenced in the URI attribute must exist in the files/ directory
18+
Below is an example component. */
19+
/* resource "aws_imagebuilder_component" "example_custom_component" {
20+
name = "example-custom-component"
21+
platform = "Linux"
22+
uri = "s3://${var.aws_s3_ami_resources_bucket}/files/example-custom-component.yml"
23+
version = "1.0.0"
24+
kms_key_id = aws_kms_key.this.arn
25+
26+
depends_on = [
27+
aws_s3_bucket_object.component_files,
28+
aws_kms_key.this
29+
]
30+
} */

config.tf

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
11
provider "aws" {
22
region = var.aws_region
3-
}
4-
5-
terraform {
6-
required_providers {
7-
aws = {
8-
source = "hashicorp/aws"
9-
version = "~> 4.45.0"
10-
}
11-
}
123
}

hardening-pipeline.tfvars

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Enter values for all of the following if you wish to avoid being prompted on each run.
2-
account_id = "012345678900"
3-
aws_region = "us-east-1"
2+
account_id = "063449332233"
3+
aws_region = "us-west-2"
44
vpc_name = "example-hardening-pipeline-vpc"
5-
kms_key_alias = "image-builder-container-key"
5+
kms_key_alias = "image-builder-container-key-2"
66
ec2_iam_role_name = "example-hardening-instance-role"
77
hardening_pipeline_role_name = "example-hardening-pipeline-role"
8-
aws_s3_ami_resources_bucket = "example-hardening-ami-resources-bucket-0123"
8+
aws_s3_ami_resources_bucket = "example-hardening-ami-resources-bucket-012345"
99
image_name = "example-hardening-al2-container-image"
1010
ecr_name = "example-hardening-container-repo"
1111
recipe_version = "1.0.0"

kms-key.tf

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* As this is intended to enable a Key Administrator in a multi-account structure
2+
the action and resource definition is broad */
13
data "aws_iam_policy_document" "this" {
24
statement {
35
sid = "Enable IAM User Permissions"

recipes.tf

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ resource "aws_imagebuilder_container_recipe" "container_image" {
99

1010
container_type = "DOCKER"
1111
parent_image = "amazonlinux:latest"
12-
working_directory = "/etc"
12+
working_directory = "/build"
1313

1414
target_repository {
1515
repository_name = var.ecr_name
@@ -42,6 +42,9 @@ resource "aws_imagebuilder_container_recipe" "container_image" {
4242

4343
# Add more component ARNs here to customize the recipe
4444
# You can also add custom components if you defined any in components.tf
45+
/* component {
46+
component_arn = aws_imagebuilder_component.example_custom_component.arn
47+
} */
4548

4649
dockerfile_template_data = <<EOF
4750
FROM {{{ imagebuilder:parentImage }}}

variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ variable "account_id" {
2424

2525
variable "aws_region" {
2626
type = string
27-
default = "us-east-2"
27+
default = "us-east-1"
2828
description = "Enter the AWS Region you wish to deploy in."
2929
}
3030

0 commit comments

Comments
 (0)