Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: CC-BY-SA-4.0
- Table of Contents
- Introduction
- Deployed Resource Details
- Implementation Instructions
- Customization Instructions
- Deletion Instructions
- References
The AMI Bakery Organization solution will automate creation of standardized and hardened Amazon Machine Operating Images with configurations and services that comply with security standards set by the Government and industry security standards/benchmarks such as and the Security Technical Implementation Guide (STIG) and the Center of Internet Security (CIS).
The solution also provides an easy way to deploy security services such as Amazon Inspector, Amazon Macie, and Amazon GuardDuty that track and report potential vulnerabilities found within the environment. Additionally, the solution, once created, reduces the need to re-create new images when customers move from one multi-account to another as it can be shared and re-used.
Key solution features:
- Amazon Linux 2023 STIG hardened image
- Ubuntu Pro CIS Level 1 hardened image
- Microsoft Windows Server 2022 Base STIG hardened image
- Windows CIS Level 1 -
Work on progress
- All resources are deployed via AWS CloudFormation as a
StackSet
andStack Instance
within themanagement account
or a CloudFormationStack
within a specific account. - The Customizations for AWS Control Tower solution deploys all templates as a CloudFormation
StackSet
. - For parameter details, review the AWS CloudFormation templates.
- The
Organizaton Management Lambda Role
is used by the Lambda function to assume a role in the target region.
- SQS dead letter queue used for retaining any failed Lambda events.
- SNS Topic used to notify subscribers when messages hit the DLQ.
- The Lambda function assumes a role in the Image Bakery Account and deploys resources to create Amazon Machine Images (AMIs). These resources include a Code Commit Repository to store CloudFormation Templates for creating AMIs, a Code Pipeline to deploy EC2 Image Builder to create AMIs, and other supporting resources such as an S3 Bucket and IAM Roles. The Lambda function also uploads an initial CloudFormation template to the Code Commit Repository.
- All the
AWS Lambda Function
logs are sent to a CloudWatch Log Group</aws/lambda/<LambdaFunctionName>
to help with debugging and traceability of the actions performed. - By default the
AWS Lambda Function
will create the CloudWatch Log Group and logs are encrypted with a CloudWatch Logs service managed encryption key. - Parameters are provided for changing the default log group retention and encryption KMS key.
- The
Configuration Role
is assumed by the Lambda function and used to create resources in the Image Bakery Account such as the Code Commit Repository, Code Pipeline, and S3 Bucket. - The
Code Pipeline Role
is assumed by te Code Pipeline and used to create resources in the Image Bakery Account such as the EC2 Image Builder. - The
Cloud Formation Role
is assumed by EC2 Image Builder and used to create Amazon Machine Images (AMIs) in the Image Bakery Account.
- Amazon S3 Bucket for storing Code Commit artifacts.
- A Code Commit Repository to store CloudFormation Templates that define EC2 Image Builder, Recipes, Components, etc.
- AWS CloudFormation Templates describe the EC2 Image Builder, Recipes, Components, etc. used to build Amazon Machine Images (AMIs).
- AWS CodePipeline monitors the CodeCommit Repository for changes to the CloudFormation Templates. When the Repository is updated, CodePipeline automatically updates EC2 Image builder.
- EC2 ImageBuilder builds new Amazon Machine Images (AMIs) based on the CloudFormation Templates in the CodeCommit Repository.
- Amazon Machine Images (AMIs) are built by EC2 Image Builder. Then can then be used to launch EC2 Instances.
- Download and Stage the SRA Solutions. Note: This only needs to be done once for all the solutions.
- Verify that the SRA Prerequisites Solution has been deployed.
Choose a Deployment Method:
In the management account (home region)
, launch the sra-ami-bakery-org-main-ssm.yaml template. This uses an approach where some of the CloudFormation parameters are populated from SSM parameters created by the SRA Prerequisites Solution.
aws cloudformation deploy --template-file $HOME/aws-security-reference-architecture-examples/aws_sra_examples/solutions/ami_bakery/ami_bakery_org/templates/sra-ami-bakery-org-main-ssm.yaml --stack-name sra-ami-bakery-org-main-ssm --capabilities CAPABILITY_NAMED_IAM --parameter-overrides pAMIBakeryAccountId=<YOUR_ACCOUNT_ID> pAMIBakeryRegion=<YOUR_REGION> pAMIBakeryFileName=<SOLUTION_FILE_NAME.YAML>
Note: Below are available Cloudformation solution file templates, you can change the file names to meet your needs.
- sra-ami-bakery-org-amazon-linux-stig-hardened.yaml
- sra-ami-bakery-org-ubuntu-pro-20-04-cis-level-1-hardened.yaml
- sra-ami-bakery-org-windows-server-2022-stig-hardened.yaml
- Log into the EC2 ImageBuilder console.
- Navigate to the
Image pipelines
tab on the top left pane. It will displaysra-ami-bakery-org-image-type-pipeline
under the pipeline name column with Pipeline status set toGreen
.Note:
i.
You can manually create the image by running the pipeline with the following steps:Click on Pipeline -> Actions dropdown -> Run pipeline
OR2.
Leave the Pipeline to automatically create it for you daily at midnight (UTC). - Verify that the image has been created by selecting the
Images
tab on the left pane or under theOutput Images
column below the pipeline's Summary
The AMI Bakery solution can be customized to meet customer needs. This can be done by updating the image recipe of each supplied Cloudformation solution file template with the addition of one or more Amazon-managed or customer-managed components.
Note: To avoid errors when updating the recipe, the EC2 Image Builder Recipe version number, i.e, pSRAAMIBakeryImageRecipeVersionNumber
parameter value in the available Cloudformation solution file templates above must be changed from the default value 1.0.0
to something like 1.1.0
or any version number in ^[0-9]+\.[0-9]+\.[0-9]+$
pattern.
You can make the changes either in the available CloudFormation files BEFORE the deployment OR from inside the CodeCommit repo after the deployment. Once updated from inside the CodeCommit repo console, go back to AWS CodePipeline console
, open the solution's pipeline, and click Release change
for the change to take effect.
-
Example 1: Adding Amazon Managed Microsoft Web Server IIS into Windows Server 2022 Image
- Add the Component's ARN as follows:
- ComponentArn: arn:aws:imagebuilder:us-east-1:aws:component/windows-server-iis/x.x.x
under therSRAAMIBakeryAMIBakeryImageBuilderRecipe
'sComponents
property. - You can do the same for all Amazon managed tools/clients found in the EC2 Image Builder component's console for other images (Amazon Linux and Ubuntu Pro 20.04) in your region.
- Add the Component's ARN as follows:
-
Example 2: Adding a custom component (Customer-Managed) for Apache Httpd Web server with PHP and MariaDB into Amazon Linux 2023 Image
-
Copy the code below and paste it into the file right at the top of the
rSRAAMIBakeryAMIBakeryImageBuilderRecipe
resource under the CloudFormationResources
section.rInstallApachePHPMariaDB: Type: AWS::ImageBuilder::Component Properties: Name: apache-install Version: !Ref pSRAAMIBakeryImageRecipeVersionNumber Platform: Linux Data: | name: InstallApachePHPMariaDB description: This will install Apache Httpd Web server with PHP and MariaDB schemaVersion: 1.0 phases: - name: build steps: - name: Install action: ExecuteBash inputs: commands: - sudo yum update -y - sudo yum install -y amazon-linux-extras - sudo amazon-linux-extras install mariadb10.5 - sudo amazon-linux-extras install php8.2 - sudo yum install -y httpd - sudo systemctl start httpd - sudo systemctl enable httpd
-
Add the customized Component's ARN
- ComponentArn: !Ref rInstallApachePHPMariaDB
under therSRAAMIBakeryAMIBakeryImageBuilderRecipe
'sComponents
property.
-
Choose one of the two options below:
- Option 1: Use AWS Management Console
- In the
management account (home region)
, delete the AWS CloudFormation Stack (sra-ami-bakery-org-main-ssm
). Note: This will delete all SRA Staging resources - In the
management account (home region)
, verify that the Lambda function processing is complete by confirming no more CloudWatch logs are generated. - In the
management account (home region)
, delete the AWS CloudWatch Log Group (e.g. /aws/lambda/<solution_name>) for the Lambda function deployed. - In the
account (home region)
identified bypAMIBakeryAccountId
parameter, delete the AWS CloudFormation Stack (sra-ami-bakery-org-cloudformation-stack
). Note: This will delete your solution with associated resources (IAM roles and policies, EC2 Image Builder resources, S3 Bucket, Codepipeline resources, etc) - Delete
sra-ami-bakery-org-cloudformation-role
role in the IAM console in theaccount (home region)
identified bypAMIBakeryAccountId
parameter Note: this will delete both cloudformation role and associated policy - Go to EC2 Image Builder console and choose Images from the navigation pane. Select the image versions created by the AMI Bakery solution. Select the images and on the Actions menu, choose Delete.
- Option 2: Use AWS CLI
- Note: For steps
1 and 2
, we assume you are running the commands below against themanagement (home region)
, and for Steps3 - 5
, we assume you are running them in theaccount (home region)
identified bypAMIBakeryAccountId
parameter.
aws cloudformation delete-stack --stack-name sra-ami-bakery-org-main-ssm
. Note: This will delete all SRA Staging resourcesaws logs delete-log-group --log-group-name /aws/lambda/sra-ami-bakery-org
. Note: This will delete the log group for AMI bakery solutionaws cloudformation delete-stack --stack-name sra-ami-bakery-org-cloudformation-stack
. Note: This will delete your solution with associated resources (IAM roles and policies, EC2 Imagebuilder resources, S3 Bucket, CodepiPeline resources, etc)aws iam delete-role-policy --role-name sra-ami-bakery-org-cloudformation-role --policy-name sra-ami-bakery-org-cloudformation-policy
. Note: This will delete CloudFormation policyaws iam delete-role --role-name sra-ami-bakery-org-cloudformation-role
. Note: This will delete CloudFormation role.aws imagebuilder delete-image --image-build-version-arn <ARN_OF_THE_IMAGE_RESOURCE_VERSION_TO_BE_DELETED >
. Note: The image's arn can be fetched using this commandaws imagebuilder list-mages