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:

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

  • Collaborative content (Comment, Homework, Description, attachments): 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 (completed families above).
  • Route every protected access path through the correct transaction/service context before activation (uploads, subscriptions, homework completion, reactions).
  • Add default-deny, cross-user concurrency, forged-owner, delete/cascade, and connection-reset tests per family (upload/subscription/homework/reaction integration suites).
  • 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 (uploads, subscriptions, homework completion, reactions, USTC identity).
  • Complete collaborative content and catalog/importer verification; keep Better Auth on auth runtime only.

References: #550, #596, #598, #599, #600, #604, #701, #702.

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

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions