Skip to content

roadmap(data): complete PostgreSQL RLS rollout by access family #601

Description

@tiankaima

Context

#550 completed the Prisma/Hyperdrive pilot and production activation for the first pure-owner families. This follow-up tracks the remaining business tables without treating policy count as the goal.

Already enforced in production with ENABLE + FORCE ROW LEVEL SECURITY:

  • Todo
  • DashboardLinkClick
  • DashboardLinkPin
  • BusUserPreference

The runtime pattern is a short interactive Prisma transaction, transaction-local set_config('app.user_id', ..., true), and all protected queries on the exact transaction client. CI uses a dedicated LOGIN NOINHERIT NOBYPASSRLS role.

Remaining access families

  • Uploads: owner-only pending/write paths, but published/referenced uploads need narrowly defined public reads. Do not apply a blanket owner SELECT policy.
  • Homework completion: owner writes coexist with public profile contribution aggregates. Move the public aggregate to a narrow view/function or remove it before owner-only SELECT.
  • Collaborative content: define anonymous, authenticated, soft-banned, moderator, and admin matrices before policies.
  • Better Auth tables: use a separate auth-service database identity because many queries happen before an end-user identity exists.
  • Catalog/importer tables: enforce role grants for read-only runtime/importer ownership; avoid meaningless USING (true) policies.

Hyperdrive / operations

  • Provision a least-privilege production runtime role with NOBYPASSRLS; application owner/migration credentials remain separate.
  • Bind auth-sensitive traffic to a cache-disabled Hyperdrive configuration. Hyperdrive currently caches only queries whose functions are immutable, so current_setting policy reads should not be cacheable, but the explicit binding avoids relying on that implementation detail.
  • Never use session-scoped SET with transaction pooling; identity must be transaction-local.

Acceptance criteria

  • Inventory every business table and assign one access family plus owner/service/migration roles.
  • Add raw SQL migrations with both USING and WITH CHECK where applicable.
  • Route every protected access path through the correct transaction/service context before activation.
  • Add default-deny, cross-user concurrency, forged-owner, delete/cascade, and connection-reset tests per family.
  • Add public-read regression tests for uploads and contribution aggregates.
  • Provision and verify production runtime/auth/importer roles and Hyperdrive bindings.
  • Roll out family by family with migration and rollback notes; do not activate mixed-access tables until their matrices are reviewed.

References: #550, #596, #598, #599, #600.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: dataPrisma, migrations, seed/import pipelines, transactions, and persistence invariantsarea: infrastructureProduction runtime, Cloudflare, storage, containers, deployment, and releasesenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions