v4 init.4th, steps 1 and 2: the ACL policy loaded after POST, then the search order

Captain Bob ruled "ACL at boot", loaded "From init.4th", the include
"Compose[d] in FORTH".
- capsules/v4/init.4th, at block 3980: S" v4:ACL.4th" CAPSULE-INCLUDE,
  then STARSHIPOS.
- capsules/v4/ACL.4th is the policy, git mv'ed from v4/capsule/ACL.fth
  and reflowed into chained 64x16 blocks, its text unchanged.
- CAPSULE-INCLUDE in centre.4th places a capsule and LOADs its lowest
  block. It is composed from CAPSULE-OPEN and CAPSULE-LINE, with no new
  C word.
- The mesh loads v4:init.4th after POST and COLD, its one fixed step
  there.

Test first in test_mesh_boot: the parity line, DOE without naming
STARSHIPOS, and ACL-BOOT pinned. The before-run failed.

After: 113 checks pass and POST is 990/990. All 52 tests, test-32 and
ASan/UBSan pass. The dictionary has 405 words. One amd64 session passes
18/18 with "ACL: active".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
Claude
2026-11-19 11:57:42 +00:00
parent fdf9c1946c
commit b13d452e66
17 changed files with 975 additions and 59 deletions
-57
View File
@@ -1,57 +0,0 @@
\ ACL.fth -- word-level access control: the policy.
\
\ This is v3's capsules/ACL.4th, as FORTH source the node compiles itself.
\ The capsule supplies the fields of an entry and the check (acl.v4,
\ compile.v4); what is strict, how long a TTL lasts and what is pinned is
\ decided here. Loading this file switches access control on: its last
\ line runs ACL-BOOT. A system that does not load it has none.
\
\ The xt these words take is what FIND and ['] give: the word's code.
FORTH DEFINITIONS
1 CONSTANT ACL-STRICT-MODE
0 CONSTANT ACL-TTL-MODE-VAL
\ the TTL of a cold word, tuned 2026-06-15 on v3
256 CONSTANT ACL-BASE-TTL
65535 CONSTANT ACL-MAX-TTL
\ ( xt -- xt ) for symmetry: the xt is the entry
: ACL-ENTRY ;
: ACL-STRICT ( xt -- )
DUP ACL-PINNED? IF DROP EXIT THEN ACL-STRICT-MODE SWAP ACL-MODE! ;
: ACL-TTL-MODE ( xt -- )
DUP ACL-PINNED? IF DROP EXIT THEN ACL-TTL-MODE-VAL SWAP ACL-MODE! ;
\ ( xt -- ttl ) a hotter word earns a longer TTL: heat/4 + 256, at most 65535
: ACL-TTL-COMPUTE ACL-HEAT@ 4 / ACL-BASE-TTL + ACL-MAX-TTL MIN ;
\ ( xt -- ) what the check runs when a word's TTL is 0.
\ STRICT: allow, and leave the TTL 0 so that every use comes back here.
\ TTL: compute a TTL from the word's heat; allow.
: ACL-RECHECK
DUP ACL-PINNED? IF DROP EXIT THEN
DUP ACL-MODE@ ACL-STRICT-MODE = IF
1 OVER ACL-ALLOW! 0 OVER ACL-TTL! DROP EXIT
THEN
DUP ACL-TTL-COMPUTE OVER ACL-TTL! 1 SWAP ACL-ALLOW! ;
\ the system CA's public key; placeholders, as in v3
0 CONSTANT ACL-CA-KEY-LO
0 CONSTANT ACL-CA-KEY-HI
\ ( req-hi req-lo -- allow? ) the fabric asks this word whether a channel
\ may be opened. The default approves every request; a policy edits this.
: HERMES-CHANNEL-OPEN? 2DROP 1 ;
\ ( -- ) default fields on every word; the words that enforce the policy
\ pinned; the recheck switched on
: ACL-BOOT
ACL-INIT-PRIMITIVES
['] ACL-RECHECK ACL-PIN ['] ACL-INIT-PRIMITIVES ACL-PIN
['] ACL-RECHECK ACL-HOOK !
LOG-INFO" ACL: active" ;
' ACL-BOOT ACL-PIN
ACL-BOOT
+4
View File
@@ -1365,6 +1365,10 @@ static int boot(v4_mesh *ms)
say("PARITY:V4_SYSTEM word_count="); v4_boot_say_dec(&bt, v4_boot_word_count(&h->n, ms->im));
say(" dict_hash="); v4_boot_say_hex(&bt, v4_image_dict_hash(&h->n, ms->im));
say("\n");
/* the system's init (MACHINE.md 3, step 5; docs/v4.0.0/plans/2026-11-18-v4-init.md): the loader's one fixed
* step after POST. Everything from here is init.4th's -- security on, the search order */
if (!load(ms, "v4:init.4th")) { say("V4: init.4th did not complete\n"); return 0; }
return 1;
}
+5 -2
View File
@@ -482,6 +482,9 @@ static int load_source(const char *name)
while (fgets(line, sizeof line, f)) {
size_t len = strlen(line);
num++;
/* a capsule's blocks, typed at the prompt in order: its headers are not FORTH, and `-->`, which chains
* to the next block when the kernel LOADs it, is an error at the terminal */
if (strncmp(line, "Block ", 6) == 0 || strcmp(line, "-->\n") == 0) continue;
if (len == 0 || line[len - 1] != '\n' || len > 80) { printf(" %s line %u: too long\n", name, num); fclose(f); return 0; }
(void)say(line);
/* every line is accepted: whatever it printed, it ended with " ok" and never with ERROR */
@@ -1632,9 +1635,9 @@ int main(void)
CHECK(is(say("SEE NOSUCH\n"), "SEE: not found\n ok\nok> ") && is(say("SEE\n"), "SEE: not found\n ok\nok> "), "a word that is not there");
CHECK(is(say("(.\")\n"), "(.\"): compile-only\n ERROR\nok> ") && is(say("(S\")\n"), "(S\"): compile-only\n ERROR\nok> "), "the string run-time words have names but cannot be run from the prompt");
/* ---- access control with its policy loaded: ACL.fth, FORTH source ---- */
/* ---- access control with its policy loaded: capsules/v4/ACL.4th, FORTH source ---- */
boot_bare();
CHECK(load_source("ACL.fth"), "ACL.fth compiles, every line of it");
CHECK(load_source("../../capsules/v4/ACL.4th"), "ACL.4th compiles, every line of it");
CHECK(strstr(out, "\033[32mINFO: \033[0mACL: active\n") == out && n.mem[ACL_HOOK] != 0, "and its last line switches access control on");
CHECK(is(say(": FOO 65 EMIT ; FOO ' FOO ACL-TTL@ . FOO ' FOO ACL-TTL@ .\n"), "A256 A255 ok\nok> "), "a word's first use is rechecked and earns it a TTL, which is then counted down");
CHECK(is(say(": SFOO 66 EMIT ; ' SFOO ACL-STRICT SFOO SFOO ' SFOO ACL-TTL@ .\n"), "BB0 ok\nok> ") && is(say("' SFOO ACL-MODE@ .\n"), "1 ok\nok> "),
+7
View File
@@ -131,6 +131,7 @@ int main(void)
CHECK(strstr(said, "PARITY:V4_CAPSULE name=v4:forth79.4th ") && strstr(said, "PARITY:V4_CAPSULE name=v4:centre.4th ")
&& strstr(said, "PARITY:V4_CAPSULE name=v4:hera.4th "), "FORTH-79 and the kernel's capsules, each with its parity line");
CHECK(strstr(said, "PARITY:V4_CAPSULE name=v4:starshipos.4th ") != 0, "starshipos.4th, with its parity line");
CHECK(strstr(said, "PARITY:V4_CAPSULE name=v4:init.4th ") != 0, "init.4th, after POST and COLD, with its parity line (MACHINE.md 3, step 5)");
{ /* every case, the kernel's too: Hera has its words (#189 Phase 7) */
char want[64];
const unsigned runs = v4_post_runs(v4_post_cases, v4_post_case_count, 1);
@@ -145,6 +146,12 @@ int main(void)
CHECK(how == V4_TEXT_COMPLETED && strcmp(r, "7 ") == 0, "a line to Hera: \"%s\" (%d)", r, how);
/* the capsules were placed in RAM, block n at n - R, and loaded from there (capsule blocks plan, step 4):
* forth79.4th's lowest block, 3948, is RAM block 1900 */
/* init.4th (docs/v4.0.0/plans/2026-11-18-v4-init.md, steps 1 and 2): security on, then the search order --
* checked first, before any line below changes the system (the COLD further down takes it all away) */
r = line(V4_MESH_HERA, "S\" ok\" DOE", &how);
CHECK(how == V4_TEXT_COMPLETED && strcmp(r, "ok") == 0, "init.4th set the search order: DOE is found without naming STARSHIPOS: \"%s\" (%d)", r, how);
r = line(V4_MESH_HERA, "' ACL-BOOT ACL-PINNED? . ' ACL-RECHECK ACL-PINNED? .", &how);
CHECK(how == V4_TEXT_COMPLETED && strcmp(r, "-1 -1 ") == 0, "init.4th turned security on: the ACL policy is loaded, its words pinned: \"%s\" (%d)", r, how);
r = line(V4_MESH_HERA, "1900 BLOCK 16 TYPE", &how);
CHECK(how == V4_TEXT_COMPLETED && strncmp(r, "( forth79.4th --", 16) == 0, "forth79.4th's lowest block is in RAM block 1900: \"%.20s\" (%d)", r, how);
/* starshipos.4th, a system capsule loaded before POST (MACHINE.md 3, step 3; ruled 2026-11-18) */