Skip to content

feat(db): step 5 scope roles and their grants, phase 1 (step 5, U2) - #53

Merged
leandrotcawork merged 20 commits into
mainfrom
feat/conexus-e05-grants
Oct 17, 2026
Merged

leandrotcawork merged 20 commits into
mainfrom
feat/conexus-e05-grants

Conversation

@leandrotcawork

@leandrotcawork leandrotcawork commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Step 5's card, unit U2: the scope roles and their grants, in a pull request of their own before the step's code (data D11). It waits for the founder's word on the exact list below, as PR 48 did. Nothing merges before it, and it merges before the build PR (#54), which carries these same commits.

What changes

  • 20261017040314_company_scope_roles is custom SQL; Drizzle generates neither a role nor a grant (data D5).
    • It creates four roles: hub_company, hub_person, hub_invitation and hub_operator, all NOLOGIN NOSUPERUSER NOINHERIT NOCREATEDB NOCREATEROLE NOBYPASSRLS.
    • An existing role is kept, as hub_runtime's migration does, because roles belong to the whole server and tests make many databases on one.
    • Each role is granted to hub_runtime WITH INHERIT FALSE, SET TRUE: the login switches to one for a transaction and inherits nothing.
    • hub_runtime's own grants do not change here; phase 2 (U7, feat(db): the Hub's login loses its reach on a company's tables, phase 2 (step 5, U7) #55) takes them away.
  • 20261017040400_installation_administrator_check is custom SQL, provisional A, firstmate 2026-10-17. It is in this PR so you read the whole list in one place (review finding).
    • It creates the role hub_administrators (NOLOGIN) with SELECT (id, role) on auth."user".
    • It creates the SECURITY DEFINER function auth.is_installation_administrator(person), owned by that role, with search_path = pg_catalog, revoked from PUBLIC, and EXECUTE for hub_operator only.
    • Why: every operator policy needs an installation administrator, and written as a plain policy query, PostgreSQL refuses it with an infinite recursion.
  • apps/server/database-grants.sql: the approved snapshot gains the lines below.

The list, role by table by verb

This is the census from the U1 proof: the whole server suite run with these grants and the row policies, in phase 1 and in phase 2.

A command that only locks a row (FOR SHARE, FOR NO KEY UPDATE) needs UPDATE, but on one column is enough, so those grants are one column no command writes (data D12; review finding): created_at on the company and a member, updated_at on a person and a session.

Role Table Verbs Why
hub_company (a company's routes) auth.company SELECT, UPDATE (created_at) read; the company lock of invite, cancel, renew
auth.member SELECT, UPDATE (created_at) read; admission's FOR SHARE
auth.invitation SELECT, INSERT, UPDATE invite, cancel, renew, mark mailed
auth."user" SELECT, UPDATE (updated_at) members' names; the inviter's lock
auth.session SELECT, UPDATE (updated_at) the session check FOR SHARE of cancel and renew
hub_person (the person's companies, the pace) auth.company, auth.member, auth.invitation, auth."user" SELECT reads only
hub_invitation (the invitation link) auth.company SELECT, UPDATE (created_at) read; the company lock
auth.member SELECT, INSERT accept
auth.invitation SELECT, UPDATE decline, accept, revision
auth."user" SELECT, INSERT, UPDATE (name, email_verified, updated_at) the password creates the person, names them and marks the e-mail verified; a role is not writable from the link
auth.account SELECT, INSERT the credential (UPDATE proved unused)
auth.session SELECT, INSERT, UPDATE sign-in after the password; accept points the session at the company
auth.verification SELECT, INSERT, DELETE the one-use link inside the password command
hub_operator (the Operations Central) auth.company, auth.invitation SELECT, INSERT, UPDATE, DELETE register, correct, delete a client's company
auth.member SELECT, DELETE owners shown; delete
auth."user" SELECT, UPDATE (updated_at) owners' names; the operator's lock
operations.client SELECT, INSERT, UPDATE, DELETE the client record
auth.is_installation_administrator(text) EXECUTE every operator policy (provisional A)
hub_administrators (owns the function, cannot log in) auth."user" SELECT (id, role) the administrator check
  • DELETE on auth.company, auth.member, auth.invitation and operations.client belongs to hub_operator alone (card, "O grant"; Q6).
  • Schema USAGE: auth for all five roles, operations for hub_operator.

Proof

  • catalog.test.ts passes with the snapshot equality.
  • The build branch's full server suite runs on these grants, in both phases.
  • npm run migrations is ok.

…ients through identity's ports (step 4.2, U3)
…rrection, behind the operator's menu link (step 4.2, U4)
…ration deletes the test companies (step 4.2, U5)
…t, and native joins no longer protect a reachable path
The scope roles hold UPDATE on the company, a member, a person or a session
only to take a row lock. PostgreSQL needs UPDATE on one column for FOR SHARE
and FOR NO KEY UPDATE, so each gets UPDATE on one column no command writes
(data D12): created_at on the company and a member, updated_at on a person
and a session.
…ovisional A (step 5, U2)

Moved here from the build so the founder reads the whole list in one grant
PR (D11): the role hub_administrators, its column grant on auth.user, the
function auth.is_installation_administrator with EXECUTE for hub_operator
only, and its ownership.
…-mail and stamp (step 5, U2)

UPDATE on auth.user for hub_invitation narrows to the columns the password
command writes; a person's role is not writable from the link scope.
…grants

Main's step 4.2 replaces the old base branch's files; this branch keeps only its own roles,
administrator check and grants.
@leandrotcawork
leandrotcawork changed the base branch from feat/conexus-e042-build to main October 17, 2026 13:32
@leandrotcawork
leandrotcawork merged commit 22f82e9 into main Oct 17, 2026
13 of 26 checks passed
leandrotcawork pushed a commit that referenced this pull request Oct 17, 2026
…#51) into feat/conexus-e05-build

The card, roadmap and decision 0039 take main's approved text.
@leandrotcawork
leandrotcawork deleted the feat/conexus-e05-grants branch November 12, 2026 20:38
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