Skip to content

chore: allow access to RDS from any source #122

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

Closed
wants to merge 4 commits into from

Conversation

hussedev
Copy link
Contributor

@hussedev hussedev commented May 26, 2025

🤖 Linear

Closes PAR-XXX

Description

Checklist before requesting a review

  • I have conducted a self-review of my code.
  • I have conducted a QA.
  • If it is a core feature, I have included comprehensive tests.

Summary by CodeRabbit

  • New Features
    • Added a manual workflow to display detailed Terraform infrastructure state and outputs for selected environments.
  • Bug Fixes
    • Made the RDS instance publicly accessible by updating its network settings.
    • Broadened access to the RDS database port, allowing inbound traffic from any IP address.
    • Enhanced deployment logs to display RDS connection details for easier access and troubleshooting.
    • Added an output variable to expose the RDS endpoint for external referencing.

Copy link

coderabbitai bot commented May 26, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

The changes update Terraform configurations and GitHub workflows related to the RDS instance and infrastructure management. The networking module adds an ingress rule allowing inbound TCP traffic on port 5432 from any IP address. The storage module sets the RDS instance as publicly accessible. A new output variable rds_endpoint is added in the staging environment outputs. The deployment workflow is enhanced to echo the RDS endpoint and a PostgreSQL connection string after applying Terraform. Additionally, a new GitHub Actions workflow is introduced to display the Terraform state and outputs for a selected environment on manual trigger.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ae5d02 and e59deb3.

📒 Files selected for processing (1)
  • .github/workflows/show-terraform-state.yml (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai 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:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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)

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

Other keywords and placeholders

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

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

@coderabbitai coderabbitai 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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 748a198 and b505de2.

📒 Files selected for processing (1)
  • deployment/modules/networking/main.tf (1 hunks)
⏰ Context from checks skipped due to timeout of 300000ms (1)
  • GitHub Check: test / Unit and Integration Tests

Comment on lines +74 to +80
# Allow access from anywhere (0.0.0.0/0)
ingress {
from_port = 5432
to_port = 5432
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Critical security risk: Public RDS exposure
Allowing 0.0.0.0/0 ingress on your RDS security group opens your database to the entire internet, greatly increasing the risk of unauthorized access and data exfiltration. At minimum, you should restrict access to known IP ranges, a bastion host, or VPN. Better yet, parameterize public access so it can be safely disabled in production.

Example refactor to make public ingress optional via a variable:

@@ -74,7 +74,12 @@ resource "aws_security_group" "rds" {
-  ingress {
-    from_port   = 5432
-    to_port     = 5432
-    protocol    = "tcp"
-    cidr_blocks = ["0.0.0.0/0"]
+  # Public access controlled via variable
+  ingress {
+    from_port   = 5432
+    to_port     = 5432
+    protocol    = "tcp"
+    cidr_blocks = var.rds_public_cidr_blocks
+    description = "Optional public RDS access"
  }

Add to your variables file:

variable "rds_public_cidr_blocks" {
  type        = list(string)
  description = "CIDR blocks allowed to access RDS publicly; leave empty to disable public access"
  default     = []
}
🤖 Prompt for AI Agents
In deployment/modules/networking/main.tf lines 74 to 80, the security group rule
allows ingress from 0.0.0.0/0, exposing the RDS instance to the entire internet,
which is a major security risk. To fix this, replace the hardcoded cidr_blocks
value with a variable that controls public access, and set it to an empty list
by default to disable public ingress. Update your variable definitions
accordingly to make the access configurable and safer for production
environments.

Copy link

@coderabbitai coderabbitai 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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b505de2 and 8086355.

📒 Files selected for processing (1)
  • deployment/modules/storage/main.tf (1 hunks)
⏰ Context from checks skipped due to timeout of 300000ms (1)
  • GitHub Check: e2e-tests / E2E Tests

@@ -23,7 +23,7 @@ module "rds" {

maintenance_window = "Mon:00:00-Mon:03:00"

publicly_accessible = false
publicly_accessible = true
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical Security Concern: Exposing RDS to the public Internet
Setting publicly_accessible = true opens your database endpoint to the Internet. Combined with an ingress rule of 0.0.0.0/0 on port 5432, this exposes sensitive data to anyone and violates security best practices. Please consider reverting this change or scoping it behind a controlled variable and locking down CIDRs.

Suggested refactor:

-  publicly_accessible = true
+  publicly_accessible = var.rds_publicly_accessible

And in variables.tf:

+variable "rds_publicly_accessible" {
+  description = "Whether the RDS instance is publicly accessible"
+  type        = bool
+  default     = false
+}

Additionally, enforce tighter network controls (whitelisted CIDRs or VPN/bastion), and enable features like deletion_protection for extra safety.

Would you like help wiring up the variable or locking down the allowed CIDRs?

🤖 Prompt for AI Agents
In deployment/modules/storage/main.tf at line 26, the setting
publicly_accessible is set to true, which exposes the RDS instance to the public
internet. Change this value to false to restrict access, or make it configurable
via a variable that defaults to false. Additionally, review and update the
security group ingress rules to restrict access to trusted CIDRs, avoiding
0.0.0.0/0. Ensure that sensitive data is protected by limiting public exposure.

@hussedev hussedev marked this pull request as draft May 26, 2025 13:44
@hussedev
Copy link
Contributor Author

still need to manage to add the db to a public subnet, as currently is in a private one

Copy link

@coderabbitai coderabbitai 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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8086355 and 532fb3b.

📒 Files selected for processing (1)
  • .github/workflows/upgrade-current-deployment-infra.yml (1 hunks)
⏰ Context from checks skipped due to timeout of 300000ms (1)
  • GitHub Check: e2e-tests / E2E Tests

Comment on lines +79 to +83

# Display RDS connection information
echo "=== RDS Connection Information ==="
echo "RDS Endpoint: $(terraform output -raw rds_endpoint)"
echo "Connection String: postgresql://${{ secrets.DATALAYER_PG_USER }}:${{ secrets.DATALAYER_PG_PASSWORD }}@$(terraform output -raw rds_endpoint)/GitcoinDatalayer{{Green|Blue}}"
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Avoid exposing credentials in logs & correct the placeholder
Echoing the full connection string (including ${{ secrets.DATALAYER_PG_PASSWORD }}) risks leaking sensitive data—even if GitHub masks secrets—and the literal {{Green|Blue}} will not resolve to the active environment. Instead, mask or omit the password in the log and interpolate the ${active_deployment} shell variable for the database name.

Suggested diff:

-                  # Display RDS connection information
-                  echo "=== RDS Connection Information ==="
-                  echo "RDS Endpoint: $(terraform output -raw rds_endpoint)"
-                  echo "Connection String: postgresql://${{ secrets.DATALAYER_PG_USER }}:${{ secrets.DATALAYER_PG_PASSWORD }}@$(terraform output -raw rds_endpoint)/GitcoinDatalayer{{Green|Blue}}"
+                  # Display RDS connection information (password masked)
+                  echo "=== RDS Connection Information ==="
+                  echo "RDS Endpoint: $(terraform output -raw rds_endpoint)"
+                  echo "Connection String: postgresql://${TF_VAR_DATALAYER_PG_USER}:****@$(terraform output -raw rds_endpoint)/${active_deployment}"
📝 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
# Display RDS connection information
echo "=== RDS Connection Information ==="
echo "RDS Endpoint: $(terraform output -raw rds_endpoint)"
echo "Connection String: postgresql://${{ secrets.DATALAYER_PG_USER }}:${{ secrets.DATALAYER_PG_PASSWORD }}@$(terraform output -raw rds_endpoint)/GitcoinDatalayer{{Green|Blue}}"
# Display RDS connection information (password masked)
echo "=== RDS Connection Information ==="
echo "RDS Endpoint: $(terraform output -raw rds_endpoint)"
echo "Connection String: postgresql://${TF_VAR_DATALAYER_PG_USER}:****@$(terraform output -raw rds_endpoint)/${active_deployment}"
🤖 Prompt for AI Agents
In .github/workflows/upgrade-current-deployment-infra.yml around lines 79 to 83,
the script echoes the full database connection string including the secret
password, which risks exposing sensitive credentials in logs, and the
placeholder {{Green|Blue}} is not dynamically replaced. Remove or mask the
password from the echoed connection string to prevent credential leaks, and
replace the placeholder with the actual environment variable that specifies the
deployment name, such as ${active_deployment}. Ensure the connection string logs
only non-sensitive information and correctly references environment variables.

@hussedev hussedev force-pushed the chore/allow-access-to-db branch from 532fb3b to 5ae5d02 Compare May 26, 2025 14:13
@hussedev hussedev closed this May 28, 2025
@hussedev hussedev deleted the chore/allow-access-to-db branch May 28, 2025 03:26
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