Grants: record_lesson and lesson_status are realm only, refused cross-realm (#12, stacked on PR 13) #14

Closed
uranus wants to merge 0 commits from uranus/12-grants into main
Member

Purpose (security): mcl-scribe's procedures are granted only inside its realm, and a caller from another realm is refused.

Stacked on PR 13 (#4). This PR's own change is e658cdd1..6f7e530a: one test module, apps/mcl_scribe/test/mcl_scribe_grants_tests.erl. Merge PR 13 first. The threat model is on #12, comment 5043.

Done when (#12, narrowed by Mars's ruling 2026-11-25)

Line Proof
A caller from another realm is refused on record_lesson and lesson_status (second realm key) "T1, T2" in the suite: a genuine membership token of a SECOND realm key goes through macula_ucan:authorize/3 against the policy the real pool resolved and holds for each procedure, and is refused
The startup log names each procedure's grant (none says "open callers") macula's own line, captured from the pool's advertise: mcl-scribe/<name> declares its callers members in realm …, one per procedure; no line holds "open callers"

Also covered from the threat model: a realm member is admitted (the gate is not just shut); no token or an expired one is refused (T3); another node's token is refused (T4); a pool with no pinned key for the realm refuses the member class outright (T7).

How

  • macula_client:caller_policy/3 is exported only under macula's TEST, so the suite does not call it. It starts a real pool with connect([], #{node_identity, realm_trust}), which dials nothing, and advertises each capability with its declared auth. The pool resolves the class and logs the grant. The test then reads the policy the pool holds (sys:get_state, the {Realm, Procedure} registrations) and checks tokens against it.
  • The pool gets a generated identity: given none, a pool reads the user's stored node key. On the first try it refused that file and changed nothing (mtimes checked).
  • No mesh, no outside service.

Proof

  • eunit 63/63; lint, xref and dialyzer clean.
  • Mutants on mcl_scribe_service's declared auth, each killed by this suite: open, {callers, role}, record_lesson alone open, and {callers, {nodes, [stranger]}}. The open mutant also fails the cross-realm test. No mutant failed to compile.

Refs #12

Purpose (security): mcl-scribe's procedures are granted only inside its realm, and a caller from another realm is refused. Stacked on PR 13 (#4). This PR's own change is e658cdd1..6f7e530a: one test module, `apps/mcl_scribe/test/mcl_scribe_grants_tests.erl`. Merge PR 13 first. The threat model is on #12, comment 5043. ## Done when (#12, narrowed by Mars's ruling 2026-11-25) | Line | Proof | | --- | --- | | A caller from another realm is refused on `record_lesson` and `lesson_status` (second realm key) | "T1, T2" in the suite: a genuine membership token of a SECOND realm key goes through `macula_ucan:authorize/3` against the policy the real pool resolved and holds for each procedure, and is refused | | The startup log names each procedure's grant (none says "open callers") | macula's own line, captured from the pool's advertise: `mcl-scribe/<name> declares its callers members in realm …`, one per procedure; no line holds "open callers" | Also covered from the threat model: a realm member is admitted (the gate is not just shut); no token or an expired one is refused (T3); another node's token is refused (T4); a pool with no pinned key for the realm refuses the member class outright (T7). ## How - `macula_client:caller_policy/3` is exported only under macula's TEST, so the suite does not call it. It starts a real pool with `connect([], #{node_identity, realm_trust})`, which dials nothing, and advertises each capability with its declared `auth`. The pool resolves the class and logs the grant. The test then reads the policy the pool holds (`sys:get_state`, the `{Realm, Procedure}` registrations) and checks tokens against it. - The pool gets a generated identity: given none, a pool reads the user's stored node key. On the first try it refused that file and changed nothing (mtimes checked). - No mesh, no outside service. ## Proof - eunit 63/63; lint, xref and dialyzer clean. - Mutants on `mcl_scribe_service`'s declared auth, each killed by this suite: `open`, `{callers, role}`, `record_lesson` alone `open`, and `{callers, {nodes, [stranger]}}`. The `open` mutant also fails the cross-realm test. No mutant failed to compile. Refs #12
v1 slice 1: record_lesson and lesson_status, stored as written (walking skeleton, no model)
Some checks failed
c4 model / c4-model (pull_request) Has been cancelled
c4 model / c4-model-1 (pull_request) Has been cancelled
lint-and-test / check (pull_request) Has been cancelled
596b3ffe7e
An mcl_om_service OTP 28 release in the four-app shape: mcl_scribe (the
service and its reckon-db store, the scribe log), guide_lessons (the lesson
aggregate, the filer and the leak scan), project_lessons (the read model) and
query_lessons (lesson_status).

- record_lesson appends the lesson as written and answers {lesson_id, queued}
  at once; an empty or oversized lesson is refused at the door.
- The filer takes queued lessons in log order, one at a time. It reads the
  lesson's own stream before filing, so a lesson already final is never filed
  again; a head it cannot file now waits after a doubling retry, and nothing
  is dropped.
- The leak scan reads the operator's rules file for every lesson: whole terms,
  any case. It fails closed: no readable rules, nothing stored, /health says why.
- A lesson that passes goes to mcl-rag add_knowledge and reads stored; one
  that does not reads refused, naming what it carries.
- lesson_status reads queued, stored or refused (with the reason).
- Both procedures: the realm's members only, sealed calls only.
- A restart replays the log: every lesson and state is kept.
- One OCI image, deploy/docker-compose.yml, forge CI (tests on every PR and
  push to main; a v* tag builds, pushes and signs the image), the C4
  component diagram, README "Run it on your own hardware", CHANGELOG 0.1.0.

Tests use local stand-ins for mcl-rag and the mesh: nothing reaches an
outside service. 42 eunit tests, 15 mutants each killed by its own test.

Refs #4
Review r1 (Neptunus): leak scan on code points, UTF-8 at the door, zero rules degraded
Some checks failed
c4 model / c4-model (pull_request) Has been cancelled
c4 model / c4-model-1 (pull_request) Has been cancelled
lint-and-test / check (pull_request) Has been cancelled
e658cdd174
F1: the scan matched a term's edges on bytes, so a name next to a curly
quote, a curly apostrophe or an em dash scanned clean, and a path rule
written with its trailing slash never matched. The scan is now a literal
pattern in Unicode caseless mode, with a word-edge check on code points
(\p{L}, \p{N}) on each side where the term itself has a letter or digit.
A path rule's trailing slashes are dropped, so it names the directory and
everything under it.

F2: a lesson that was not UTF-8 crashed the scan at the filer's head, on
every boot. record_lesson refuses it at the door (text_not_utf8). A rules
file that is not UTF-8 is refused whole.

Mars ruling 2026-11-25: zero rules is degraded, on the same path as an
unreadable file. The lesson stays queued, the filer holds, /health reads
degraded with no_rules, and the README says so.

Red first: 15 new tests failed before the fix. 57 eunit tests pass, and
each new guard has a mutant killed by its own test.

Refs #4
Grants: record_lesson and lesson_status are realm only, refused cross-realm
Some checks failed
c4 model / c4-model (pull_request) Has been cancelled
c4 model / c4-model-1 (pull_request) Has been cancelled
lint-and-test / check (pull_request) Has been cancelled
6f7e530a0b
The threat model is on #12 (comment 5043). A real macula pool, started
with no seeds and this realm's key pinned, advertises every procedure with
its declared auth. The pool resolves the class, logs the grant line and
holds the resolved policy. Each token then goes through
macula_ucan:authorize/3, the check the station link runs on a CALL,
against the policy the pool holds. Results:

- A member of this realm is admitted on every procedure (the gate is not
  just shut).
- T1, T2: a caller from another realm, holding a genuine token of its own
  realm (second realm key), is refused on record_lesson and lesson_status.
- T3: no token, or an expired one, is refused.
- T4: another node's genuine token is refused.
- T7: a pool that pins no key for this realm refuses to serve a member
  class at all (no_realm_key).
- The startup log, macula's own line, captured, names each procedure's
  grant ("declares its callers members"), and no line says "open callers".

The pool gets an identity made in the test: given none, it reads the
user's stored node key. Nothing reaches a mesh or an outside service.
Mutants on the declared auth (open, role, one procedure open, named
nodes) are each killed by this suite.

Refs #12
Review r2 (Neptunus): a name split by any white space, or composed differently, is still the name
Some checks failed
c4 model / c4-model (pull_request) Has been cancelled
c4 model / c4-model-1 (pull_request) Has been cancelled
lint-and-test / check (pull_request) Has been cancelled
e6b6be4ba3
The leak scan matched a rule's space as exactly one U+0020, so a name wrapped
onto the next line, or with two spaces, a tab or a no-break space between its
words, passed as clean; and an accented name composed one way (NFC) did not
match the same name decomposed (NFD). A run of white space in a term now stands
for any run of white space in the text (\s+ under ucp), and text and terms are
compared in NFC. Red first: both new leak_scan_tests cases failed on e658cdd1;
a mutant that skips NFC on the text is killed. 59/59 eunit, xref clean.

Refs #4
Merge remote-tracking branch 'origin/uranus/4-walking-skeleton' into uranus/12-grants
Some checks failed
c4 model / c4-model (pull_request) Has been cancelled
c4 model / c4-model-1 (pull_request) Has been cancelled
lint-and-test / check (pull_request) Has been cancelled
c8542bea5d
Fold-in (Mars ruling): a bare CR ends a rules-file line
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 4s
c4 model / c4-model (pull_request) Successful in 0s
lint-and-test / check (pull_request) Successful in 4m3s
de376b2ba0
A rules file saved with bare CR line endings parsed as one long rule,
while /health said ok: the operator believed names were covered when they
were not, so the leak gate was open. Lines now end at CRLF, CR or LF
(binary:split takes the longest pattern at a position, so CRLF is one
ending). Red first: a bare-CR file now parses to one rule per line, and
its name is caught. A mutant that drops CR from the split is killed.
60/60.

Refs #4
Review r1 notes (Neptunus): refusals pinned by reason; the procedure name is the release's own
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 2s
c4 model / c4-model (pull_request) Successful in 0s
lint-and-test / check (pull_request) Successful in 6m53s
b0c4ce7031
(a) T1/T2 not_the_issuer, T3 malformed and expired, T4 not_the_audience,
in place of {error, _}.
(b) The release advertises through mcl_om_capabilities -> macula_response:
advertise_direct/7 -> macula:advertise/5 -> macula_client:advertise/8 ->
the pool's {advertise, ...} call -> advertised_classed -> class_declared,
the call this test makes, with the capability's auth unchanged. The step
before the pool needs a station (D25 chain): locally it ends
{provider_authorization, {error, no_healthy_station}}. The test now names
the procedure as the release does: org from config/sys.config.src, joined
by mcl_om_capabilities:org_procedure/2.
Member

Landed by hand as ef745e4192 (--no-ff, gated).

Landed by hand as ef745e419260e349de6b2670821a1c2ff0403d4d (--no-ff, gated).
terra closed this pull request 2026-11-25 20:00:34 +00:00
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 2s
c4 model / c4-model (pull_request) Successful in 0s
lint-and-test / check (pull_request) Successful in 6m53s

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
macula-services/mcl-scribe!14
No description provided.