Skip to content

fix(db): correct backend_reader grants to real indexer tables (#1524) - #1672

Open
ogaziedaniel80-droid wants to merge 1 commit into
crackedstudio:masterfrom
ogaziedaniel80-droid:fix/1524-backend-reader-role-grants
Open

ogaziedaniel80-droid wants to merge 1 commit into
crackedstudio:masterfrom
ogaziedaniel80-droid:fix/1524-backend-reader-role-grants

Conversation

@ogaziedaniel80-droid

Copy link
Copy Markdown
Contributor

Problem

Closes #1524

db/baseline-schema.sql granted SELECT to backend_reader on 'raffle'
and 'participant'. Neither table exists. Because every grant was wrapped
in IF EXISTS, the block silently did nothing — the ownership boundary
from #1468 was completely unenforced in every environment.

Changes

File What changed
db/baseline-schema.sql Replace phantom table names with the 12 real names (sourced from @Entity(...) decorators). Replace silent IF EXISTS skip with RAISE WARNING ... CONTINUE so missing tables are visible.
indexer/.../1780000000000-GrantBackendReaderRole.ts New TypeORM migration that applies the correct grants at deploy time. Throws a hard error (not a silent skip) if any listed table is absent, so future drift is caught immediately.
indexer/.../helpers/all-migrations.ts Register the new migration in the canonical ordered list.
indexer/.../migration-smoke.integration.spec.ts Add the new migration name to the ordered assertion.
indexer/.../backend-reader-role.integration.spec.ts New acceptance test: spins up Testcontainers Postgres, creates backend_reader_login with the role granted, asserts SELECT COUNT(*) passes and INSERT … DEFAULT VALUES is rejected with PG error 42501 (insufficient_privilege) on every indexer-owned table.

Testing

cd indexer && npx jest --config jest.integration.config.js

New spec: backend-reader-role.integration.spec.ts — SELECT allowed / INSERT denied for all 12 tables.

Acceptance criteria (from #1524)

  • backend_reader is granted SELECT on every real indexer-owned table
  • A write attempt is rejected (INSERT returns 42501)
  • A test proves it

…dstudio#1524)

The DO $$ block in db/baseline-schema.sql was granting SELECT on
'raffle' and 'participant', neither of which exist. Because every
GRANT was wrapped in IF EXISTS, the block silently did nothing,
leaving the ownership boundary from crackedstudio#1468 completely unenforced.

Changes:
- db/baseline-schema.sql: replace the two phantom table names with
  the 12 real names sourced from each @entity(...) decorator; swap
  the silent IF-EXISTS skip for RAISE WARNING so missing tables are
  visible rather than swallowed.
- indexer migration 1780000000000-GrantBackendReaderRole: applies
  the correct grants at deploy time; throws a hard error (not a
  silent skip) if any listed table is absent when it runs.
- all-migrations.ts: register the new migration in canonical order.
- migration-smoke.integration.spec.ts: add the new migration name to
  the ordered assertion.
- backend-reader-role.integration.spec.ts (new): spins up a
  Testcontainers Postgres instance, creates a backend_reader_login
  user with the role granted, then asserts SELECT succeeds and INSERT
  is rejected with PG error 42501 on every indexer-owned table.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[repo] The backend read-only grant targets tables that do not exist

1 participant