-
Notifications
You must be signed in to change notification settings - Fork 0
Create newdec11.tf #9
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,309 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| resource "aws_instance" "web_host" { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| # ec2 have plain text secrets in user data | ||||||||||||||||||||||||||||||||||||||||||||||||
| ami = "${var.ami}" | ||||||||||||||||||||||||||||||||||||||||||||||||
| instance_type = "t2.nano" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| vpc_security_group_ids = [ | ||||||||||||||||||||||||||||||||||||||||||||||||
| "${aws_security_group.web-node.id}"] | ||||||||||||||||||||||||||||||||||||||||||||||||
| subnet_id = "${aws_subnet.web_subnet.id}" | ||||||||||||||||||||||||||||||||||||||||||||||||
| user_data = <<EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| #! /bin/bash | ||||||||||||||||||||||||||||||||||||||||||||||||
| sudo apt-get update | ||||||||||||||||||||||||||||||||||||||||||||||||
| sudo apt-get install -y apache2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| sudo systemctl start apache2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| sudo systemctl enable apache2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 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 Terraform</h1>" | sudo tee /var/www/html/index.html | ||||||||||||||||||||||||||||||||||||||||||||||||
| EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| tags = merge({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| Name = "${local.resource_prefix.value}-ec2" | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, { | ||||||||||||||||||||||||||||||||||||||||||||||||
| git_commit = "d68d2897add9bc2203a5ed0632a5cdd8ff8cefb0" | ||||||||||||||||||||||||||||||||||||||||||||||||
| git_file = "terraform/aws/ec2.tf" | ||||||||||||||||||||||||||||||||||||||||||||||||
| git_last_modified_at = "2020-06-16 14:46:24" | ||||||||||||||||||||||||||||||||||||||||||||||||
| git_last_modified_by = "nimrodkor@gmail.com" | ||||||||||||||||||||||||||||||||||||||||||||||||
| git_modifiers = "nimrodkor" | ||||||||||||||||||||||||||||||||||||||||||||||||
| git_org = "bridgecrewio" | ||||||||||||||||||||||||||||||||||||||||||||||||
| git_repo = "terragoat" | ||||||||||||||||||||||||||||||||||||||||||||||||
| yor_trace = "347af3cd-4f70-4632-aca3-4d5e30ffc0b6" | ||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||
| ebs_optimized = true | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
caswalker marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
| } | |
| *_block_device { | |
| encrypted = true | |
| } | |
| } |
EBS volumes do not have encrypted launch configurations
Resource: aws_instance.web_host | ID: BC_AWS_GENERAL_13
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
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EBS does not have an AWS Backup backup plan
Resource: aws_ebs_volume.web_host_storage | ID: BC_AWS_GENERAL_50
How to Fix
resource "aws_ebs_volume" "ebs_good" {
availability_zone = "us-west-2a"
size = 40
tags = {
Name = "HelloWorld"
}
}
resource "aws_backup_selection" "backup_good" {
iam_role_arn = "arn"
name = "tf_example_backup_selection"
plan_id = "123456"
resources = [
aws_ebs_volume.ebs_good.arn
]
}
Description
TBADependent Resources
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not only encrypted EBS volumes are attached to EC2 instances
Resource: aws_ebs_volume.web_host_storage | ID: BC_AWS_GENERAL_60
How to Fix
resource "aws_instance" "web" {
ami = "ami-21f78e11"
availability_zone = "us-west-2a"
instance_type = "t2.micro"
tags = {
Name = "HelloWorld"
}
}
resource "aws_volume_attachment" "ok_attachment1" {
device_name = "/dev/sdh3"
volume_id = aws_ebs_volume.ok_ebs2.id
instance_id = aws_instance.web.id
}
resource "aws_ebs_volume" "ok_ebs2" {
availability_zone = ""
encrypted = true
}
Description
TBADependent Resources
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | |
| encrypted = true | |
| } |
AWS EBS volumes are not encrypted
Resource: aws_ebs_volume.web_host_storage | ID: BC_AWS_GENERAL_3
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.1 3.4
- PCI-DSS V3.2 3
- NIST-800-53 SC-2
- FEDRAMP (MODERATE) SC-28
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AWS Security Group allows all traffic on SSH port 22
Resource: aws_security_group.web-node | 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.1 1.2.1, 1.3, 2.2.2
- 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
- CIS AWS V1.3 5.2
- FEDRAMP (MODERATE) AC-4, SC-7, SC-7(3)
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not every Security Group rule has a description
Resource: aws_security_group.web-node | ID: BC_AWS_NETWORKING_31
Description
Descriptions can be up to 255 characters long and can be set and viewed from the AWS Management Console, AWS Command Line Interface (CLI), and the AWS APIs.We recommend you add descriptive text to each of your Security Group Rules clarifying each rule's goals, this helps prevent developer errors.
Benchmarks
- SOC2 CC6.3.3
- ISO27001 A.10.1.1
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AWS Default Security Group does not restrict all traffic
Resource: aws_vpc.web_vpc | ID: BC_AWS_NETWORKING_4
How to Fix
resource "aws_default_security_group" "default" {
vpc_id = aws_vpc.ok_vpc.id
}Description
A VPC comes with a default security group that has an initial setting denying all inbound traffic, allowing all outbound traffic, and allowing all traffic between instances assigned to the security group. If you do not specify a security group when you launch an instance, the instance is automatically assigned to this default security group. Security groups are stateful and provide filtering of ingress/egress network traffic to AWS resources.We recommend that your default security group restricts all inbound and outbound traffic. The default VPC in every region should have its default security group updated to comply with this recommendation. Any newly created VPCs will automatically contain a default security group that will need remediation to comply with this recommendation.
Configuring all VPC default security groups to restrict all traffic will encourage least privilege security group development and mindful placement of AWS resources into security groups. This in-turn reduces the exposure of those resources.
Benchmarks
- SOC2 CC6.3.3
- PCI-DSS V3.2.1 1.3, 2.1
- 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.13.1.3
- CIS AWS V1.2 4.4
- FEDRAMP (MODERATE) AC-4, SC-7, SC-7(3)
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| map_public_ip_on_launch = true |
VPC subnets should not allow automatic public IP assignment
Resource: aws_subnet.web_subnet | ID: BC_AWS_NETWORKING_53
Description
TBDDependent Resources
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| map_public_ip_on_launch = true |
VPC subnets should not allow automatic public IP assignment
Resource: aws_subnet.web_subnet2 | ID: BC_AWS_NETWORKING_53
Description
TBDDependent Resources
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AWS access logging not enabled on S3 buckets
Resource: aws_s3_bucket.flowbucket | ID: BC_AWS_S3_13
How to Fix
resource "aws_s3_bucket" "bucket" {
acl = var.s3_bucket_acl
bucket = var.s3_bucket_name
policy = var.s3_bucket_policy
force_destroy = var.s3_bucket_force_destroy
versioning {
enabled = var.versioning
mfa_delete = var.mfa_delete
}
+ dynamic "logging" {
+ for_each = var.logging
+ content {
+ target_bucket = logging.value["target_bucket"]
+ target_prefix = "log/${var.s3_bucket_name}"
+ }
+ }
}Description
Access logging provides detailed audit logging for all objects and folders in an S3 bucket.Benchmarks
- HIPAA 164.312(B) Audit controls
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing Bucket with encryption
Resource: aws_s3_bucket.flowbucket | ID: cb404a47-3b88-40eb-b6ad-94081e055e6a
Dependent Resources
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tags must exist - Custom Policy
Resource: aws_s3_bucket.flowbucket | ID: bf9d1e74-2303-4d6c-8bd7-13f5582b94f9
Dependent Resources
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S3 Bucket does not have public access blocks
Resource: aws_s3_bucket.flowbucket | ID: BC_AWS_NETWORKING_52
How to Fix
resource "aws_s3_bucket" "bucket_good_1" {
bucket = "bucket_good"
}
resource "aws_s3_bucket_public_access_block" "access_good_1" {
bucket = aws_s3_bucket.bucket_good_1.id
block_public_acls = true
block_public_policy = true
}
Description
When you create an S3 bucket, it is good practice to set the additional resource **aws_s3_bucket_public_access_block** to ensure the bucket is never accidentally public.We recommend you ensure S3 bucket has public access blocks. If the public access block is not attached it defaults to False.
Dependent Resources
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S3 bucket cross-region replication disabled
Resource: aws_s3_bucket.flowbucket | ID: BC_AWS_GENERAL_72
How to Fix
resource "aws_s3_bucket" "test" {
...
+ replication_configuration {
+ role = aws_iam_role.replication.arn
+ rules {
+ id = "foobar"
+ prefix = "foo"
+ status = "Enabled"
+
+ destination {
+ bucket = aws_s3_bucket.destination.arn
+ storage_class = "STANDARD"
+ }
+ }
+ }
}Description
Cross-region replication enables automatic, asynchronous copying of objects across S3 buckets. By default, replication supports copying new S3 objects after it is enabled. It is also possible to use replication to copy existing objects and clone them to a different bucket, but in order to do so, you must contact AWS Support.Dependent Resources
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | |
| versioning { | |
| enabled = true | |
| } | |
| } |
AWS S3 object versioning is disabled
Resource: aws_s3_bucket.flowbucket | ID: BC_AWS_S3_16
Description
S3 versioning is a managed data backup and recovery service provided by AWS. When enabled it allows users to retrieve and restore previous versions of their buckets.S3 versioning can be used for data protection and retention scenarios such as recovering objects that have been accidentally/intentionally deleted or overwritten.
Benchmarks
- PCI-DSS V3.2.1 10.5.3
- FEDRAMP (MODERATE) CP-10, SI-12
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | |
| server_side_encryption_configuration { | |
| rule { | |
| apply_server_side_encryption_by_default { | |
| sse_algorithm = "AES256" | |
| } | |
| } | |
| } | |
| } |
Data stored in the S3 bucket is not securely encrypted at rest
Resource: aws_s3_bucket.flowbucket | ID: BC_AWS_S3_14
Description
SSE helps prevent unauthorized access to S3 buckets. Encrypting and decrypting data at the S3 bucket level is transparent to users when accessing data.Benchmarks
- PCI-DSS V3.2.1 3.4
- PCI-DSS V3.2 3
- NIST-800-53 AC-17, SC-2
- CIS AWS V1.3 2.1.1
- FEDRAMP (MODERATE) SC-28
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | |
| server_side_encryption_configuration { | |
| rule { | |
| apply_server_side_encryption_by_default { | |
| sse_algorithm = "aws:kms" | |
| } | |
| } | |
| } | |
| } |
S3 buckets are not encrypted with KMS
Resource: aws_s3_bucket.flowbucket | ID: BC_AWS_GENERAL_56
Description
TBADependent Resources
Calculating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im not merging this because xyz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resource: aws_instance.web_host | ID:
BC_AWS_SECRETS_1How to Fix
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.
Dependent Resources
Calculating...