Skip to the lesson
CivOps AI Academy · F06The Role and Exposure Matrix: Who Sees What and Who Does What, Written Once
0%

Chapter 1 · Session 7

Who may do what, written once

Your tables exist and are closed to everyone. Before anything opens them, you write down, once, which job may read or change which table, at which part of the plant. Claude Code drafts it from your intent and schema plan; you will check it in the next chapter.

30 min1 stepNo SQL, no policies

By the end of this chapter you can

  • Say why access written in several places goes wrong, and why one file fixes it.
  • Read a Role and Exposure Matrix: roles, tables, rights in each cell, scope.
  • Have Claude Code draft docs/matrix.json from docs/INTENT.md and docs/SCHEMA-PLAN.md.

Why access is written once

OWASP, the open community that tracks web application security, ranks broken access control first in its Top 10: a signed-in person reaching data or actions their job should not [1]. It is common because most systems write the same rule by hand in three places: the screen hides a button, the server checks a role, the database limits rows. Each copy is written at a different time, often by a different person or agent, and they stop agreeing.

Permission driftA rule about who may release a held lot, written separately in screens, server routes and the database, agrees in month 1; by month 9 the screens and routes are out of step with the database. Month 1Month 4Month 9Screenshide Release from operatorsagreesagreesout of stepServer routescheck the role on /api/holdsagreesout of stepout of stepDatabaserow rules on holdsagreesagreesagreesThree hand-written copies of one rule drift apart. One matrix, generated into all three, cannot.
Permission drift. One rule, "operators cannot release a held lot", written three times. By month 9 two of the copies have drifted and nobody noticed.

We lived this. On the platform CivOps built, the screens were careful and the database rules were not checked: a user of one company could open another company's batch by changing the number in the address, and an operator account could delete a whole site, because the only check was "is someone signed in". Both are in this course's edge cases (7.1 and 7.2), and both happened because who-may-do-what was not written in one place that everything else came from.

One matrix, everything generated from itThe matrix file is checked in Session 7, then feeds generated database rules and access tests in Session 8, route guards and the review sheet in Session 9, and menus in Sessions 12 and 13. docs/matrix.jsonone file in the repository,reviewed like codeCheck (Session 7)valid, complete,real tables onlyDatabase row rulesSession 8: generated policiesAccess testsSession 8: allowed and refused, per cellRoute guardsSession 9: every page closed until openedReview sheetSession 9: docs/access-review.mdMenusSessions 12–13: only what a role may open
One file, everything else generated from it. This session writes the file and the check that keeps it honest; the next sessions generate from it.

Reading a matrix

A Role and Exposure Matrix is a table. Each row is a role: a job, not a person. Each column is one of your tables. Each cell holds the rights that job has on that table. An empty cell means no access at all, not even knowing the rows exist.

The stamping plant's Role and Exposure MatrixEight roles by five of the plant's tables. Operators read and insert lots and inspections; the quality lead inserts holds and maintains limits; the manager and the AI agent only read; the connector inserts inspections; only the admin touches memberships, and that is the only delete. Rows are roles (jobs, not people), columns are tables, each cell is what that role may do. A dash is no.lotsinspectionsholdscharacteristicsmembershipsoperatorread insertread insertreadread–supervisorread insert updateread insertreadread–quality_leadreadread insertread insertread insert update–maintenancereadread–read–managerreadreadreadread–admin––––read insert update deleteplant_connector ⚙readread insert–read–agent ⚙readreadreadread–⚙ machine account. Delete appears once: removing a person's membership. Records are never deleted.
The stamping plant's matrix. The quality lead decides holds and owns the limits; operators record results; the manager and AI agents only read; only the admin touches memberships. Yours will follow your intent.
RightWhat it allowsStamping plant example
readSee the rows in scopeAn operator sees whether lot L-2041 is on hold before running it
insertAdd new rows, as yourselfAn operator records a first-piece result; the quality lead records a hold
updateChange rows that may changeA supervisor closes a lot at the end of the run; the quality lead corrects a limit
deleteRemove rowsOnly the admin, only memberships: taking a person's role away
(empty)NothingMaintenance and holds; the admin and every production table

Records of what happened are never deleted or changed. Session 5 made inspections and holds append-only: a correction is a new row that says why. The matrix agrees with that: no role gets update or delete on an event or decision table, and delete appears in exactly one place, removing a person's membership.

Scope: line, area or site

Rights say what a job may do; scope says where. Two operators share a role but may work on different lines. Scope uses the same levels as your naming standard from Session 4: line, area, site.

Scope: line, area, siteNested boxes: the site contains the press shop and assembly areas; the press shop contains line 1 and line 2. A line-scoped operator on line 1 sees only line 1; an area-scoped supervisor sees the press shop; a site-scoped manager sees the whole site. scope: site, the whole plant (every role in the stamping example)scope: area, the press shopLine 1 · presses 1–3scope: linean operator here seesline 1's rows onlyLine 2 · presses 4–6the line 1 operatorsees nothing hereArea: assemblya press shop supervisorsees nothing here;a site-scoped managersees it all
Scope. The same right, limited to the part of the plant a person is assigned to. The database enforces it on every query from Session 8.

Use the narrowest scope your tables can already hold. The stamping plant has one press shop and its memberships table records a person's site, so every role there is site-scoped. If your plant needs line scope (a line 2 operator must not see line 3), the schema needs a line on each membership and on each row; Claude Code will raise it as a question rather than invent it.

Jobs, machines, and the smallest rights

Two principles shape every cell. Least privilege: each job gets only what it needs for the decision, nothing more [2]. Default deny: anything not written in the matrix is refused, so a forgotten cell fails closed [3]. Write supervisor, not Dana: people are given a role in the memberships table, and when they change job the matrix stays the same.

People and machine accountsSix person roles, each with personal sign-in, beside two machine accounts: the plant connector, which only inserts gauge results and reads what it needs, and AI agents, which only read. People: personal sign-in, one role eachOperatorrecords resultsSupervisorruns the shiftQuality leadholds and releasesMaintenancekeeps presses runningManagerreads, changes nothingAdmingives roles, no plant dataMachines: one account per jobConnector (Session 20)inserts gauge resultsreads lots and limits, nothing elseAI agents (Session 16)read onlyno inserts, no updates, no deletesMachine accounts are rows in the matrix too. They never borrow a person's login or the secret key.
People and machines. Software that acts on the platform gets its own role, with the narrowest rights for its one job.

Machines are roles too. The plant connector (Session 20) needs to insert gauge results; AI agents (Session 16) need to read. Each gets its own row and its own account, never a person's login and never the Supabase secret key, which skips every rule (Session 8 tests that the app's own login cannot).

The file

The matrix is a JSON file: plain text that people can read and programs can check [4]. This is the stamping plant's, shortened. Yours will have your tables and jobs.

docs/matrix.json (shortened)
{
  "version": 1,
  "owner": "plant manager",
  "checked_with": "quality lead, 2026-10-20",
  "roles": {
    "operator":     { "job": "Runs a press; records first-piece and hourly results", "scope": "site" },
    "quality_lead": { "job": "Decides hold or release; owns parts and limits", "scope": "site" },
    "admin":        { "job": "Gives people their roles; reads no plant data", "scope": "site" },
    "plant_connector": { "job": "Sends gauge results from the plant (Session 20)", "scope": "site", "machine": true },
    "agent":        { "job": "AI agents that read and summarise (Session 16)", "scope": "site", "machine": true }
  },
  "tables": {
    "inspections": { "kind": "event", "by": "recorded_by",
                     "rights": { "operator": "read insert", "quality_lead": "read insert",
                                 "plant_connector": "read insert", "agent": "read" } },
    "holds":       { "kind": "decision", "by": "decided_by",
                     "rights": { "operator": "read", "quality_lead": "read insert", "agent": "read" } },
    "memberships": { "kind": "people", "rights": { "admin": "read insert update delete" } }
  },
  "screens": { "/inspect": ["operator", "quality_lead"], "/holds": ["quality_lead"] },
  "left_out": [ { "role": "contractor", "why": "No contractor touches this decision yet" } ]
}

by names the column that records who wrote the row. Session 8 uses it so nobody can record a result in someone else's name.

Step 1

Ask Claude Code to draft the matrix from your intent and schema plan

10 minutes

Why

Claude Code can read your intent, your signed-off schema plan and every migration in seconds, and draft a complete matrix with every table in it. Asking for the draft in a fixed shape, with the smallest rights and a list of questions, gets you something you can check in one sitting instead of building it cell by cell over several conversations.

Do this

Terminal or PowerShell
cd ~/code/acme-platform && git switch main && git pull && claude
Paste into Claude Code
Read docs/INTENT.md, docs/SCHEMA-PLAN.md (signed off) and every file in supabase/migrations. Do not write any SQL or policies.

On a new branch access/matrix, write docs/matrix.json: the Role and Exposure Matrix for this platform, in exactly this shape:
{
  "version": 1,
  "owner": "<the job that approves changes to this file>",
  "checked_with": "",
  "roles": { "<role>": { "job": "<one sentence>", "scope": "site", "machine": true } },
  "tables": { "<table>": { "kind": "<reference | people | thing | event | decision>", "by": "<column that records who wrote the row, if the table has one>", "rights": { "<role>": "read insert" } } },
  "screens": { "/<page>": ["<role>"] },
  "left_out": [ { "role": "<job>", "why": "<reason>" } ]
}
("machine": true only on machine accounts.)

Rules:
- Roles are jobs, never people's names, in lower case with underscores. Include the jobs docs/INTENT.md names, an admin role that gives people their roles and reads no plant data, and two machine accounts: plant_connector (the plant connector, Session 20) and agent (AI agents, Session 16).
- Every table created by a migration appears once under "tables", with its kind from the schema plan. No table that no migration creates. Views are not listed: they follow the tables they read.
- Rights are only read, insert, update and delete, separated by spaces. Give each role the smallest rights its job needs for the decision in docs/INTENT.md. Leave a role out of a table when it needs nothing: a missing role means no access.
- No delete anywhere except delete on memberships for admin. No update or delete on event or decision tables: they are append-only.
- A role that updates or deletes rows in a table also reads it. A role that inserts also reads, unless it is a machine account that only sends data.
- Scope: the narrowest of line, area or site that the memberships table can already hold. If the intent needs a narrower scope than the schema can hold, use site and add it to the questions.
- Screens: the pages the intent needs, each with the roles that may open it. Machine accounts open no screens.
- Under "left_out", name any job you were tempted to include (contractors, auditors, customers) and why it is not there now.

Then open a pull request titled "Role and exposure matrix". In its description put the matrix as a plain-English table (roles down the side, tables across, rights in the cells, a dash for none), each role's scope, and a section "Questions for the decision-maker" with anything the intent and schema plan do not settle. Show me the link.

You will see recreated screen

claude — acme-platform
⏺ Read(docs/INTENT.md)
⎿ Read 38 lines
⏺ Read(docs/SCHEMA-PLAN.md)
⎿ Read 112 lines
⏺ Bash(ls supabase/migrations)
⎿ 20261016091500_create_first_tables.sql 20261017140200_release_by_other.sql
1
⏺ Write(docs/matrix.json)
+"holds": { "kind": "decision", "by": "decided_by",
+ "rights": { "operator": "read", "supervisor": "read",
+ "quality_lead": "read insert", "manager": "read", "agent": "read" } },
+"memberships": { "kind": "people", "rights": { "admin": "read insert update delete" } },
2
⏺ Bash(gh pr create --title "Role and exposure matrix" ...)
⎿ https://github.com/acme-ops/acme-platform/pull/18
⏺ Pull request #18 adds docs/matrix.json: 8 roles (2 machine accounts), 8 tables, 6 screens. Every role is site-scoped: memberships records only a site. Three questions for the quality lead are in the description.3
Claude Code reads the three sources first, then writes one file and opens the pull request. The roles and tables here are the stamping plant's; yours follow your intent.
  1. It lists the migrations: the tables in the matrix must be the tables those files create.
  2. One decision table: who may read holds, and the one job that may record one. No update, no delete.
  3. The questions are the most valuable part. Do not answer them yourself: they go to the decision-maker in Step 3.

Check it worked

Pull request Role and exposure matrix changes one file, docs/matrix.json. Its description has a readable table, each role's scope, and a Questions for the decision-maker section.

Fastest path

Asking for the plain-English table in the pull request description means you, the decision-maker and owner two all read the same thing on GitHub, with no extra document to keep in step. Session 9 generates the permanent review sheet from the file.

If it goes wrong

The draft has a role per person ("dana", "night_supervisor_2")

Say: Roles are jobs, not people. Merge any role that differs only by person or shift into the job, and list what you merged. A person's name in the matrix means rewriting access every time someone changes job.

It lists tables no migration creates (users, audit_log, settings)

Say: Remove every table that no file in supabase/migrations creates. If the intent needs it, list it under Questions instead. Sign-in accounts already live in Supabase; a matrix entry for a table that does not exist is a rule nobody can test.

Claude Code also wrote policies or a migration

Say: Remove the SQL. This session writes only docs/matrix.json and its check; Session 8 generates the policies from it. A policy written before the matrix is signed off is a guess about who may see the plant's data.

It says it cannot find docs/SCHEMA-PLAN.md or the migrations

Session 5 is not merged yet. Finish it first: the matrix is a list of rights on tables, and without the tables it is invented.

Knowledge check

A screen hides the Release button from operators, but nothing else checks the role. What can an operator do?

Knowledge check

In the matrix, a role is missing from a table's rights. What may that role do with the table?

References

  1. OWASP Top 10:2025 (A01 Broken Access Control). https://owasp.org/Top10/2025/
  2. NIST Computer Security Resource Center glossary: least privilege. https://csrc.nist.gov/glossary/term/least_privilege
  3. OWASP Authorization Cheat Sheet (deny by default, least privilege). https://cheatsheetseries.owasp.org/cheatsheets/Authorization_Cheat_Sheet.html
  4. IETF RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format. https://www.rfc-editor.org/rfc/rfc8259

Chapter 2 · Session 7

Read it by row and by column, then check it with the person who decides

You do not need to read JSON to review a matrix. Claude Code reads it back to you two ways: what each job may do, and who can reach each table. Then the person who makes the decision every day checks it, and their answers go into the file.

30 min2 stepsOne meeting with the decision-maker

By the end of this chapter you can

  • Have Claude Code explain the matrix by row and by column, against eight yes-or-no questions.
  • Check it with the decision-maker: what each job needs, and who must never see what.
  • Record their answers and sign-off in the file.

Two ways to read the same table

Read across a row and you see everything one job can do: that is how a supervisor will read it ("what can I do?"). Read down a column and you see everyone who can reach one table: that is how IT and an auditor will read it ("who can see the holds?"). Mistakes hide in one view and show in the other, so the review uses both.

Role-based access control, where rights attach to jobs and people are given jobs, is an established model with a NIST standard behind it [1]. Two of NIST's standard controls are exactly what you are checking: least privilege (AC-6) and separation of duties (AC-5), so that no one person both does a thing and approves it [2]. In the stamping plant, separation of duties is already a rule in the holds table from Session 5 (a lot cannot be released by the person who held it), so the matrix does not repeat it.

Step 2

Have Claude Code read the matrix back to you, two ways

10 minutes

Why

A matrix you cannot read is a matrix you cannot check. Asking Claude Code to explain it by row and by column, and to answer eight fixed questions with the line that proves each answer, turns a page of JSON into sentences you can judge, and catches the plausible mistakes agents make, such as a manager who can quietly change limits.

Do this

Paste into Claude Code
Explain docs/matrix.json in pull request "Role and exposure matrix" to me twice, in plain English, without changing anything:

1. By row: for each role, "A <role> may ..." in one or two sentences, and what they may NOT do that someone might expect.
2. By column: for each table, who can read it, who can change it, and who cannot see it at all.

Then answer each question with Yes or No and the line in docs/matrix.json that shows it:
a. Is every role a job, not a person?
b. Does every table that a migration creates appear, and nothing else?
c. Is there no delete except admin on memberships?
d. Is there no update or delete on any event or decision table?
e. Does every role that updates or deletes rows in a table also read it?
f. Does the admin role read no plant data?
g. Do the machine accounts have only what their one job needs, and no screens?
h. Can every right be traced to the decision in docs/INTENT.md? Name any you cannot trace.

If any answer is No, say what you would change and wait.

You will see recreated screen

claude — acme-platform
⏺ By row. A quality lead may read lots and results, record holds and releases, and add or correct parts and limits. They may not change a recorded result or a hold: those are corrected with new rows.
⏺ By column. holds: read by operator, supervisor, quality_lead, manager and agent. Recorded only by quality_lead. Not visible to maintenance, admin or plant_connector.1
⏺ a Yes (lines 5–14). b Yes: 8 tables, the same 8 the migrations create. c Yes: only memberships/admin (line 61). d Yes. e Yes. f Yes: admin reaches only sites and memberships. g Yes: plant_connector reads the reference tables and lots and inserts inspections; agent reads only; neither has a screen. h One I cannot trace: manager has update on characteristics (line 47). The intent says the quality lead owns limits.2
The review: each job in a sentence, each table's readers, then eight answers with the line that proves each.
  1. Down a column: who can see the decision. Ask the decision-maker if maintenance really does not need it.
  2. The answer that matters is the one that is not a plain Yes. Here a manager could change limits; the intent says nothing about it.

Check it worked

Every answer is Yes, or each No has a change you agree with. Note anything you are unsure of for the decision-maker.

If it goes wrong

An answer is No

Say: Make the change you described in docs/matrix.json, push it to the same pull request, and answer the eight questions again.

The answers say Yes but the table in the pull request shows something else

The description was written before a later change. Say: Regenerate the table in the pull request description from docs/matrix.json as it is now, and tell me what changed. We trust the file, never an old summary of it.

Claude Code says a whole group of rights is fine "because they are all read-only"

Ask for each one separately: For each read right you grouped, say which part of the intent needs it. Read access to holds or results is still access to plant data; we were once told a group of warnings were all false, and one of them exposed 23 people's names and work emails.

Checking it with the person who decides

The decision-maker knows things neither the intent nor the schema says: that night-shift operators release their own lots when the quality lead is off site, that maintenance does need to see holds on the press they are fixing, that the manager wants to read everything but never change it. Each of those is a cell. Finding it now costs a sentence; finding it after go-live costs a change, a retest, and possibly an incident.

Step 3

Check it with the decision-maker, and record their answers

20 minutes

Why

The matrix decides who in the plant can see and change the records the decision depends on, so it must be agreed by the person who owns that decision, not guessed by the person building the platform. Their sign-off in the file means the access rules generated in Session 8 rest on a written decision, which is what an auditor or IT will ask for.

Do this

Open

https://github.com/acme-ops/acme-platform/pulls

Open Role and exposure matrix. The description holds the table; send this link to the decision-maker if they will read it on their own screen.

Sit with the decision-maker and read the table in the pull request description together. Ask four questions:

  • By row: is this everything each job needs to do its part of the decision? Is anything missing?
  • By column: who must never see this table? Is anyone listed who should not be?
  • The machines: is it right that the connector can only add results, and AI agents can only read?
  • The questions at the end: what is the answer, in their words?

Then give Claude Code the answers:

Paste into Claude Code, after replacing the <...> parts
The quality lead reviewed docs/matrix.json and answered:
1. <paste their answer to question 1>
2. <paste their answer to question 2>
3. <paste their answer to question 3>
They also changed: <paste anything else they changed>.

Update docs/matrix.json to match, keeping every rule from before (smallest rights, no delete except admin on memberships, no update on event or decision tables, read with every update). Set "checked_with" to "quality lead, <today's date>". Regenerate the table in the pull request description, push to the same pull request, and list exactly which cells changed.

You will see recreated screen

github.com/acme-ops/acme-platform/pull/18
ConversationCommitsChecksFiles changed
Role and exposure matrix
Checked with the quality lead on 2026-10-201
2
Rolelotsinspectionsholdscharacteristics
operatorread insertread insertreadread
quality_leadreadread insertread insertread insert update
maintenancereadread–read
managerreadreadreadread
The pull request as the decision-maker reads it: a table, not code. Each cell is one job's rights on one table.
  1. The sign-off: who checked it, and when. It is in the file, so it travels with every later change.
  2. Read across for a job, down for a table. The dash is a deliberate no.
  3. What the conversation changed. This is what the step is for.

Check it worked

checked_with in docs/matrix.json names the decision-maker's role and today's date, no questions are left open, and every change they asked for is in the list of changed cells.

Fastest path

If the decision-maker cannot meet, send them the pull request link with the four questions in the email. Do not merge until they answer: a guessed cell becomes a generated database rule in the next session.

If it goes wrong

The decision-maker wants everyone to see everything "to keep it simple"

Ask about one cell they care about: Should the connector, a piece of software in the plant network, be able to change a hold? Least privilege is easier to agree one cell at a time. Anything they still want opened is a reviewed change later, not a default now.

They want a person named in the matrix ("only Dana releases")

Make it a job: a role such as release_authority, given to Dana in memberships. When Dana moves on, the matrix stays the same and one membership changes.

They want night shift to release their own holds

That conflicts with the release-by-another rule in the holds table from Session 5. Do not loosen it in the matrix. Write it down as a question for the plant manager; if they agree, it is a schema change (a new migration) and a matrix change, both reviewed.

Knowledge check

Which view of the matrix answers IT's question "who can see the holds?"

Knowledge check

Why is the decision-maker's sign-off recorded in docs/matrix.json itself?

References

  1. NIST: Role Based Access Control (RBAC) project. https://csrc.nist.gov/projects/role-based-access-control
  2. NIST SP 800-53 Rev. 5, Security and Privacy Controls (AC-5 Separation of Duties, AC-6 Least Privilege). https://csrc.nist.gov/pubs/sp/800/53/r5/upd1/final
  3. GitHub Docs: Reviewing proposed changes in a pull request. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/reviewing-proposed-changes-in-a-pull-request

Chapter 3 · Session 7

A check that keeps the matrix honest

From the next session on, the database's rules are generated from this file, so a mistake in it becomes a mistake in the database. One prompt adds a check that runs on every pull request; then you watch it fail on purpose before you trust it.

30 min2 stepsEnds with a gate

By the end of this chapter you can

  • Have Claude Code write scripts/check-matrix.mjs, its tests and the CI step in one pull request.
  • Know what the check refuses, and why each rule is there.
  • See the check go red on planted mistakes before you rely on it.

What the check refuses

The check reads docs/matrix.json and the migrations, and fails the pull request with a plain message when the matrix and the database disagree, or when the matrix breaks one of the session's rules. GitHub runs it on every pull request, next to the checks from Sessions 3 and 4 [1].

What the matrix check refusesSix mistakes the check refuses: a table that does not exist, a table missing from the matrix, a right that is not read, insert or update, delete on a record, update on an append-only table, and an update or delete without read on the same table. node scripts/check-matrix.mjs fails the pull request, and says which line, when it finds:A table the schema does not have"inspection" (no s): not created by any migrationA table the matrix forgotshift_notes is in a migration, not in the matrixA right that is not a right"approve", "all", "admin": only read, insert, updateDelete on a recorddelete on inspections, holds or lotsUpdate on historyupdate on inspections or holds (append-only)Update without readupdate or delete with no read on the same table
Six mistakes the check refuses. Each one has a line in the check and a test that proves the line works.
RuleWhy it is here
Every table in the matrix is created by a migration, and every created table is in the matrixA matrix entry for "inspection" when the table is "inspections" is a rule that protects nothing; a new table with no entry is a table nobody decided about. Names one letter apart caused real, quiet bugs on the platform (edge case 4.2)
Only read, insert, update and delete"approve" or "all" cannot be turned into a database rule, so the generator would have to guess
No delete on records; no update on event or decision tablesSession 5 made history unchangeable. A matrix that grants update on holds would ask the database to do something its own trigger refuses
A role that updates a table also reads itIn Postgres an update only finds rows the role can read. Without read, a Save button reports success and changes nothing (edge case 7.3)
Known roles only; machine accounts have no screensA typo in a role name is a role nobody holds; a screen for the connector is a door nobody should use
Step 4

One prompt: the check, its tests and the CI step

15 minutes

Why

Writing the check, its tests and the CI step in the same pull request as the matrix means the file is never on main unchecked. From Session 8 on, a wrong cell becomes a wrong database rule; the check is the cheapest place to catch it, on the pull request, before anything is generated.

Do this

Paste into Claude Code
On the branch of pull request "Role and exposure matrix", add a check that keeps docs/matrix.json honest.

1. scripts/check-matrix.mjs (Node, no new dependencies). It reads docs/matrix.json and every file in supabase/migrations, and exits with an error and a plain message naming the role, table or screen at fault when:
   - the file is not valid JSON, a role has no job, or a scope is not site, area or line;
   - a table in the matrix is not created by any migration, or a table a migration creates is missing from the matrix;
   - a cell names a role that is not under roles, or a right other than read, insert, update and delete;
   - delete appears on any table whose kind is not people;
   - update or delete appears on a table of kind event or decision;
   - a role updates or deletes rows in a table it does not read;
   - a "by" column is named that the table does not have;
   - a role's scope is area or line but memberships has no column that holds it;
   - a screen names an unknown role, or a machine account has a screen.
   When everything passes, it prints one line with the number of roles, tables and screens checked.

2. tests/check-matrix.test.ts (Vitest): the real matrix passes, and one broken copy per rule above fails with its message.

3. A step in .github/workflows/ci.yml that runs node scripts/check-matrix.mjs on every pull request.

Do not change docs/matrix.json to make the check pass: if the check finds a problem in it, stop and tell me what and why. Push, wait for every check on the pull request to finish, and tell me the result in plain words. If a check fails, fix the cause, not the check, and wait again before reporting.

You will see recreated screen

claude — acme-platform
⏺ Write(scripts/check-matrix.mjs)
+const created = tablesCreatedBy("supabase/migrations");
+for (const t of Object.keys(matrix.tables))
+ if (!created.has(t)) fail(`table ${t} is in docs/matrix.json but no migration creates it`);
+for (const t of created)
+ if (!matrix.tables[t]) fail(`table ${t} is created by a migration but is not in docs/matrix.json`);
1
⏺ Bash(npm test -- check-matrix)
⎿ ✓ tests/check-matrix.test.ts (11 tests) 412ms
⏺ Bash(node scripts/check-matrix.mjs)
⎿ matrix ok: 8 roles, 8 tables, 6 screens
⏺ Bash(gh pr checks 18 --watch)
⎿ ci / lint-typecheck-test pass 1m08s schema / test pass 1m47s
2
⏺ Pull request #18 is green. The matrix check runs on every pull request: 11 tests, one per rule, each proving a broken matrix is refused, plus the real one passing. I did not change docs/matrix.json.3
Claude Code writes the check and its tests, runs them, then waits for GitHub before reporting.
  1. Both directions: a table in the matrix that does not exist, and a table that exists but is not in the matrix.
  2. Every check on the pull request, waited for: we trust GitHub's result, never the summary.
  3. It says it left the matrix alone. If a summary says it "fixed the matrix", read the Files changed tab before anything else.

Check it worked

Pull request Role and exposure matrix is green on GitHub, its Files changed tab shows docs/matrix.json, scripts/check-matrix.mjs, tests/check-matrix.test.ts and one new step in .github/workflows/ci.yml, and nothing else.

Fastest path

"Wait for every check and fix the cause before reporting" saves a whole round trip: Claude Code reads the failure and fixes it while you do something else.

If it goes wrong

The check passes on Claude Code's computer but the check on GitHub is red

Say: The check on pull request #18 is red. Run gh pr checks 18, read the failed log, fix the cause and wait for green before you report. Then look at the pull request yourself. A summary is a claim; the check on the latest commit is the evidence.

Claude Code "fixed" a failure by loosening the check or deleting a test

Say: Undo that. Never change a check or a test to get to green. Tell me what the check found and why, and I will decide. We had an agent go round a check it was refused. Read the list of changed files on every pull request before the summary.

The check says a table a migration creates is missing, and it is a table you have never heard of

Ask before adding it: Which migration creates , when, and why? Is it in docs/SCHEMA-PLAN.md? If someone created it outside the plan, that is a Session 5 conversation first; only then does it get a row in the matrix.

It reads table names wrongly (misses one written as create table if not exists, or with quotes)

Say: Your parser missed table in . Add a test with that exact line, then fix the parser. A check that misses a table passes while the matrix is incomplete.

Step 5

Watch the check fail on purpose, then merge

15 minutes

Why

A check that has never been seen failing may not be able to fail: we had probes that could only ever answer yes, green for weeks while the thing they guarded was broken. Planting two mistakes and watching the check go red on GitHub proves it catches exactly what this session is about, before anyone relies on it.

Do this

Paste into Claude Code
Prove the matrix check works, without merging anything. On a new branch access/prove-check, starting from the branch of pull request "Role and exposure matrix", make two deliberate mistakes in docs/matrix.json: give operator delete on inspections, and add a table called inspection (no s) with operator read. Push, open a draft pull request titled "DO NOT MERGE: the matrix check must fail", wait for the checks, and show me the exact lines of the failure. Then close that pull request without merging and delete the branch.

Then owner two reads the real pull request, approves it, and you merge it:

Open

https://github.com/acme-ops/acme-platform/pulls

Owner two opens Role and exposure matrix, reads Files changed, and approves; then merge.

Bring main up to date on your computer:

Terminal or PowerShell
git switch main && git pull

You will see recreated screen

github.com/acme-ops/acme-platform/pull/19/checks
ConversationCommitsChecksFiles changed
DO NOT MERGE: the matrix check must fail
Run node scripts/check-matrix.mjs
matrix: inspections: delete is only allowed on tables of kind people (role operator)
matrix: table inspection is in docs/matrix.json but no migration creates it
Error: Process completed with exit code 1.
This pull request was closed without merging.2
The draft pull request's failed check on GitHub, naming both planted mistakes.
  1. Red, on GitHub, on this branch's latest commit.
  2. Closed, never merged. Both mistakes are named: the check can fail, and fails for the right reasons.

Check it worked

You saw the draft pull request fail with both mistakes named, it is closed unmerged, and Role and exposure matrix is merged on main with a green check.

If it goes wrong

The draft pull request is green

The check cannot catch these mistakes, so it is not protecting you. Say: The planted mistakes passed the check. Find why each was not caught, add a test for each, fix the check on the matrix pull request, and plant them again. Do not merge the matrix until it goes red.

It is red, but for a different reason (lint, a type error)

Ask: Which check failed, on which commit, and is it the matrix check? Show me the matrix check's own output. A red for the wrong reason proves nothing about the matrix check.

Claude Code merged the draft or pushed the mistakes to the matrix branch

Main is protected, so it cannot reach main without approval. Say: Revert the planted mistakes on access/matrix, push, and show me docs/matrix.json is as reviewed. Then check the Files changed tab yourself before approving.

Before you go on · Session 7 is done whenTick each one

Knowledge check

An agent adds a table shift_notes in a migration and forgets the matrix. What happens?

Knowledge check

Why plant mistakes and watch the check fail before merging?

References

  1. GitHub Docs: GitHub Actions. https://docs.github.com/en/actions
  2. Vitest: Getting started. https://vitest.dev/guide/
  3. PostgreSQL Documentation: Row Security Policies (update needs read). https://www.postgresql.org/docs/current/ddl-rowsecurity.html

Chapter 4 · 12 questions · 80% passes

Final assessment

Twelve questions across the element. Score 80% (10 of 12) to pass. Your LMS records your score and each answer; you can review the chapters and try again.

15 min12 questions≈ 15 minutesRetake allowed

Choose one answer for each question, then submit. You will see the right answer and why for every question.

1. Which flaw does OWASP rank first in its Top 10 for web applications?
2. Why do access rules written by hand in the screen, the server and the database become dangerous?
3. In the Role and Exposure Matrix, what is a row?
4. A role is missing from a table's rights in docs/matrix.json. What may it do with that table?
5. Why does no role get update or delete on inspections or holds?
6. Where does delete appear in the stamping plant's matrix?
7. Which account should the plant connector use?
8. A role may update a table but has no read on it. What happens in Postgres?
9. Your plant needs a line 2 operator not to see line 3, but memberships records only a site. What should the matrix do?
10. What does the matrix check do when a migration creates a table that is not in docs/matrix.json?
11. Why did you plant two mistakes and watch the check fail before merging?
12. Who must agree the matrix before it merges?