Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions pass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
AWSTemplateFormatVersion: '2010-09-09'
Description: AWS CloudFormation Template to deploy insecure infrastructure

Parameters:
CompanyName:
Description: Company Name

Type: String
Default: acme
Environment:
Description: Environment
Type: String

Default: dev
DBName:
Description: Name of the Database
Type: String

Default: db1
Password:
Description: Database Password
Type: String
NoEcho: True

MinLength: 1
MaxLength: 41

AllowedPattern: ^[a-zA-Z0-9]*$
LatestAmiId:
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
Default: /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2


Resources:
####################
### EC2 in VPC ###
####################
EC2Instance:
Copy link

@bridgecrew bridgecrew bot Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HIGH   Ensure EC2 user data does not expose secrets
    Resource: AWS::EC2::Instance.EC2Instance | ID: BC_AWS_SECRETS_1

Description

**User Data** is a metadata field of an EC2 instance that allows custom code to run after the instance is launched. It contains code exposed to any entity which has the most basic access to EC2, even read-only configurations. This code is not encrypted.

Removing secrets from easily-accessed unencrypted places reduces the risk of passwords, private keys and more from being exposed to third parties.

Type: AWS::EC2::Instance
Properties:
AvailabilityZone:

Fn::Select:
- 0
- Fn::GetAZs: ""

InstanceType: t2.nano
SecurityGroupIds:

- !Ref WebNodeSG
ImageId: !Ref LatestAmiId
SubnetId: !Ref WebSubnet

Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-ec2"
UserData:
Fn::Base64: |
#!/bin/bash
sudo yum -y update
sudo yum -y install httpd php php-mysqlnd
sudo systemctl enable httpd
sudo systemctl start httpd
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMAAA
export AWS_SECRET_ACCESS_KEY=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
export AWS_DEFAULT_REGION=us-west-2
echo "<h1>Deployed via CloudFormation</h1>" | sudo tee /var/www/html/index.html

WebHostStorage:
Copy link

@bridgecrew bridgecrew bot Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HIGH   Ensure AWS EBS volumes are encrypted
    Resource: AWS::EC2::Volume.WebHostStorage | ID: BC_AWS_GENERAL_3

How to Fix

Resources: 
  NewVolume:
    Type: AWS::EC2::Volume
    Properties: 
      ...
+     Encrypted: true

Description

Encrypting EBS volumes ensures that replicated copies of your images are secure even if they are accidentally exposed. AWS EBS encryption uses AWS KMS customer master keys (CMK) when creating encrypted volumes and snapshots. Storing EBS volumes in their encrypted state reduces the risk of data exposure or data loss. We recommend you encrypt all data stored in the EBS.

Benchmarks

  • PCI-DSS V3.2 3
  • NIST-800-53 SC-2
  • PCI-DSS V3.2.1 3.4
  • FEDRAMP (MODERATE) SC-28

# Unencrypted Volume

Type: AWS::EC2::Volume
Properties:
AvailabilityZone: !Select
- 0

- Fn::GetAZs: ""
#Encrypted: False
Size: 1

Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-ebs"
83 changes: 83 additions & 0 deletions test/fail.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
AWSTemplateFormatVersion: '2010-09-09'
Description: AWS CloudFormation Template to deploy insecure infrastructure

Parameters:
CompanyName:
Description: Company Name

Type: String
Default: acme
Environment:
Description: Environment
Type: String

Default: dev
DBName:
Description: Name of the Database
Type: String

Default: db1
Password:
Description: Database Password
Type: String
NoEcho: True

MinLength: 1
MaxLength: 41

AllowedPattern: ^[a-zA-Z0-9]*$
LatestAmiId:
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
Default: /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2


Resources:
####################
### EC2 in VPC ###
####################
EC2Instance:
Copy link

@bridgecrew bridgecrew bot Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HIGH   Ensure EC2 user data does not expose secrets
    Resource: AWS::EC2::Instance.EC2Instance | ID: BC_AWS_SECRETS_1

Description

**User Data** is a metadata field of an EC2 instance that allows custom code to run after the instance is launched. It contains code exposed to any entity which has the most basic access to EC2, even read-only configurations. This code is not encrypted.

Removing secrets from easily-accessed unencrypted places reduces the risk of passwords, private keys and more from being exposed to third parties.

Type: AWS::EC2::Instance
Properties:
AvailabilityZone:

Fn::Select:
- 0
- Fn::GetAZs: ""

InstanceType: t2.nano
SecurityGroupIds:

- !Ref WebNodeSG
ImageId: !Ref LatestAmiId
SubnetId: !Ref WebSubnet

Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-ec2"
UserData:
Fn::Base64: |
#!/bin/bash
sudo yum -y update
sudo yum -y install httpd php php-mysqlnd
sudo systemctl enable httpd
sudo systemctl start httpd
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMAAA
export AWS_SECRET_ACCESS_KEY=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
export AWS_DEFAULT_REGION=us-west-2
echo "<h1>Deployed via CloudFormation</h1>" | sudo tee /var/www/html/index.html

WebHostStorage:
Copy link

@bridgecrew bridgecrew bot Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HIGH   Ensure AWS EBS volumes are encrypted
    Resource: AWS::EC2::Volume.WebHostStorage | ID: BC_AWS_GENERAL_3

How to Fix

Resources: 
  NewVolume:
    Type: AWS::EC2::Volume
    Properties: 
      ...
+     Encrypted: true

Description

Encrypting EBS volumes ensures that replicated copies of your images are secure even if they are accidentally exposed. AWS EBS encryption uses AWS KMS customer master keys (CMK) when creating encrypted volumes and snapshots. Storing EBS volumes in their encrypted state reduces the risk of data exposure or data loss. We recommend you encrypt all data stored in the EBS.

Benchmarks

  • PCI-DSS V3.2 3
  • NIST-800-53 SC-2
  • PCI-DSS V3.2.1 3.4
  • FEDRAMP (MODERATE) SC-28

# Unencrypted Volume

Type: AWS::EC2::Volume
Properties:
AvailabilityZone: !Select
- 0

- Fn::GetAZs: ""
#Encrypted: False
Size: 1

Tags:
- Key: Name
Value: !Sub "${AWS::AccountId}-${CompanyName}-${Environment}-ebs"