Skip to content

feat(db): activate Todo row-level security#598

Merged
tiankaima merged 6 commits into
mainfrom
agent/rls-todo-activation-20260722
Jul 22, 2026
Merged

feat(db): activate Todo row-level security#598
tiankaima merged 6 commits into
mainfrom
agent/rls-todo-activation-20260722

Conversation

@tiankaima

Copy link
Copy Markdown
Member

Part of #550

Summary

  • activate and force PostgreSQL RLS on Todo with matching USING and WITH CHECK owner policy
  • add a dedicated CI phase that creates a non-owner NOINHERIT NOBYPASSRLS runtime role and grants only runtime table access
  • prove default-deny without context, concurrent A/B isolation, forged-owner rejection, context reset, and role attributes against a real PostgreSQL database

Deployment order

This follows the already-merged inactive context plumbing in #596. It deliberately remains separate so the application context is deployed before policy activation. It does not close #550; the remaining table families need their own policy matrices.

Verification

  • fresh PostgreSQL migration replay + seed + runtime-role integration test: 3/3 passed locally
  • bunx vitest run tests/unit/rls-context.test.ts tests/unit/todo-service-delete.test.ts: 8/8
  • full unit suite on the activation commit: 235 files / 1439 tests (previous local run)

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 22, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
life-ustc 60c85c4 Commit Preview URL

Branch Preview URL
Jul 22 2026, 10:05 AM

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR activates PostgreSQL row-level security (RLS) for the Todo table and adds a dedicated CI job to validate default-deny behavior and per-user isolation using a non-owner, NOBYPASSRLS runtime role—aligning with the staged rollout plan in #550 / #596.

Changes:

  • Enable and force RLS on Todo, adding an owner-isolation policy that ties row access to app.user_id.
  • Add an integration test that exercises default-deny, concurrent user isolation, forged-owner rejection, and runtime role attributes.
  • Introduce a dedicated ci:rls workflow phase/job that runs the test suite under a locked-down runtime role with only table-level grants.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
prisma/migrations/20260722163000_todo_owner_rls/migration.sql Enables + forces RLS on Todo and adds a strict owner-matching USING/WITH CHECK policy keyed on app.user_id.
tests/integration/todo-rls.test.ts Adds a DB-backed integration test proving default-deny, isolation between two seeded users, and forged ownership rejection.
.github/workflows/db-backed-bun-job.yml Adds a new ci:rls phase that creates a non-owner NOINHERIT NOBYPASSRLS runtime role, grants minimal schema/table access, and runs only the RLS test under that role.
.github/workflows/ci.yml Wires a new “PostgreSQL RLS Isolation Test” CI job that runs the ci:rls phase.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/integration/todo-rls.test.ts Outdated
Comment thread .github/workflows/db-backed-bun-job.yml Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 09:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread tests/integration/todo-rls.test.ts Outdated
Comment thread tests/integration/todo-rls.test.ts Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 09:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 22, 2026 09:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread .github/workflows/db-backed-bun-job.yml
@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

Copilot AI review requested due to automatic review settings July 22, 2026 09:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread .github/workflows/db-backed-bun-job.yml Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 10:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@tiankaima
tiankaima merged commit 5b16b66 into main Jul 22, 2026
18 checks passed
@tiankaima
tiankaima deleted the agent/rls-todo-activation-20260722 branch July 22, 2026 10:16
github-actions Bot pushed a commit that referenced this pull request Jul 22, 2026
# [1.76.0](v1.75.0...v1.76.0) (2026-07-22)

### Features

* **db:** activate Todo row-level security ([#598](#598)) ([5b16b66](5b16b66))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.76.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rfc(data): pilot PostgreSQL RLS with Prisma and Hyperdrive

2 participants