Skip to content

docs(aidlc): let the database decide permissions from the user ID alone - #81

Merged
yufoxda merged 2 commits into
developfrom
claude/epic-wright-9zzc8u-authz
Nov 5, 2026
Merged

yufoxda merged 2 commits into
developfrom
claude/epic-wright-9zzc8u-authz

Conversation

@yufoxda

@yufoxda yufoxda commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

権限の決め方についての設計変更を、ドキュメントに記録する PR です。2026-11-01 に依頼者が決定した内容で、コードの変更はありません。

背景:前の説明は、守れる範囲を大きく書きすぎていた

C-4 と U-2.5 は「アプリが申告した役割を、データベースが実際の値と突き合わせる。アプリが侵害されても権限を偽装できない」と説明していました。確かめたところ、この方式で防げるのはアプリのバグだけでした。

  • 突き合わせるのは「申告された人の ID と役割が、表と一致するか」です。乗っ取られたアプリが本物の管理者の ID を申告すれば一致してしまいます
  • アプリ(app_rls)は app_accounts を更新でき(split_auth_schema.sql:79)、role 列も制限されていません。突き合わせ先そのものを書き換えられます

既存の members の突き合わせ(enforce_member_workflow)も同じで、守れているのはバグだけです。

決めたこと

  1. アプリの乗っ取りは、データベースの保証の対象外とする。 乗っ取りはアプリ側で防ぎます(依存パッケージを最新に保つ、秘密情報を管理する)
  2. アプリは役割を申告しない。 データベースに伝えるのはユーザー ID だけで、権限はデータベースが調べます(app_private.has_permission(ユーザー ID, '権限名'))。申告そのものがなくなるので、「申告を間違える」バグが起こりません
  3. U-2.5 を U-3 に統合する。 RLS を書き換える U-3 で一緒に行うのが自然なためです
  4. community は、member が調べた権限を使う。 U-10 で分けた後、community は member_roles を読めません。権限を計算する場所は member の 1 か所に限ります。受け取り方は U-11 で決めます

変更したファイル

ファイル 変更
requirements.md C-4 を書き換え、範囲を追記。改訂後の C-4 は U-3 で満たすと明記(今のコードはまだ申告を信じている)
unit-of-work.md U-2.5 を欠番にし、前の説明を訂正。U-3 に「データベースへ伝えるもの」を追記。U-10・U-11 に community の扱いを追記。順序と運用開始の条件を更新。承認欄に今回の決定を追記
components.md 3.3(RLS の判定方法)と 3.5(付与の制限)の U-2.5 への参照を更新
README.md 次の単位を U-3 に変更

FR-5.3(ロールの変更履歴)は、予定どおり U-5 で作るものとして残しています。


Generated by Claude Code

claude and others added 2 commits November 1, 2026 14:13
Checking on 2026-11-01 showed that comparing a claimed role with the stored
one only stops application bugs: a compromised application can claim a real
admin's user ID, and app_rls may update app_accounts.role itself. The same
holds for the existing members trigger. The requester decided that a
compromised application is outside what the database guarantees.

- requirements.md C-4: the application tells the database who is calling
  (the user ID) and never claims a role or permission; the database works
  the permissions out. The aim is stopping bugs. Record the scope, and that
  C-4 in this form is met by U-3, not by the current code.
- unit-of-work.md: fold U-2.5 into U-3, correct its earlier claim that the
  cross-check stopped a compromised application, and specify
  app_private.has_permission(user_id, key) for member's RLS. After U-10,
  community cannot read member_roles, so it uses the permissions member
  resolves for it (received in U-11). Launch conditions and order follow.
- components.md 3.3 and 3.5, README.md: follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vm1iXpgdwQfcWuyNzX9KF7
@yufoxda
yufoxda merged commit 3e0eaff into develop Nov 5, 2026
3 checks passed
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.

2 participants