How to Integrate Jenkins and RDS Postgres Safely

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams pair jenkins and rds postgres to run database changes and tests during builds. A build worker connects to the database, runs SQL tasks, and logs the output. This setup speeds up app delivery for engineering teams. Still, it also creates risks if build jobs hold broad database rights. A safe setup needs tight roles, clear logs, and locked network paths. How jenkins and rds postgres share data and roles In a standard pipeline, a build worker starts a job and reads stored credentials. The

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 jenkins and rds postgres to run database changes and tests during builds. A build worker connects to the database, runs SQL tasks, and logs the output.

This setup speeds up app delivery for engineering teams. Still, it also creates risks if build jobs hold broad database rights. A safe setup needs tight roles, clear logs, and locked network paths.

How jenkins and rds postgres share data and roles

In a standard pipeline, a build worker starts a job and reads stored credentials. The worker opens a network session to the cloud database over a private subnet. It logs in as a specific database user to run schema updates or checks.

PostgreSQL uses roles to control what that build user can read or change. You can set up group roles to manage rights when you have many users. Individual users then gain membership in the group role to inherit those exact rights.

For jobs that only verify data, you can grant the SELECT privilege. This right allows reading from any column, or specific columns, of a table. It also works on views and materialized views, and it allows exporting data.

Database admins must also watch out for built-in default rights on the server. The special role name PUBLIC grants a privilege to every role on the system. By default, PUBLIC gets rights to connect and make temporary tables on databases. It also gets the right to run functions and procedures unless the owner revokes them.

In PostgreSQL 15 and later, regular users cannot create objects in the public schema. Older or upgraded databases still allow this unless an admin revokes that right from PUBLIC.

Common failure modes in build database access

Many teams use one shared admin account for all their build pipelines. If a bad script runs in a build, it can drop production tables. Shared accounts also make it hard to see which job ran a bad query.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Static passwords stored in build servers create another big risk for teams. People copy these secrets across jobs, and they rarely rotate them on time. If an attacker reads the build server files, they get full database access.

Unlogged queries and raw test data cause audit issues as well. A test job might read a table that holds real customer emails or phone numbers. Without data masking to rewrite matched fields in results, sensitive data leaks into build logs.

Scoping database roles and network paths

Start by splitting your build roles by task instead of using one login. Give schema migration jobs a role that only alters tables in one target schema. Give test verification jobs a read-only role scoped to safe columns.

Lock down the network path between your build workers and the database subnet. Only allow traffic from specific worker nodes on the exact database port. Never place the database on a public subnet just to let cloud builders reach it.

Finally, revoke default rights from the PUBLIC role on every sensitive database. Make sure each build role only holds the exact privileges needed for its single task. Keep cloud identity rules tight so build workers cannot touch other database instances.

Run guardrails and masking on the Postgres connection

Role grants and firewall rules are needed setup. Setup alone cannot check single SQL statements or mask sensitive rows in a response. By design, hoop.dev is an open-source proxy that sits beside Postgres, RDS, or Aurora as a sidecar for your Postgres. Clients and agent tools keep their credentials and point their connection string at the listener.

On each query, hoop.dev guardrails refuse disallowed drops, deletes, or table reads before they run. Next, hoop.dev data masking rewrites sensitive fields in returned rows that match your rules. Furthermore, hoop.dev holds SOC 2 Type II and logs every statement and verdict per resource. Check out the project on GitHub.

Frequently asked questions

Should build jobs use the master database user?

No, never use the master user for automated jobs. Create separate roles for migrations and read-only checks to limit damage from bad scripts.

How can I restrict a test job to read only certain columns?

Grant the PostgreSQL SELECT privilege on specific columns of a table instead of the whole table. This stops the build job from reading other columns on that same table.

Why can a new read-only build role still run database functions?

PostgreSQL grants EXECUTE on functions and procedures to the PUBLIC role by default. The object owner must revoke those default privileges from PUBLIC to block execution.

The query runs. The emails stay hidden.