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/src/runtime/rx_aegis.h # 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 / src / runtime / rx_aegis.h` 180 lines · 7741 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* 18 * rx_aegis.h -- AEGIS resident authority (ADR 0016 §41, R8). 19 * 20 * Authority relationships are world objects. Each client principal has 21 * capability slots: objects that hold the reference it presents for one 22 * resource. A reaction declares a slotted capability need, and the world 23 * reads the reference from the slot at every check (rx_world.h, 24 * cap_slotted). Holding a slot is not permission; the native AIENOS authority 25 * still validates the reference. 26 * 27 * fast path slot holds a live reference -> the reaction runs. No AEGIS 28 * activation, no policy round trip. 29 * slow path client publishes a request -> aegis.decide.k applies policy 30 * (GRANT, DENY, ESCALATE to a human, REVOKE on release) 31 * -> root.install.k mints through the AIENOS root and writes 32 * the slot -> the client's reaction wakes on the slot. 33 * 34 * Nothing here is called. The client does not wait for AEGIS; its reaction 35 * is simply not ready until its slot holds authority. 36 * 37 * Mint authentication. root.install is the only holder of the AIENOS admin. 38 * It mints only when 39 * - every decision field it uses was last written by that client's 40 * aegis.decide reaction (subject RX_AEGIS_SUBJ, faculty AEGIS), 41 * - every request field was last written by a reaction of the client's 42 * own subject, and the decision echoes that request, and 43 * - the grant stays inside the client's domain and rights ceiling and 44 * carries no privileged right. 45 * So a forged decision, a request written for someone else, or a policy 46 * mistake that widens a grant beyond the client's domain is refused by the 47 * root, whatever AEGIS said. AEGIS decides policy. The root decides only 48 * what may exist. 49 */ 50 #ifndef RX_AEGIS_H 51 #define RX_AEGIS_H 52 53 #include "aienos_cap.h" 54 #include "rx_world.h" 55 56 #include 57 #include 58 59 #define RX_AEGIS_CLIENTS 4u 60 #define RX_AEGIS_SLOTS 4u 61 #define RX_AEGIS_RULES 16u 62 63 enum { RX_OT_AUTH_REQUEST = 0x5810u, RX_OT_AUTH_APPROVAL, RX_OT_AUTH_DECISION, RX_OT_CAP_SLOT }; 64 65 /* request: 0 seq, 1 resource, 2 rights, 3 lease ticks (0 = policy default), 66 * 4 slot index, 5 op (client) 67 * approval: 0 request seq, 1 verdict (external, human) 68 * decision: 0 request seq, 1 verdict, 2 resource, 3 rights, 4 lease ticks, 69 * 5 slot index, 6 rule id or reason, 7 op (AEGIS) 70 * slot: 0 cap id, 1 generation, 2 state, 3 resource, 4 rights, 71 * 5 decision seq it answers, 6 lease expiry (0 = none), 72 * 7 root refusal reason (0 = none) (root) */ 73 enum { RX_AEGIS_OP_ACQUIRE = 1, RX_AEGIS_OP_RELEASE }; 74 enum { RX_AEGIS_APPROVE = 1, RX_AEGIS_REJECT }; 75 enum { RX_AEGIS_GRANT = 1, RX_AEGIS_DENY, RX_AEGIS_ESCALATE, RX_AEGIS_REVOKE }; 76 enum { RX_AEGIS_SLOT_EMPTY = 0, RX_AEGIS_SLOT_LIVE, RX_AEGIS_SLOT_REVOKED }; 77 78 /* Reasons in decision field 6 when not a rule id, and in slot field 7. */ 79 enum { 80 RX_AEGIS_WHY_NO_RULE = 1000, /* no rule covers subject, resource and rights */ 81 RX_AEGIS_WHY_PRIVILEGED, /* asked for a privileged right */ 82 RX_AEGIS_WHY_HUMAN, /* a human rejected it */ 83 RX_AEGIS_WHY_BAD_REQUEST, /* slot out of range, unknown op, zero rights */ 84 /* root refusals */ 85 RX_AEGIS_WHY_DECISION_ORIGIN, /* a decision field was not written by AEGIS */ 86 RX_AEGIS_WHY_REQUEST_ORIGIN, /* a request field was not written by the client */ 87 RX_AEGIS_WHY_MISMATCH, /* the decision does not echo the request */ 88 RX_AEGIS_WHY_DOMAIN, /* outside the client's domain or rights ceiling */ 89 RX_AEGIS_WHY_MINT /* the AIENOS root refused the mint */ 90 }; 91 92 /* One policy rule: subject may hold at most `rights` on [res_lo, res_hi]. */ 93 typedef struct { 94 uint32_t id; 95 uint32_t subject; 96 uint64_t res_lo, res_hi; 97 uint32_t rights; 98 uint64_t max_lease; /* 0 = no lease */ 99 uint32_t needs_approval; 100 } RxAegisRule; 101 102 typedef struct { 103 uint32_t n_rules; 104 RxAegisRule rules[RX_AEGIS_RULES]; 105 } RxAegisPolicy; 106 107 /* What the root will ever let exist for a client, whatever AEGIS decides. */ 108 typedef struct { 109 uint32_t subject; 110 uint64_t domain_lo, domain_hi; 111 uint32_t max_rights; 112 } RxAegisClient; 113 114 typedef struct { 115 RxObjRef request, approval, decision; 116 RxObjRef slot[RX_AEGIS_SLOTS]; 117 } RxAegisClientObjects; 118 119 /* Resources: RX_AEGIS_RES_BASE + client * RX_AEGIS_RES_STRIDE + index. */ 120 #define RX_AEGIS_RES_BASE 0x5810000ull 121 #define RX_AEGIS_RES_STRIDE 0x100ull 122 enum { RX_AEGIS_RES_REQUEST = 0, RX_AEGIS_RES_APPROVAL, RX_AEGIS_RES_DECISION, RX_AEGIS_RES_SLOT0 }; 123 124 static inline uint64_t rx_aegis_res(uint32_t client, uint32_t index) { 125 return RX_AEGIS_RES_BASE + client * RX_AEGIS_RES_STRIDE + index; 126 } 127 128 enum { RX_AEGIS_SUBJ = 41, RX_AEGIS_ROOT_SUBJ = 42 }; 129 130 /* Capability references the two faculties run under, per client. */ 131 typedef struct { 132 RxCapRef aegis_request, aegis_approval, aegis_decision; /* R, R, RW */ 133 RxCapRef root_request, root_decision; /* R, R */ 134 RxCapRef root_slot[RX_AEGIS_SLOTS]; /* RW */ 135 } RxAegisCaps; 136 137 typedef struct { 138 uint64_t seq; 139 RxCapRef ref; 140 } RxAegisMinted; 141 142 typedef struct RxAegisFaculty { 143 RxWorld *w; 144 AienosCapAdmin *admin; /* only root.install uses it */ 145 RxAegisPolicy policy; 146 uint32_t n_clients; 147 RxAegisClient client[RX_AEGIS_CLIENTS]; 148 RxAegisClientObjects o[RX_AEGIS_CLIENTS]; 149 uint32_t r_decide[RX_AEGIS_CLIENTS], r_install[RX_AEGIS_CLIENTS]; 150 struct { struct RxAegisFaculty *f; uint32_t k; } ctx[RX_AEGIS_CLIENTS]; 151 152 pthread_mutex_t mu; /* guards the root's record below */ 153 RxAegisMinted minted[RX_AEGIS_CLIENTS][RX_AEGIS_SLOTS]; 154 155 /* Observability only. */ 156 uint64_t mints, revokes, root_refusals; 157 /* R16 C5: this faculty's caller credentials (rx_caller.h); null in a 158 * world without bound callers. Held here, never published. */ 159 const RxCallerKeyring *keys; 160 } RxAegisFaculty; 161 162 /* Pure policy evaluation. Returns a verdict; *rule_or_why gets the rule id or 163 * a reason, *lease the granted lease ticks. Also used as the synchronous 164 * baseline when measuring what the fast path saves. */ 165 uint32_t rx_aegis_evaluate(const RxAegisPolicy *p, uint32_t subject, uint64_t resource, 166 uint32_t rights, uint64_t lease, uint64_t *out_lease, 167 uint32_t *rule_or_why, uint32_t *needs_approval); 168 169 int rx_aegis_create(RxAegisFaculty *f, RxWorld *w, AienosCapAdmin *admin, 170 const RxAegisPolicy *policy, const RxAegisClient *clients, uint32_t n); 171 172 int rx_aegis_register(RxAegisFaculty *f, const RxAegisCaps caps[]); 173 174 void rx_aegis_destroy(RxAegisFaculty *f); 175 176 /* Make caps[i] of a client reaction read its reference from a slot, and let 177 * the slot wake the reaction. Call before rx_world_add_reaction. */ 178 void rx_aegis_use_slot(RxReactionDesc *d, uint32_t i, RxObjRef slot); 179 180 #endif /* RX_AEGIS_H */