-
Notifications
You must be signed in to change notification settings - Fork 0
Update main.tf #4
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 |
|---|---|---|
| @@ -1,45 +1,148 @@ | ||
| resource "aws_s3_bucket" "bad_bucket" { | ||
| bucket = "prisma-cloud-test-bucket" | ||
| acl = "private" | ||
| locals { | ||
| eks_name = { | ||
| value = "${local.resource_prefix.value}-eks" | ||
| } | ||
| } | ||
|
|
||
| data aws_iam_policy_document "iam_policy_eks" { | ||
| statement { | ||
| effect = "Allow" | ||
| actions = ["sts:AssumeRole"] | ||
| principals { | ||
| type = "Service" | ||
| identifiers = ["eks.amazonaws.com"] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource aws_iam_role "iam_for_eks" { | ||
| name = "${local.resource_prefix.value}-iam-for-eks" | ||
| assume_role_policy = data.aws_iam_policy_document.iam_policy_eks.json | ||
| tags = { | ||
| Name = "PrismaCloudTestBucket" | ||
| Environment = "Test" | ||
| git_commit = "d68d2897add9bc2203a5ed0632a5cdd8ff8cefb0" | ||
| git_file = "terraform/aws/eks.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 = "de052596-21a0-43de-8153-469add277b18" | ||
| } | ||
| } | ||
|
|
||
| resource aws_iam_role_policy_attachment "policy_attachment-AmazonEKSClusterPolicy" { | ||
| policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy" | ||
| role = aws_iam_role.iam_for_eks.name | ||
| } | ||
|
|
||
| resource "aws_s3_bucket" "bad_bucket_log_bucket" { | ||
| bucket = "bad_bucket-log-bucket" | ||
| resource aws_iam_role_policy_attachment "policy_attachment-AmazonEKSServicePolicy" { | ||
| policy_arn = "arn:aws:iam::aws:policy/AmazonEKSServicePolicy" | ||
| role = aws_iam_role.iam_for_eks.name | ||
| } | ||
|
|
||
| resource "aws_s3_bucket_logging" "bad_bucket" { | ||
| bucket = aws_s3_bucket.bad_bucket.id | ||
| target_bucket = aws_s3_bucket.bad_bucket_log_bucket.id | ||
| target_prefix = "log/" | ||
| resource aws_vpc "eks_vpc" { | ||
| cidr_block = "10.10.0.0/16" | ||
| enable_dns_hostnames = true | ||
| enable_dns_support = true | ||
| tags = merge({ | ||
| Name = "${local.resource_prefix.value}-eks-vpc" | ||
| }, { | ||
| git_commit = "d68d2897add9bc2203a5ed0632a5cdd8ff8cefb0" | ||
| git_file = "terraform/aws/eks.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 = "1600ca6c-72f6-45c0-a71d-88e117e51d6b" | ||
| }) | ||
| } | ||
|
|
||
| resource aws_subnet "eks_subnet1" { | ||
|
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.
|
||
| vpc_id = aws_vpc.eks_vpc.id | ||
| cidr_block = "10.10.10.0/24" | ||
| availability_zone = "${var.region}a" | ||
| map_public_ip_on_launch = true | ||
| tags = merge({ | ||
| Name = "${local.resource_prefix.value}-eks-subnet" | ||
| "kubernetes.io/cluster/${local.eks_name.value}" = "shared" | ||
| }, { | ||
| git_commit = "6e62522d2ab8f63740e53752b84a6e99cd65696a" | ||
| git_file = "terraform/aws/eks.tf" | ||
| git_last_modified_at = "2021-05-02 11:16:31" | ||
| git_last_modified_by = "nimrodkor@gmail.com" | ||
| git_modifiers = "nimrodkor" | ||
| git_org = "bridgecrewio" | ||
| git_repo = "terragoat" | ||
| "kubernetes.io/cluster/$${local.eks_name.value}" = "shared" | ||
| yor_trace = "1fb4fa23-a5d6-4d6a-b7dc-88749383f48d" | ||
| }, { | ||
| "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" | ||
| }) | ||
| } | ||
|
|
||
| resource "aws_security_group" "bad_security_group" { | ||
| name = "prisma-cloud-test-sg" | ||
| description = "Allow all inbound traffic" | ||
| resource aws_subnet "eks_subnet2" { | ||
|
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.
|
||
| vpc_id = aws_vpc.eks_vpc.id | ||
| cidr_block = "10.10.11.0/24" | ||
| availability_zone = "${var.region}b" | ||
| map_public_ip_on_launch = true | ||
| tags = merge({ | ||
| Name = "${local.resource_prefix.value}-eks-subnet2" | ||
| "kubernetes.io/cluster/${local.eks_name.value}" = "shared" | ||
| }, { | ||
| git_commit = "6e62522d2ab8f63740e53752b84a6e99cd65696a" | ||
| git_file = "terraform/aws/eks.tf" | ||
| git_last_modified_at = "2021-05-02 11:16:31" | ||
| git_last_modified_by = "nimrodkor@gmail.com" | ||
| git_modifiers = "nimrodkor" | ||
| git_org = "bridgecrewio" | ||
| git_repo = "terragoat" | ||
| "kubernetes.io/cluster/$${local.eks_name.value}" = "shared" | ||
| yor_trace = "9ce04af2-5321-4e6c-a262-e4d7c1f69525" | ||
| }, { | ||
| "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" | ||
| }) | ||
| } | ||
|
|
||
| ingress { | ||
| from_port = 0 | ||
| to_port = 0 | ||
| protocol = "-1" | ||
| cidr_blocks = ["0.0.0.0/0"] # This is a misconfiguration (open to the world) | ||
| } | ||
| resource aws_eks_cluster "eks_cluster" { | ||
|
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.
|
||
| name = local.eks_name.value | ||
| role_arn = "${aws_iam_role.iam_for_eks.arn}" | ||
|
|
||
| egress { | ||
| from_port = 0 | ||
| to_port = 0 | ||
| protocol = "-1" | ||
| cidr_blocks = ["0.0.0.0/0"] | ||
| vpc_config { | ||
| endpoint_private_access = true | ||
| subnet_ids = ["${aws_subnet.eks_subnet1.id}", "${aws_subnet.eks_subnet2.id}"] | ||
| } | ||
|
|
||
| depends_on = [ | ||
| "aws_iam_role_policy_attachment.policy_attachment-AmazonEKSClusterPolicy", | ||
| "aws_iam_role_policy_attachment.policy_attachment-AmazonEKSServicePolicy", | ||
| ] | ||
| tags = { | ||
| Name = "PrismaCloudTestSG" | ||
| Environment = "Test" | ||
| git_commit = "d68d2897add9bc2203a5ed0632a5cdd8ff8cefb0" | ||
| git_file = "terraform/aws/eks.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 = "7fa14261-c18d-4fa2-aec4-746f6e64d2d3" | ||
| } | ||
| } | ||
|
|
||
| output "endpoint" { | ||
| value = "${aws_eks_cluster.eks_cluster.endpoint}" | ||
| } | ||
|
|
||
| output "kubeconfig-certificate-authority-data" { | ||
| value = "${aws_eks_cluster.eks_cluster.certificate_authority.0.data}" | ||
| } | ||
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_vpc.eks_vpc | Checkov ID: CKV2_AWS_12
How to Fix
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.
NOTE: When implementing this recommendation, VPC flow logging is invaluable in determining the least privilege port access required by systems to work properly. VPC flow logging can log all packet acceptances and rejections occurring under the current security groups. This dramatically reduces the primary barrier to least privilege engineering, discovering the minimum ports required by systems in the environment.
Even if the VPC flow logging recommendation described is not adopted as a permanent security measure, it should be used during any period of discovery and engineering for least privileged security groups.