How to Integrate CircleCI and RDS Postgres Safely

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams pair circleci and rds postgres to run schema changes and tests during builds. A build runner connects to the database, runs SQL tasks, and returns the status. This setup speeds up code delivery for engineering teams. Still, it also exposes your database to external build runners. You must lock down keys, network paths, and database roles before running production jobs. How circleci and rds postgres work together In a standard pipeline, the build runner starts a container when code chan

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Teams pair circleci and rds postgres to run schema changes and tests during builds. A build runner connects to the database, runs SQL tasks, and returns the status.

This setup speeds up code delivery for engineering teams. Still, it also exposes your database to external build runners. You must lock down keys, network paths, and database roles before running production jobs.

How circleci and rds postgres work together

In a standard pipeline, the build runner starts a container when code changes. This runner needs a network path and a valid key to reach the database. Once logged in, the runner applies schema updates or checks data states.

Database admins control what the build runner can do through roles. You can set up group roles to manage permissions across many users and jobs. You then grant specific build accounts membership in the right group role.

When a job only needs to read data, you grant the SELECT privilege. This privilege allows reading from any column or specific columns of a table. It also works on views and materialized views, and it allows copying data out.

Admins also need to watch default permissions on the database. The special PUBLIC role grants rights to every role on the system. By default, PUBLIC gets rights to connect to databases and make temporary tables. It also gets the right to run functions and procedures. The database owner can revoke these defaults to keep build runners restricted.

Common failure modes in build pipelines

Many teams use one master database account for every build pipeline. This choice creates a huge risk if a build log leaks the password. Anyone with that key can drop tables or read private customer data.

Broad network access is another common mistake with cloud build runners. Cloud runners often use changing IP addresses across wide ranges. Opening your database firewall to the whole internet invites constant attacks. Instead, teams should run build jobs inside a private network or use peering.

End-to-End Encryption + CircleCI Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Older database setups also hide risky schema permissions. In PostgreSQL 15 and later, regular users cannot create objects in the public schema. Older versions, or upgraded databases, still let every user create objects there by default. An admin must fix this by revoking create rights on the public schema from PUBLIC.

Unlogged queries also hurt security during automated deploys. When five pipelines share one login, the database log shows the same user name. You cannot tell which commit or developer ran a broken query. Giving each pipeline a distinct role with tight permissions solves part of this problem.

Scoping database roles for safer automation

Start by splitting read jobs from write jobs in your pipeline. Validation jobs only need to read specific columns to check data health. Granting column-level read rights stops test jobs from pulling emails or card numbers. Data masking can also rewrite matched fields like phone numbers or national IDs in results.

Migration jobs need rights to alter tables, so keep them in separate steps. Trigger those steps only after a human reviews the code on the main branch. Rotate the passwords for these roles often so old build logs hold dead keys.

Finally, strip out every default permission that your build runner does not need. Revoke connect and function execution rights from the PUBLIC role on sensitive databases. Grant those rights back only to the exact group roles that require them. This keeps every automated run inside a small, safe box.

Add query and result controls beside Postgres

Grants and pools govern who logs into PostgreSQL. Yet every query in an open session still runs with that role's full scope. In practice, hoop.dev runs beside your database as a sidecar for your Postgres. It reads plain and prepared queries on the wire with no change to your users or drivers.

When a tool or agent sends SQL, hoop.dev Postgres controls check each statement against your deny rules. An AI Analyzer you configure can also score intent or hold a risky query for human review. Matched sensitive columns in result rows are masked in memory before they reach the caller. Each query and decision is logged per listener, which generates evidence for SOC 2, HIPAA, and GDPR audits. View the binary on GitHub.

Frequently asked questions

How do I limit a CircleCI job to reading specific Postgres columns?

Create a dedicated role for the build job and grant the SELECT privilege. You can grant SELECT on specific columns of a table or view. This prevents the runner from reading sensitive columns in the same table.

Why can my read-only build user still create tables in the public schema?

Databases created before PostgreSQL 15 let the PUBLIC role create objects in the public schema. If you upgraded an older database, that old rule stays in place. An admin must revoke create permissions on the public schema from the PUBLIC role.

What default permissions does every Postgres role get through PUBLIC?

By default, the PUBLIC role gets rights to connect to databases and create temporary tables. It also receives the right to execute functions and procedures. The object owner can revoke any of these default rights to tighten security.

The query runs. The emails stay hidden.