Repository navigation
fix(db): grant service_role the eight tables it could not read, and stop search_path drifting - #725
Merged
Merged
Conversation
…top search_path drifting Two grant/definition gaps, both reproduced against a live database before and after. **#481 — eight core tables service_role cannot read.** `service_role` is the bypass-everything role, and edge-function code reaches for the service client whenever it needs to read past RLS. These eight were readable by `authenticated` (three also by `anon`) and not by `service_role` at all, so that client got a GRANT error — which fires before RLS is even evaluated: { code: "42501", message: "permission denied for table soft_skills" } All eight have RLS enabled with policies already written, so it is the same omission migrations 332 (api_keys) and 335 (scheduling) fixed: the policies were authored, the table-level GRANTs beneath them were not. A policy cannot widen access past an absent GRANT. `core.soft_skills` is the clearest case — public reference data seeded by migration 001, with a public-read policy for anon and authenticated. It is also where this bit: GET /v1/profiles/:username had to resolve skill names with the caller's client because the service client could not read the catalog (see `resolveSkillNames`, #464). Migration 352 grants service_role only. anon and authenticated are untouched, verified after: soft_skills and portfolio_items still anon+authenticated, archetypes still authenticated. The issue's own detection query now returns nothing. **#468 — ten functions with no search_path.** Migration 308 set one on every owned function in core/data/community/onet/public. Ten had none, because migrations 314-325 created them after 308 ran. Nine are trigger functions plus core.tasks_handle_completion, so today's risk is low — but a function without an explicit search_path resolves unqualified names against whatever the caller's search_path happens to be, and "it is only a trigger function" is not a property that stays true. Migration 353 sets them, as explicit ALTERs against real signatures rather than another positional DO-sweep. A sweep is one-shot by construction — it covers what exists when it runs and nothing after — which is exactly how these drifted unnoticed for eleven migrations. The count the issue asks about is now 0. **The half that matters more:** scripts/check-migrations.mjs, wired into `pnpm lint` and prepush, fails the build when a migration above 353 creates a function without a search_path. So there is no twelfth. It is exercised rather than assumed — the first version was decorative. Its regex read `(?:or\s+replace\s+)+?`, requiring at least one occurrence, so a plain `CREATE FUNCTION` (the usual form for a new function, and the only form this guard exists to catch) passed straight through. Caught by probing it with a deliberate offender instead of trusting a green run over zero files. Now verified against five cases: plain CREATE without a path fails, CREATE OR REPLACE without a path fails, a path in the header passes, a path mentioned only in the body fails, and a function in an unowned schema is out of scope. The same script also fails on two migrations sharing a number. That is not hypothetical either: #723 landed 351_drop_redundant_review_link_policies.sql while this branch was writing its own 351, and git merges both files without a conflict — leaving migration order to whatever the filesystem returns. Mine are renumbered to 352 and 353. Closes #481 Closes #468 Co-Authored-By: Claude Opus 5 <[email protected]>
This was referenced Sep 10, 2026
Scaffald/sdk#22 points sdk's tsx/tsup/typescript/vitest at the workspace catalog. Only tsx actually moves: it declared `^4.7.0` and resolved to 4.22.3, which does not satisfy the catalog's `~4.19.3`, so the lockfile carried both that and the 4.19.4 that packages/ai-pipeline gets through `catalog:`. `pnpm dedupe --check` — what Monorepo integrity runs — fails on that split. It is invisible on main because the check is gated on the deps paths filter, so only a PR touching a package.json ever runs it, and this PR's two-line script addition was the first in a while. tsx now resolves to 4.19.4 and `pnpm dedupe --check` exits 0. Co-Authored-By: Claude Opus 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two grant/definition gaps, both reproduced against a live database before and after.
#481 — eight
coretablesservice_rolecannot readservice_roleis the bypass-everything role, and edge-function code reaches for the service client whenever it needs to read past RLS. These eight were readable byauthenticated(three also byanon) and not byservice_roleat all, so that client got a GRANT error — which fires before RLS is even evaluated:All eight have RLS enabled with policies already written, so it is the same omission migrations 332 (
api_keys) and 335 (scheduling) fixed: the policies were authored, the table-level GRANTs beneath them were not. A policy cannot widen access past an absent GRANT.core.soft_skillsis the clearest case — public reference data seeded by migration 001, with a public-read policy for anon and authenticated. It is also where this bit:GET /v1/profiles/:usernamehad to resolve skill names with the caller's client because the service client could not read the catalog (seeresolveSkillNames, #464).Migration 352 grants
service_roleonly.soft_skills/portfolio_itemsfor anon+authenticatedarchetypesfor authenticated#468 — ten functions with no
search_pathMigration 308 set one on every owned function in
core/data/community/onet/public. Ten had none, because migrations 314–325 created them after 308 ran.Nine are trigger functions plus
core.tasks_handle_completion, so today's risk is low — but a function without an explicitsearch_pathresolves unqualified names against whatever the caller'ssearch_pathhappens to be, and "it is only a trigger function" is not a property that stays true.Migration 353 sets them, as explicit
ALTERs against real signatures rather than another positionalDO-sweep. A sweep is one-shot by construction — it covers what exists when it runs and nothing after — which is exactly how these drifted unnoticed for eleven migrations. The count the issue asks about is now 0.The half that matters more
scripts/check-migrations.mjs, wired intopnpm lintand prepush, fails the build when a migration above 353 creates a function without asearch_path. So there is no twelfth.It is exercised rather than assumed — the first version was decorative. Its regex read
(?:or\s+replace\s+)+?, requiring at least one occurrence, so a plainCREATE FUNCTION— the usual form for a new function, and the only form this guard exists to catch — passed straight through. It was reporting "✓" over zero files, which is the same shape as the bugs the last two sessions were spent removing, so I probed it with a deliberate offender instead of trusting the green.Now verified against five cases:
CREATE FUNCTION, no pathCREATE OR REPLACE, no pathsearch_pathmentioned only in the bodyAlso: two migrations sharing a number
The same script fails on duplicate migration numbers. Not hypothetical — #723 landed
351_drop_redundant_review_link_policies.sqlwhile this branch was writing its own351. Git merges both files without a conflict, and migration order becomes whatever the filesystem returns. Concurrent branches make this likely rather than exotic.Mine are renumbered to 352 and 353, and the check now covers all 189 migrations.
Closes #481
Closes #468