Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create ec2.tf #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
14 changes: 14 additions & 0 deletions terraform/aws/eks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ resource aws_subnet "eks_subnet1" {
"kubernetes.io/cluster/$$$${local.eks_name.value}" = "shared"
"kubernetes.io/cluster/$$${local.eks_name.value}" = "shared"
"kubernetes.io/cluster/$${local.eks_name.value}" = "shared"
}, {
"kubernetes.io/cluster/$$$$$$${local.eks_name.value}" = "shared"
"kubernetes.io/cluster/$$$$$${local.eks_name.value}" = "shared"
"kubernetes.io/cluster/$$$$${local.eks_name.value}" = "shared"
"kubernetes.io/cluster/$$$${local.eks_name.value}" = "shared"
"kubernetes.io/cluster/$$${local.eks_name.value}" = "shared"
"kubernetes.io/cluster/$${local.eks_name.value}" = "shared"
})
}

Expand Down Expand Up @@ -133,6 +140,13 @@ resource aws_subnet "eks_subnet2" {
"kubernetes.io/cluster/$$$${local.eks_name.value}" = "shared"
"kubernetes.io/cluster/$$${local.eks_name.value}" = "shared"
"kubernetes.io/cluster/$${local.eks_name.value}" = "shared"
}, {
"kubernetes.io/cluster/$$$$$$${local.eks_name.value}" = "shared"
"kubernetes.io/cluster/$$$$$${local.eks_name.value}" = "shared"
"kubernetes.io/cluster/$$$$${local.eks_name.value}" = "shared"
"kubernetes.io/cluster/$$$${local.eks_name.value}" = "shared"
"kubernetes.io/cluster/$$${local.eks_name.value}" = "shared"
"kubernetes.io/cluster/$${local.eks_name.value}" = "shared"
})
}

Expand Down
58 changes: 58 additions & 0 deletions terraform/simple_instance/ec2.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
provider "aws" {
region = "us-west-2"
}

resource "aws_security_group" "ssh_traffic" {
Copy link

@bridgecrew bridgecrew bot Sep 21, 2021

Choose a reason for hiding this comment

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

LOW   AWS resources that support tags do not have Tags
    Resource: aws_security_group.ssh_traffic | ID: BC_AWS_GENERAL_26

How to Fix

resource "aws_security_group" "sg" {
  name = "my-sg"
  ...
+ tags = {
+   Environment = "dev"
+   Owner = "apps-team"
+ }
}

Description

Many different types of AWS resources support tags. Tags allow you to add metadata to a resource to help identify ownership, perform cost / billing analysis, and to enrich a resource with other valuable information, such as descriptions and environment names. While there are many ways that tags can be used, we recommend you follow a tagging practice.

View AWS's recommended tagging best practices here.

Copy link

@bridgecrew bridgecrew bot Sep 21, 2021

Choose a reason for hiding this comment

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

CRITICAL   AWS Security Group allows all traffic on SSH port 22
    Resource: aws_security_group.ssh_traffic | ID: BC_AWS_NETWORKING_1

Description

Security groups are stateful and provide filtering of ingress/egress network traffic to AWS resources. We recommend that security groups do not allow unrestricted ingress access to port 22. Removing unfettered connectivity to remote console services, such as SSH, reduces a server's exposure to risk.

Benchmarks

  • SOC2 CC6.3.3
  • PCI-DSS V3.2 2
  • HIPAA 164.312(E)(1)
  • NIST-800-53 AC-17, CA-3, CA-9, CM-3, SC-2
  • ISO27001 A.10.1.1
  • CIS AWS V1.2 4.1
  • PCI-DSS V3.2.1 1.2.1, 1.3, 2.2.2
  • FEDRAMP (MODERATE) AC-4, SC-7, SC-7(3)
  • CIS AWS V1.3 5.2

name = "ssh_traffic"
description = "Allow SSH inbound traffic"
ingress {
description = "SSH"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
git_commit = "79f5e352df8b678c797eccb0f44fba6003b516cc"
git_file = "terraform/simple_instance/ec2.tf"
git_last_modified_at = "2021-09-21 18:36:29"
git_last_modified_by = "[email protected]"
git_modifiers = "31853954+pasqua1e"
git_org = "pasqua1e"
git_repo = "terragoat"
yor_trace = "0b54c47e-b4fc-4429-a0d1-ebf9e3705af4"
}
}

resource "aws_instance" "web_server_instance" {
Copy link

@bridgecrew bridgecrew bot Sep 21, 2021

Choose a reason for hiding this comment

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

LOW   Instance Metadata Service version 1 is enabled
    Resource: aws_instance.web_server_instance | ID: BC_AWS_GENERAL_31

How to Fix

resource "aws_instance" "example" {
  ...
  instance_type     = "t2.micro"
+   metadata_options {
        ...
+       http_endpoint = "enabled"
+       http_tokens   = "required"
+  }
  ...
}

Description

The Instance Metadata Service (IMDS) is an on-instance component used by code on the instance to securely access instance metadata. You can access instance metadata from a running instance using one of the following methods: * Instance Metadata Service Version 1 (IMDSv1) – a request/response method * Instance Metadata Service Version 2 (IMDSv2) – a session-oriented method

As a request/response method IMDSv1 is prone to local misconfigurations:

  • Open proxies, open NATs and routers, server-side reflection vulnerabilities.
  • One way or another, local software might access local-only data.

Benchmarks

  • FEDRAMP (MODERATE) AC-6

Copy link

@bridgecrew bridgecrew bot Sep 21, 2021

Choose a reason for hiding this comment

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

HIGH   EBS volumes do not have encrypted launch configurations
    Resource: aws_instance.web_server_instance | ID: BC_AWS_GENERAL_13

How to Fix

resource "aws_launch_configuration" "example" {
  ...
  instance_type = "t2.micro"
+ root_block_device {
+ encrypted     = true
+ }
  ...
}

Description

Amazon Elastic Block Store (EBS) volumes allow you to create encrypted launch configurations when creating EC2 instances and auto scaling. When the entire EBS volume is encrypted, data stored at rest on the volume, disk I/O, snapshots created from the volume, and data in-transit between EBS and EC2 are all encrypted.

Benchmarks

  • PCI-DSS V3.2 3

ami = data.aws_ami.ubuntu.id
instance_type = "t2.micro"
security_groups = ["${aws_security_group.ssh_traffic.name}"]
tags = {
Name = "bc_workshop_ec2"
git_commit = "79f5e352df8b678c797eccb0f44fba6003b516cc"
git_file = "terraform/simple_instance/ec2.tf"
git_last_modified_at = "2021-09-21 18:36:29"
git_last_modified_by = "[email protected]"
git_modifiers = "31853954+pasqua1e"
git_org = "pasqua1e"
git_repo = "terragoat"
yor_trace = "b17a8e94-dc61-449a-9981-18df937bf3a9"
}
}
Copy link

@bridgecrew bridgecrew bot Sep 21, 2021

Choose a reason for hiding this comment

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

Suggested change
}
monitoring = true
}
MEDIUM   Detailed monitoring for EC2 instances is disabled
    Resource: aws_instance.web_server_instance | ID: BC_AWS_LOGGING_26

Description

TBA

Copy link

@bridgecrew bridgecrew bot Sep 21, 2021

Choose a reason for hiding this comment

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

Suggested change
}
ebs_optimized = true
}
LOW   EC2 EBS is not optimized
    Resource: aws_instance.web_server_instance | ID: BC_AWS_GENERAL_68

Description

TBA


data "aws_ami" "ubuntu" {
most_recent = true

filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}

owners = ["099720109477"] # Canonical
}