Skip to content

Checkov #111

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Checkov #111

wants to merge 2 commits into from

Conversation

alexcoderabbitai
Copy link
Owner

@alexcoderabbitai alexcoderabbitai commented Apr 18, 2025

Summary by CodeRabbit

  • New Features
    • Added a sample Terraform configuration file that provisions AWS security groups and a public S3 bucket, intended for testing and demonstration purposes.

@alexcrtestapp
Copy link

alexcrtestapp bot commented Apr 18, 2025

Walkthrough

A new Terraform configuration file has been added, defining several AWS resources with intentionally insecure settings for testing purposes. The file sets up local variables, configures the AWS provider with hardcoded credentials, and declares two security groups—one with minimal restrictions and another with overly permissive rules. Additionally, a public S3 bucket is created with a "public-read" ACL and website hosting enabled. The Terraform block specifies required versions for both Terraform and the AWS provider. Comments are included to explain resource purposes and provide instructions for security scanning.

Changes

File(s) Change Summary
sampleTerraformFile.tf New Terraform configuration file introducing AWS provider setup with static credentials, two security groups (one minimal, one insecure), a public S3 bucket with website hosting, local variables, required version blocks, and explanatory comments.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Terraform
    participant AWS

    User->>Terraform: Apply configuration
    Terraform->>AWS: Create security group (this)
    Terraform->>AWS: Create security group (insecure)
    Terraform->>AWS: Create public S3 bucket with website config
    AWS-->>Terraform: Resources created
    Terraform-->>User: Provisioning complete
Loading

Poem

In the land of cloud and code so bright,
A file appears, not hidden from sight.
Security groups wide open, S3 buckets on display,
For testing and scanning, in a risky array.
Terraform whispers, "Deploy with care!"
The rabbit hops by, aware of each snare.
🐇✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @alexcrtestapp in a new review comment at the desired location with your query. Examples:
    • @alexcrtestapp generate unit testing code for this file.
    • @alexcrtestapp modularize this function.
  • PR comments: Tag @alexcrtestapp in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @alexcrtestapp gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @alexcrtestapp read src/utils.ts and generate unit testing code.
    • @alexcrtestapp read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @alexcrtestapp help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @alexcrtestapp pause to pause the reviews on a PR.
  • @alexcrtestapp resume to resume the paused reviews.
  • @alexcrtestapp review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @alexcrtestapp full review to do a full review from scratch and review all the files again.
  • @alexcrtestapp summary to regenerate the summary of the PR.
  • @alexcrtestapp generate docstrings to generate docstrings for this PR.
  • @alexcrtestapp resolve resolve all the CodeRabbit review comments.
  • @alexcrtestapp configuration to show the current CodeRabbit configuration for the repository.
  • @alexcrtestapp help to get help.

Other keywords and placeholders

  • Add @alexcrtestapp ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @alexcrtestapp summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @alexcrtestapp or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@alexcrtestapp alexcrtestapp bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (3)
sampleTerraformFile.tf (3)

9-15: Ensure explicit, secure defaults for ports and CIDR ranges
Using strings for port values and defaulting the CIDR block to ["0.0.0.0/0"] increases the risk of misconfiguration and unintended exposure. Convert port values to numeric types and consider requiring explicit CIDR input via variables instead of a wide-open default.

Proposed diff:

 locals {
   sg_name    = "checkov-test"
   aws_vpc_id = "vpc-#####" # enter vpc id here
   cidr_block = ["0.0.0.0/0"]
-  from_port  = "80"
-  to_port    = "80"
+  from_port  = 80
+  to_port    = 80
 }

43-48: Egress rule is overly permissive (-1 protocol, all ports)
Allowing all outbound traffic by default increases your attack surface. Consider restricting egress to only the necessary ports and destinations following least‑privilege principles.


68-74: Consider tightening outbound rules for the insecure group
Even for a test group, restricting egress prevents unintended data exfiltration. Define explicit egress rules rather than allowing all traffic.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5fbf32a and 5d7beff.

📒 Files selected for processing (1)
  • sampleTerraformFile.tf (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Security Checks
sampleTerraformFile.tf

[error] 24-24: terraform.aws.security.aws-provider-static-credentials.aws-provider-static-credentials: A hard-coded credential was detected. It is not recommended to store credentials in source-code, as this risks secrets being leaked. Use environment variables or secure vaults instead.

🪛 CircleCI: semgrep
sampleTerraformFile.tf

[error] 24-24: terraform.aws.security.aws-provider-static-credentials.aws-provider-static-credentials: Hard-coded credential detected. Storing credentials in source code risks secrets being leaked. Use environment variables or secure vaults to provide credentials.

Comment on lines +35 to +41
ingress {
description = "Ingress from VPC"
from_port = local.from_port
to_port = local.to_port
protocol = "tcp"
cidr_blocks = local.cidr_block
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ingress rule allows traffic from any IP despite the description
The cidr_blocks = local.cidr_block default of ["0.0.0.0/0"] contradicts the "Ingress from VPC" description and opens port 80 globally. Restrict this to your VPC CIDR or specific IP ranges.

Example using a data source:

data "aws_vpc" "selected" {
  id = var.aws_vpc_id
}

resource "aws_security_group" "this" {
  ingress {
    from_port   = local.from_port
    to_port     = local.to_port
    protocol    = "tcp"
-   cidr_blocks = local.cidr_block
+   cidr_blocks = [data.aws_vpc.selected.cidr_block]
  }
  # ...
}

Comment on lines +60 to +66
ingress {
description = "Allow all TCP traffic"
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
Copy link

@alexcrtestapp alexcrtestapp bot Apr 18, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Insecure security group permitting all TCP ports from the internet
This aws_security_group.insecure resource opens ports 0–65535 to 0.0.0.0/0, undermining network security. Unless strictly required for testing, remove or narrow this rule to specific ports and trusted CIDRs.

Comment on lines +21 to +25
provider "aws" {
region = "us-east-1"
access_key = "AKIA123456789EXAMPLE"
secret_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove hard‑coded AWS credentials from source
Storing access_key and secret_key in your Terraform code risks leaking sensitive credentials. Use environment variables (e.g., AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY), shared credentials files, or a secrets manager.

Proposed refactor:

- provider "aws" {
-   region     = "us-east-1"
-   access_key = "AKIA123456789EXAMPLE"
-   secret_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
- }
+ provider "aws" {
+   region = var.aws_region
+   # credentials supplied via environment variables or shared credentials file
+ }

Let me know if you’d like sample variable definitions and documentation.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
provider "aws" {
region = "us-east-1"
access_key = "AKIA123456789EXAMPLE"
secret_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
}
provider "aws" {
region = var.aws_region
# credentials supplied via environment variables or shared credentials file
}
🧰 Tools
🪛 GitHub Actions: Security Checks

[error] 24-24: terraform.aws.security.aws-provider-static-credentials.aws-provider-static-credentials: A hard-coded credential was detected. It is not recommended to store credentials in source-code, as this risks secrets being leaked. Use environment variables or secure vaults instead.

🪛 CircleCI: semgrep

[error] 24-24: terraform.aws.security.aws-provider-static-credentials.aws-provider-static-credentials: Hard-coded credential detected. Storing credentials in source code risks secrets being leaked. Use environment variables or secure vaults to provide credentials.

Comment on lines +80 to +92
resource "aws_s3_bucket" "public" {
bucket = "checkov-public-bucket-demo-12345"
acl = "public-read" # Vulnerability: Bucket is publicly readable

versioning {
enabled = false
}

# Intentionally not configuring block public access to expose potential risk
website {
index_document = "index.html"
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Public S3 bucket with public‑read ACL and no public access block
This configuration exposes bucket contents publicly and disables protective controls. For production, set acl = "private", enable public_access_block, and turn on versioning.

Proposed diff:

 resource "aws_s3_bucket" "public" {
   bucket = "checkov-public-bucket-demo-12345"
-  acl    = "public-read"
+  acl    = "private"
+  public_access_block {
+    block_public_acls       = true
+    block_public_policy     = true
+    ignore_public_acls      = true
+    restrict_public_buckets = true
+  }

   versioning {
-    enabled = false
+    enabled = true
   }

   # website configuration (only enable if hosting a static site via CloudFront)
   website {
     index_document = "index.html"
   }
 }

Let me know if you’d like a full refactor for private hosting behind CloudFront.

Committable suggestion skipped: line range outside the PR's diff.

@alexcoderabbitai
Copy link
Owner Author

@alexcrtestapp full review

@alexcrtestapp
Copy link

alexcrtestapp bot commented Apr 18, 2025

Tip

For best results, initiate chat on the files or code changes.

@alexcoderabbitai I'll initiate a full review of your PR now. This will attempt to re-analyze all files in your PR from scratch.

I see there was a previous issue with cloning the repository. This full review will try again, but if the problem persists, you might want to:

  • Check that the repository permissions are correctly set up
  • Consider adding path_filters in your .coderabbit.yaml configuration to include only specific files
  • Verify that the repository size and structure are within GitHub's limits

I'll proceed with the full review process now.

@alexcoderabbitai
Copy link
Owner Author

@alexcrtestapp full review

@alexcrtestapp
Copy link

alexcrtestapp bot commented Apr 18, 2025

✅ Actions performed

Full review triggered.

Copy link

@alexcrtestapp alexcrtestapp bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (4)
sampleTerraformFile.tf (4)

21-25: Remove hard‑coded AWS credentials
Storing access_key and secret_key in source code risks leaking sensitive credentials. Use environment variables or a shared credentials file instead per best practices.

🧰 Tools
🪛 GitHub Actions: Security Checks

[error] 24-24: terraform.aws.security.aws-provider-static-credentials.aws-provider-static-credentials: A hard-coded credential was detected. It is not recommended to store credentials in source-code, as this risks secrets being leaked and used by malicious adversaries. Use environment variables or secure vaults instead.

🪛 CircleCI: semgrep

[error] 24-24: terraform.aws.security.aws-provider-static-credentials.aws-provider-static-credentials: Hard-coded AWS credential detected. Storing credentials in source code risks secret leaks. Use environment variables or secure vaults to provide credentials.


35-41: Ingress rule allows traffic from any IP
The cidr_blocks = local.cidr_block default of ["0.0.0.0/0"] contradicts the "Ingress from VPC" description and opens port 80 globally. Restrict this to your VPC CIDR or specific IP ranges.


60-66: Critical: Insecure security group permitting all TCP ports from the internet
This aws_security_group.insecure resource opens ports 0–65535 to 0.0.0.0/0, undermining network security. Unless strictly required for testing, remove or narrow this rule to specific ports and trusted CIDRs.


80-92: Public S3 bucket with public‑read ACL and no public access block
This configuration exposes bucket contents publicly and disables protective controls. For production, set acl = "private", enable public_access_block, and turn on versioning.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5fbf32a and 5d7beff.

📒 Files selected for processing (1)
  • sampleTerraformFile.tf (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Security Checks
sampleTerraformFile.tf

[error] 24-24: terraform.aws.security.aws-provider-static-credentials.aws-provider-static-credentials: A hard-coded credential was detected. It is not recommended to store credentials in source-code, as this risks secrets being leaked and used by malicious adversaries. Use environment variables or secure vaults instead.

🪛 CircleCI: semgrep
sampleTerraformFile.tf

[error] 24-24: terraform.aws.security.aws-provider-static-credentials.aws-provider-static-credentials: Hard-coded AWS credential detected. Storing credentials in source code risks secret leaks. Use environment variables or secure vaults to provide credentials.

🔇 Additional comments (2)
sampleTerraformFile.tf (2)

1-8: No issues detected in the file header comments.


97-105: No issues detected in the Terraform block settings.

Comment on lines +9 to +15
locals {
sg_name = "checkov-test"
aws_vpc_id = "vpc-#####" #enter vpc id here
cidr_block = ["0.0.0.0/0"]
from_port = "80"
to_port = "80"
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Incorrect variable types and insecure defaults in locals.
Defining cidr_block as ["0.0.0.0/0"] opens all traffic, contradicting the intended VPC-only access. Also, from_port and to_port are strings rather than numbers, which may cause type mismatches. Suggest using a data source to retrieve the VPC CIDR and defining ports as numeric values:

 locals {
-  cidr_block = ["0.0.0.0/0"]
-  from_port  = "80"
-  to_port    = "80"
+  cidr_block = [data.aws_vpc.selected.cidr_block]
+  from_port  = 80
+  to_port    = 80
 }

And add:

data "aws_vpc" "selected" {
  id = local.aws_vpc_id
}

Repository owner deleted a comment from alexcrtestapp bot May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant