Automated Deployment with RLS Preservation

Published
Length
3 min read

Luis Felipe Dias

All posts

You run automated deployment with rls preservation by tracking row rules in version control. Your build tool then checks and applies those rules during every database update. Most teams use migration tools to push table changes from test to live databases. If the build role has broad rights, a bad script can drop row rules. This mistake exposes private tenant rows to every app user right away. How automated deployment with rls preservation works Row level security restricts which rows a user

Automated Deprovisioning + Deployment Approval Gates: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

You run automated deployment with rls preservation by tracking row rules in version control. Your build tool then checks and applies those rules during every database update. Most teams use migration tools to push table changes from test to live databases. If the build role has broad rights, a bad script can drop row rules. This mistake exposes private tenant rows to every app user right away.

How automated deployment with rls preservation works

Row level security restricts which rows a user or app role can read or write. Databases store these row rules alongside tables and views inside each schema. When a team updates a table, the migration tool compares the old and new schemas. If the tool recreates a table from scratch, the database drops the attached row rules.

To keep row rules safe, engineers store rule definitions in the same source folder as tables. The build pipeline runs a diff check before it pushes any change to production. The migration runner reads the target state and alters the table in place when possible. If the runner must rebuild a table, it reattaches the row rules inside one transaction. If any step in that transaction fails, the database rolls back the whole update.

Teams also run automated tests against a staging database before the live release starts. These tests log in with limited app roles and try to read forbidden rows. If the test reads rows from another tenant, the pipeline stops the release right away. This workflow keeps row rules intact across every schema change.

Why schema checks alone leave a live session gap

Tracking row rules in source control stops accidental rule drops during code releases. It makes sure that standard app roles keep their row filters after every deploy. Still, migration pipelines need high database rights to alter tables and manage row rules. Engineers also need direct database sessions to fix broken deploys or check live data.

Native database roles decide who can log in and which tables they can alter. Many superuser and schema owner roles bypass row level security by default. When a build runner or engineer logs in with an admin role, row rules do not apply. A single query or bad script in that session can read or delete every row.

Automated Deprovisioning + Deployment Approval Gates: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Schema checks only verify the static rules stored inside the database catalog. They do not inspect what individual queries do during a live admin session. They also cannot mask sensitive fields like emails, phone numbers, card numbers, or national IDs. When an engineer queries a table to debug a deploy, raw data returns in full. Static role setups cannot require peer approval for a single risky command in flight.

How to protect live data during database updates

Teams reduce this risk by splitting schema owner roles from daily human roles. The build runner gets a role that can alter schemas only during scheduled release windows. Human engineers log in with roles that enforce row rules and block table drops. Even with split roles, teams still need visibility into every query run during a fix.

Good operational habits pair versioned row rules with strict query controls on live sessions. Every statement should leave a clear log tied to the person who ran it. Sensitive columns should have masking rules that rewrite matched fields in query results. Risky commands that alter schemas or bypass filters should pause for a quick team review.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev sits inline in the protocol beside each supported service as an open-source proxy, a sidecar for your database or API. For every query or command an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human approval.

First, hoop.dev guardrails block banned queries before they run or hold risky ones for review, and hoop.dev data masking rewrites matched sensitive values in responses in memory. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Why do database migrations drop row level security rules?

Some migration tools rebuild a table to change a column type or constraint. When the tool drops the old table, the database also drops its attached row rules. You must include the row rule scripts in your migration so they get recreated.

Do database admin roles follow row level security rules?

No, most database superusers and table owners bypass row level security by default. They can read and write all rows even when row rules are active on the table. Teams must restrict who can log in with these high power roles.

How can we test if row rules survived a deployment?

Add an automated check to your pipeline that runs right after the schema update. Have the test log in as a standard tenant role and query the updated table. Verify that the query returns only allowed rows and blocks cross-tenant reads.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.