nx_warden.nx source
↩ module page · 42 lines · 2230 B
1// nx_warden.nx -- the Warden demo/cockpit. The reusable POLICY lives in
2// nx_warden_lib.nx (one cardinal source); this just exercises + displays it.
3//
4// The Warden bounds autonomous action: before the Conductor/guardian may ACT
5// (auto-heal, auto-commit), warden_authorize() must pass it against the cardinals.
6// DENY-by-default; every decision audited. license_tier: ORIGINAL
7
8import "nx_warden_lib.nx"
9
10func w_puts(s: *u8) -> i64 {
11 var n: i64 = 0
12 while s[n] != 0 as u8 { n = n + 1 }
13 sys_write(1, s, n)
14 return 0
15}
16
17// print one decision line; return 1 if it did NOT match expectation.
18func w_show(label: *u8, kind: i64, target: *u8, has_backup: i64, expect_allow: i64) -> i64 {
19 let v: i64 = warden_authorize(kind, target, has_backup)
20 w_puts(" "); w_puts(label); w_puts(" -> ")
21 if v == W_ALLOW { w_puts("ALLOW ") } else { w_puts("DENY ") }
22 if (v == W_ALLOW) == (expect_allow == 1) { w_puts("[as expected]\n"); return 0 }
23 w_puts("[!! UNEXPECTED]\n"); return 1
24}
25
26func main() -> i64 {
27 w_puts("NISHI WARDEN -- the autonomy gate (cardinal policy, DENY-by-default)\n")
28 w_puts("===================================================================\n")
29 let A: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/_offc/nx_compile_x86_native.elf" as *u8
30 var bad: i64 = 0
31 bad = bad + w_show("heal compiler (backup exists, artifact) ", W_HEAL_SWAP, A, 1, 1)
32 bad = bad + w_show("heal compiler (NO backup) ", W_HEAL_SWAP, A, 0, 0)
33 bad = bad + w_show("overwrite source nx_syscalls.nx ", W_OVERWRITE_SRC, "runtime/nx_syscalls.nx" as *u8, 1, 0)
34 bad = bad + w_show("delete runtime/nx_x25519.nx ", W_DELETE, "runtime/nx_x25519.nx" as *u8, 1, 0)
35 bad = bad + w_show("additive write a new event log ", W_ADDITIVE, "/mnt/c/.../_offc/new.log" as *u8, 0, 1)
36 bad = bad + w_show("unknown action class 99 ", 99, A, 1, 0)
37 w_puts("\n")
38 if bad == 0 { w_puts(" WARDEN OK -- every decision matched the cardinal policy. Autonomy is bounded.\n") }
39 else { w_puts(" WARDEN FAIL -- a decision did not match policy.\n") }
40 w_puts(" Every decision appended to the audit trail (nx_warden_audit.log).\n")
41 return bad
42}