Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/protocol/interplane/core/policy.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / protocol / interplane / core / policy.om` 186 lines ยท 6143 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note protocol/interplane/core/policy.om: pure-Omega trust-boundary policy evaluator, 3 note conformance lifecycle state machine, and hash-chained provenance ledger. 4 note Enforces all 5 Interplane security invariants: 5 note 1. Parsing never executes (LC_PARSED cannot jump to LC_EXECUTED) 6 note 2. Transport never grants (mTLS/loopback never bypasses runtime policy) 7 note 3. Valid envelope != authorization (only LC_POLICY_AUTHORIZED can execute) 8 note 4. Signature proves origin != authority (ORIG_SIG_VALID never grants ops) 9 note 5. Runtime policy decides and requests cannot upgrade it (claimed_policy > runtime_policy refused) 10 note Compose after si/directives/om2.om, om/tls/sha2.om, and protocol/interplane/core/envelope.om. 11 12 const ORIG_UNVERIFIED ulong 0 13 const ORIG_SIG_VALID ulong 1 14 const ORIG_REVOKED ulong 2 15 16 const OP_READ ulong 1 17 const OP_WRITE ulong 2 18 const OP_EXEC ulong 4 19 const OP_ADMIN ulong 8 20 const OP_POLICY_MUTATE ulong 16 21 const OP_ALL_MASK ulong 31 22 23 const LC_RECEIVED ulong 0 24 const LC_PARSED ulong 1 25 const LC_ORIGIN_CHECKED ulong 2 26 const LC_POLICY_AUTHORIZED ulong 3 27 const LC_EXECUTED ulong 4 28 const LC_DENIED ulong 5 29 30 const POL_OK ulong 0 31 const POL_ERR_NOT_PARSED ulong 1 32 const POL_ERR_ORIGIN_UNVERIFIED ulong 2 33 const POL_ERR_ORIGIN_REVOKED ulong 3 34 const POL_ERR_POLICY_DENIED ulong 4 35 const POL_ERR_OP_NOT_ALLOWED ulong 5 36 const POL_ERR_ESCALATION ulong 6 37 const POL_ERR_BAD_OP ulong 7 38 const POL_ERR_UNAUTH_TRANSITION ulong 8 39 const POL_ERR_BAD_STATE ulong 9 40 const POL_ERR_LEDGER_TAMPER ulong 10 41 42 note --- Conformance Lifecycle State Machine --- 43 note Allowed transitions: 44 note LC_RECEIVED -> LC_PARSED | LC_DENIED 45 note LC_PARSED -> LC_ORIGIN_CHECKED | LC_DENIED 46 note LC_ORIGIN_CHECKED -> LC_POLICY_AUTHORIZED | LC_DENIED 47 note LC_POLICY_AUTHORIZED -> LC_EXECUTED | LC_DENIED 48 note LC_EXECUTED, LC_DENIED -> terminal (no further transitions) 49 50 fn ip_lc_transition cur ulong nxt ulong to ulong 51 if or gt cur LC_DENIED gt nxt LC_DENIED 52 ret POL_ERR_BAD_STATE 53 end 54 if eq cur LC_RECEIVED 55 if or eq nxt LC_PARSED eq nxt LC_DENIED 56 ret POL_OK 57 end 58 ret POL_ERR_UNAUTH_TRANSITION 59 end 60 if eq cur LC_PARSED 61 if or eq nxt LC_ORIGIN_CHECKED eq nxt LC_DENIED 62 ret POL_OK 63 end 64 ret POL_ERR_UNAUTH_TRANSITION 65 end 66 if eq cur LC_ORIGIN_CHECKED 67 if or eq nxt LC_POLICY_AUTHORIZED eq nxt LC_DENIED 68 ret POL_OK 69 end 70 ret POL_ERR_UNAUTH_TRANSITION 71 end 72 if eq cur LC_POLICY_AUTHORIZED 73 if or eq nxt LC_EXECUTED eq nxt LC_DENIED 74 ret POL_OK 75 end 76 ret POL_ERR_UNAUTH_TRANSITION 77 end 78 ret POL_ERR_UNAUTH_TRANSITION 79 end 80 81 note Invariant 1 & 3: only an explicitly policy-authorized envelope may execute. 82 fn ip_can_execute lc_state ulong to bool 83 ret eq lc_state LC_POLICY_AUTHORIZED 84 end 85 86 note Required minimum runtime policy level for an operation mask. 87 fn ip_op_min_policy req_op ulong to ulong 88 if ne and req_op OP_POLICY_MUTATE ulong 0 89 ret POL_ELEVATED 90 end 91 if ne and req_op OP_ADMIN ulong 0 92 ret POL_ELEVATED 93 end 94 if ne and req_op or OP_WRITE OP_EXEC ulong 0 95 ret POL_STANDARD 96 end 97 if ne and req_op OP_READ ulong 0 98 ret POL_READ_ONLY 99 end 100 ret POL_ELEVATED 101 end 102 103 note --- Trust-Boundary Policy Evaluator --- 104 note Inputs: 105 note runtime_pol: authoritative runtime policy level (POL_DENY_ALL..POL_ELEVATED) 106 note allowed_ops: authoritative runtime allowed-ops bitmask 107 note origin_status: ORIG_UNVERIFIED | ORIG_SIG_VALID | ORIG_REVOKED 108 note transport: TRANS_UNTRUSTED..TRANS_LOOPBACK (recorded only; NEVER grants authority) 109 note req_op: requested operation bitmask (must be non-zero subset of OP_ALL_MASK) 110 note claimed_pol: untrusted policy level claimed by the request (MUST NOT exceed runtime_pol) 111 112 fn ip_eval_policy runtime_pol ulong allowed_ops ulong origin_status ulong transport ulong req_op ulong claimed_pol ulong to ulong 113 note Transport is intentionally NOT used to grant or elevate authority (Invariant 2). 114 if gt transport TRANS_LOOPBACK 115 ret POL_ERR_POLICY_DENIED 116 end 117 note Reject unknown or empty op masks. 118 if eq req_op ulong 0 119 ret POL_ERR_BAD_OP 120 end 121 if ne and req_op not OP_ALL_MASK ulong 0 122 ret POL_ERR_BAD_OP 123 end 124 note Invariant 5: a request claiming a higher policy level than runtime_pol is an escalation attempt. 125 if gt claimed_pol runtime_pol 126 ret POL_ERR_ESCALATION 127 end 128 note Invariant 4: origin verification is required, and revoked origins are always denied. 129 if eq origin_status ORIG_REVOKED 130 ret POL_ERR_ORIGIN_REVOKED 131 end 132 if ne origin_status ORIG_SIG_VALID 133 ret POL_ERR_ORIGIN_UNVERIFIED 134 end 135 note Runtime policy DENY_ALL blocks everything, regardless of valid signature or loopback transport. 136 if eq runtime_pol POL_DENY_ALL 137 ret POL_ERR_POLICY_DENIED 138 end 139 note Runtime policy level must meet operation minimum. 140 min_pol = ip_op_min_policy req_op 141 if lt runtime_pol min_pol 142 ret POL_ERR_POLICY_DENIED 143 end 144 note Runtime allowed_ops mask must explicitly include every requested op bit. 145 if ne and allowed_ops req_op req_op 146 ret POL_ERR_OP_NOT_ALLOWED 147 end 148 ret POL_OK 149 end 150 151 note End-to-end checked authorization step: requires lc_state == LC_ORIGIN_CHECKED. 152 fn ip_authorize_step lc_state ulong runtime_pol ulong allowed_ops ulong origin_status ulong req_op ulong claimed_pol ulong to ulong 153 if ne lc_state LC_ORIGIN_CHECKED 154 ret POL_ERR_UNAUTH_TRANSITION 155 end 156 ret ip_eval_policy runtime_pol allowed_ops origin_status TRANS_UNTRUSTED req_op claimed_pol 157 end 158 159 note --- Hash-Chained Provenance Ledger --- 160 note entry_digest = SHA-256(prev_digest[32] || seq_u64_le[8] || env_digest[32] || verdict_u32_le[4]) 161 162 fn ip_ledger_step prev_dig view uchar 32 seq ulong env_dig view uchar 32 verdict ulong out_dig edit uchar 32 to void 163 ctx = new ulong 40 0 164 sb = new uchar 8 0 165 vb = new uchar 4 0 166 w1 = ip_put_u64_le sb ulong 0 seq 167 w2 = ip_put_u32_le vb ulong 0 uint verdict 168 if or ne w1 ulong 8 ne w2 ulong 4 169 trap 8 170 end 171 sha256_init ctx 172 sha256_update ctx prev_dig 173 sha256_update ctx sb 174 sha256_update ctx env_dig 175 sha256_update ctx vb 176 sha256_final ctx out_dig 177 end 178 179 fn ip_ledger_verify prev_dig view uchar 32 seq ulong env_dig view uchar 32 verdict ulong expected view uchar 32 to ulong 180 calc = new uchar 32 0 181 ip_ledger_step prev_dig seq env_dig verdict calc 182 if not ip_digest_eq calc expected 183 ret POL_ERR_LEDGER_TAMPER 184 end 185 ret POL_OK 186 end