Repository navigation
docs+test(auth): record and test why grants are readable without request context - #77
Merged
Merged
Conversation
U-2 opens SELECT on member_roles to app_rls unconditionally, an exception to "enforce in the database" (3.4). Record the reason, what stays restricted, what it obliges the API to do, and the alternatives that were rejected, so the decision is findable outside the migration comment. Also reconcile 3.2 with share/permissions.ts: the list in the code is the subset it refers to by name, not a second source of truth. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vm1iXpgdwQfcWuyNzX9KF7
Contributor
Author
|
落ちているのは
修正案(未適用): docs だけの PR に依存関係の更新を混ぜないよう、修正は Generated by Claude Code |
The assertion that grants are readable ran with the member's own context set, so a policy scoped to the member's own rows passed it too. Narrowing the policy back would have left every caller with no permissions while the suite stayed green: nothing else reads member_roles as app_rls without context (the migration test reads as superuser, the join test uses its own tables). Clear the context before the read and restore it after. The assertion count is unchanged. Verified against PGlite with the migrations replayed: with no context set, the current policy returns the grant and the old self-only policy returns nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vm1iXpgdwQfcWuyNzX9KF7
…ude/epic-wright-9zzc8u
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.
#76 の補足 PR です。マージ先は
feat/permission-checksです。背景
#76 で
member_rolesの SELECT をusing (true)に緩めました。これは 3.4「アプリではなくデータベース側で守る」の例外にあたります。それにもかかわらず、理由は migration のコメントにしか書かれていませんでした。さらに、この変更を守るテストもありませんでした。変更
1. 設計記録(
docs/aidlc/components.md)3.5 を追加:「ロールの付与情報はデータベースで絞らない」という決定を記録しました。
app.current_member_idがまだ設定されていません。また、app_accounts.roleは既に無条件で読めるので、絞っても守れるものがほぼありませんmember_rolesを参照してかまいません3.2 の矛盾を解消:3.2 の「コード側に権限の一覧を持たない」は、
share/permissions.tsと矛盾していました。そこで、あの一覧は正典ではなく、コードが名前で参照する部分集合であると追記しました。2. pgTAP(
supabase/tests/004_roles.test.sql)付与が読めることを確かめる assert は、部員本人の文脈が設定された状態で実行されていました。そのため、本人の行だけを見せるポリシーに戻しても通ってしまいます。ほかに
app_rlsとして文脈なしでmember_rolesを読むテストもありません(migration のテストはスーパーユーザーで読み、join のテストは自前のテーブルを使っています)。つまり、ポリシーを戻すと全員の権限がゼロになるのに、テストはすべて通る状態でした。そこで、ミドルウェアと同じく文脈を空にしてから読み、読んだ後に元の文脈に戻すようにしました。assert の数は変わらないため、
planもそのままです。検証:この環境では Docker が使えないため、pgTAP そのものは CI の
databasejob で確認することになります。代わりに PGlite に migration を流し込み、文脈を設定しない状態で読み取りを試しました。今のポリシーでは付与が 1 行見え、元のポリシーに戻すと 0 行になることを確認しています。pgtap-plan.test.tsを含む member のテストは 23 件すべて成功しました。CI について
memberとapplicationの失敗は、この PR の変更が原因ではありません(依存パッケージの audit が原因です。コメント参照)。修正は #78 で develop に出しています。🤖 Generated with Claude Code
https://claude.ai/code/session_01Vm1iXpgdwQfcWuyNzX9KF7