interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / argus / argus_abi.h

601 lines · 39116 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 * argus_abi.h -- ARGUS security event ABI and core defensive types, version 1 (event version byte 1; ABI minor 2 = v1.2, see below).
19 *
20 * ARGUS observes, detects, contains (by request), and defends. It never
21 * authorizes. Nothing in this header, or in anything that includes it, may
22 * mint, validate, or re-check a capability: the authority (native/capability)
23 * already decided, and the producer copies that decision's result code into
24 * the event. ARGUS cross-checks decisions against its own shadow state.
25 *
26 * Rules fixed by this header (see docs/adr/0017 in aien-architecture):
27 * - C only, freestanding-friendly: <stdint.h>/<stddef.h> only, no libc I/O.
28 * - Fixed 128-byte event, version byte first, no pointers, no variable
29 * length fields, no secret-sized field. Digests only.
30 * - Deterministic: no wall clock in any hashed field. Time = sequence +
31 * the authority's logical tick (aienos_cap_clock).
32 * - Capability reference = AienosCapRef layout (u32 id, u64 generation).
33 * The Omega stand-in rx_caproot (u32 generation) is NOT a source.
34 * - Principal = the authority's subject (u32). No parallel principal type.
35 * - Object = RxGenObject id (u32) + digest; World generation = the 64-bit
36 * rx_generation id. Object generation, when needed, travels in `resource`.
37 * - MachineId is a PROVISIONAL opaque 32-byte slot. Fabric identity is not
38 * designed here (cryptographic identity is on the operator's escalation list).
39 * - A Finding is evidence, never authority. A ContainmentRequest is a
40 * proposal to AEGIS, never an action.
41 * - Conventions fixed at integration (lanes B/D/E agree):
42 * CAPABILITY_GRANTED: `resource` = authority resource, `object_id` = rights
43 * mask (AIENOS_CAP_RIGHT_*), `principal` = subject.
44 * Producer sequence streams are keyed by (machine_id, CONSUMER flag bit);
45 * the core reports a repeat/decrease as ARGUS_F_SEQUENCE_ANOMALY and
46 * still applies the event. ARGUS_ERR_SEQUENCE is reserved for producers/ring.
47 * argus_event_encode and argus_chain_extend never validate their input
48 * (the core reuses chain_extend for its state digest); only decode/validate do.
49 * argus_core_ingest may return ARGUS_ERR_FULL or ARGUS_ERR_OVERFLOW after the
50 * event has already been applied; MALFORMED means nothing was applied.
51 * Detectors never raise ARGUS_F_TELEMETRY_LOSS for TELEMETRY_DROPPED; the core does.
52 * - Hostile-review rules (docs/HOSTILE_REVIEW.md, applied after the first review):
53 * Producer trust boundary (v1): argus_ring_push is reachable only from AEGIS/runtime
54 * code inside the trusted process, never from cognition (same split as the
55 * authority admin/view). Cryptographic producer attestation is ARGUS-3 work.
56 * validate rejects: ARGUS_FLAG_CONSUMER on any kind but TELEMETRY_DROPPED;
57 * cap_id >= ARGUS_CAP_MAX; sequence == UINT64_MAX; a class weaker than
58 * argus_event_min_class(kind) (producers may strengthen, never weaken);
59 * EXTERNAL_EFFECT_* with effect_class != EXTERNAL. argus_ring_push also
60 * refuses (ARGUS_ERR_MALFORMED) a class weaker than the kind minimum.
61 * Apply rules (core): an event that raises SEQUENCE_ANOMALY or AUTHORITY_REPLAY is
62 * detected but NOT applied. GRANTED applies only when the slot is UNSEEN or the
63 * generation is strictly above the shadow generation; otherwise AUTHORITY_REPLAY.
64 * REVOKED on an UNSEEN slot is AUTHORITY_REPLAY and creates no entry.
65 * LEASE_CREATED on a LIVE or REVOKED lease id is a finding (code 6, prior_sequence set)
66 * and is not applied: lease ids are never reused. WORLD_COMMITTED applies only when
67 * generation == shadow+1 (or shadow 0); a flagged commit is not adopted.
68 * Malformed events raise MALFORMED_EVENT (core) and are not applied or chained.
69 * Machine lifecycle: JOINED trust = max(OBSERVED, object_id) by rank (a machine cannot
70 * declare itself TRUSTED); TRUST_CHANGED may only move DOWN the rank order
71 * TRUSTED < OBSERVED < REATTESTATION_REQUIRED < RESTRICTED < QUARANTINED < UNTRUSTED;
72 * an upward move is TRUST_ESCALATION and is ignored (re-entry is ARGUS-1/2 work);
73 * TRUST_CHANGED for an unknown machine is MACHINE_IDENTITY_MISMATCH and creates no
74 * entry; REMOVED keeps a tombstone (state REMOVED, trust preserved, joined_sequence 0).
75 * Self-reported kinds 60-63 without shadow corroboration yield sync_allowed = 0 and
76 * containment NONE (a report is not evidence).
77 * Sequence gaps are expected (ring refusals) and are not findings.
78 * - v1.1 hot-path rules (after the lane H measurement: one 128-byte event per validate
79 * cost ~50 ns on a ~24 ns operation, -60% throughput; see docs/PERF.md):
80 * Emit on transition, count on use. Full events only for GRANTED/DENIED/REVOKED/
81 * WORLD_COMMITTED/errors/joins. A successful validate updates a per-thread
82 * 256-slot use table (count, min gen, max gen) and emits nothing.
83 * Flush policy (the explicit aggregation policy of brief section 3): every
84 * ARGUS_USE_FLUSH_OPS validates per thread AND at least every flush interval
85 * the producer emits one CAPABILITY_USE_SUMMARY per touched slot; a table that
86 * cannot flush (ring refused) keeps counting and the next summary carries the
87 * total, so no use is ever silently lost; refusals are still counted.
88 * Tick (aienos_cap_clock, a mutex) is read only for transition events; USED and
89 * summaries carry tick 0.
90 * A producer flushes a slot's pending summary BEFORE emitting GRANTED or REVOKED for
91 * that slot (a summary spanning a re-grant would read as stale/revoked use).
92 * The consumer uses ONE shared next_sequence for argus_ring_drain_drops across all
93 * rings (drop events share the zero-machine/stream-0/CONSUMER stream).
94 * A 9th World store is table-full: ERR_FULL + one CRITICAL TELEMETRY_LOSS, counted.
95 * One ring and one stream id per producer thread; no push lock; the consumer
96 * polls all rings. Sequence is per stream.
97 * cap_id 0 is the office capability and is checked like any other; "none" is
98 * ARGUS_CAP_NONE. validate accepts cap_id < ARGUS_CAP_MAX or == ARGUS_CAP_NONE.
99 * Detector 3 also requires cap_generation <= shadow generation (a use above the
100 * revoked generation is detector 1 territory).
101 * GRANTED/REVOKED should originate at the authority (observer hook, separate
102 * aienos PR); until then a mint outside rx_aegis is reported as FORGED.
103 * Table sizes: caps ARGUS_CAP_MAX, artifacts 256, incidents 256; every FULL is counted in health.
104 *
105 * - v1.2 (ARGUS-1 containment, docs/ARGUS1_SPEC.md; strictly ADDITIVE):
106 * The 128-byte event layout and ARGUS_ABI_VERSION (the event version byte, 1) are
107 * unchanged; static asserts below pin every v1.1 offset. ARGUS_ABI_MINOR = 2.
108 * Appended: kinds 90-93 (containment proposed/decided/executed, authority escalated),
109 * finding codes 17-21 (containment bookkeeping; never propose), the request fields
110 * after the ARGUS-0 ones plus its 152-byte canonical encoding, ArgusContainHealth,
111 * the containment table constants and argus_core_incident. Invariants I1-I5 bind:
112 * only RevokeCapability has a LIVE executor; FreezePrincipal is a declared stand-in
113 * with no executor (I2); no request type grants, mints or widens anything (I5.c).
114 *
115 * Wire encoding (argus_event_encode/decode): each field in the order below,
116 * little-endian, packed to exactly ARGUS_EVENT_SIZE bytes, offsets as noted.
117 * Event digest = SHA-256 of those 128 bytes. Chain digest =
118 * SHA-256(previous chain digest || event bytes).
119 */
120#ifndef ARGUS_ABI_H
121#define ARGUS_ABI_H
122#include <stddef.h>
123#include <stdint.h>
124
125#define ARGUS_ABI_VERSION 1u /* event version byte, unchanged since v1 (v1.1 and v1.2 are layout-identical; see ARGUS_ABI_MINOR) */
126#define ARGUS_ABI_MINOR 2u /* v1.2: ARGUS-1 containment, additive; the event version byte stays ARGUS_ABI_VERSION */
127#define ARGUS_EVENT_SIZE 128u
128#define ARGUS_DIGEST_LEN 32u
129#define ARGUS_MACHINE_ID_LEN 32u /* PROVISIONAL opaque identity slot */
130#define ARGUS_CAP_MAX 256u /* == AIENOS_CAP_MAX; cap_id >= this is MALFORMED, never "table full" */
131#define ARGUS_CAP_NONE UINT32_MAX /* "no capability". cap_id 0 is the authority OFFICE slot, a real capability. */
132
133/* Result codes. Negative, distinct from AIENOS_CAP_* (-1..-17) and RX_GEN_* (-40..-49). */
134#define ARGUS_OK 0
135#define ARGUS_ERR_ARG (-60)
136#define ARGUS_ERR_VERSION (-61)
137#define ARGUS_ERR_MALFORMED (-62) /* unknown class/kind/outcome, reserved bits set */
138#define ARGUS_ERR_FULL (-63) /* ring or table at capacity */
139#define ARGUS_ERR_SEQUENCE (-64) /* non-monotonic or replayed sequence */
140#define ARGUS_ERR_STATE (-65)
141#define ARGUS_ERR_OVERFLOW (-66) /* output buffer too small */
142
143/* Event class: what happens when the consumer falls behind. */
144enum {
145 ARGUS_CLASS_CRITICAL = 1, /* never dropped silently: full ring capacity, sticky overflow flag */
146 ARGUS_CLASS_SECURITY = 2, /* refused above the SECURITY watermark, counted */
147 ARGUS_CLASS_AUDIT = 3, /* refused above the AUDIT watermark, counted */
148 ARGUS_CLASS_INFORMATIONAL = 4, /* first to be refused, counted */
149 ARGUS_CLASS_MAX = 4
150};
151
152/* Event kinds. Values are stable forever; append only, never renumber. */
153enum {
154 ARGUS_EV_NONE = 0,
155 ARGUS_EV_CAPABILITY_GRANTED = 1, /* cap = NEW ref; object_id = rights; resource = resource; no parent ref in v1 */
156 ARGUS_EV_CAPABILITY_USED = 2,
157 ARGUS_EV_CAPABILITY_DENIED = 3,
158 ARGUS_EV_CAPABILITY_REVOKED = 4,
159 ARGUS_EV_CREDENTIAL_LEASE_CREATED = 10, /* object_id = lease id; resource = scope (USED: requested bits) */
160 ARGUS_EV_CREDENTIAL_LEASE_USED = 11,
161 ARGUS_EV_CREDENTIAL_LEASE_REVOKED = 12,
162 ARGUS_EV_ARTIFACT_ADMITTED = 20, /* evidence_digest = artifact digest (all ARTIFACT_*) */
163 ARGUS_EV_ARTIFACT_REJECTED = 21,
164 ARGUS_EV_ARTIFACT_ACTIVATED = 22, /* an admitted artifact began executing */
165 ARGUS_EV_MACHINE_JOINED = 30, /* object_id = initial ARGUS_TRUST_* (1..6); 0 => OBSERVED */
166 ARGUS_EV_MACHINE_TRUST_CHANGED = 31, /* object_id = new ARGUS_TRUST_* (1..6); other values ignored */
167 ARGUS_EV_MACHINE_REMOVED = 32,
168 ARGUS_EV_PROVIDER_DISCOVERED = 40, /* evidence_digest = provider id (all PROVIDER_*) */
169 ARGUS_EV_PROVIDER_CHANGED = 41,
170 ARGUS_EV_PROVIDER_QUARANTINED = 42,
171 ARGUS_EV_PROVIDER_USED = 43,
172 ARGUS_EV_EXTERNAL_EFFECT_REQUESTED = 50,
173 ARGUS_EV_EXTERNAL_EFFECT_DENIED = 51,
174 ARGUS_EV_EXTERNAL_EFFECT_COMMITTED = 52,
175 ARGUS_EV_INTEGRITY_VIOLATION = 60,
176 ARGUS_EV_SIGNATURE_FAILURE = 61,
177 ARGUS_EV_STALE_GENERATION = 62,
178 ARGUS_EV_FORGED_CAPABILITY = 63,
179 ARGUS_EV_WORLD_COMMITTED = 70, /* object_id = store/lineage id (several stores per process); world shadow per id */
180 ARGUS_EV_POLICY_CHANGED = 71,
181 ARGUS_EV_RUNTIME_BUILD_CHANGED = 72,
182 ARGUS_EV_TELEMETRY_DROPPED = 80, /* synthesized by the ring consumer: object_id = class, resource = count */
183 ARGUS_EV_CAPABILITY_USE_SUMMARY = 81, /* aggregation of successful validates per (cap_id, principal) since the last flush:
184 resource = count, cap_generation = MAX generation seen, world_generation = MIN
185 generation seen (64-bit; object_id unused = 0), tick = 0, outcome OK (else malformed). Detectors 1-3 treat it as a USED (3 checks max vs
186 REVOKED, 2 checks min vs shadow generation). The core applies nothing. Floor AUDIT. */
187 /* v1.2 containment kinds (spec section 3). All four: floor CRITICAL, effect_class NONE.
188 * 90-92: object_id = ARGUS_CONTAIN_PACK(type, status, finding_code), world_generation =
189 * request_id, evidence_digest = request digest. The core applies no shadow change and
190 * the detectors never treat them as triggers. */
191 ARGUS_EV_CONTAINMENT_PROPOSED = 90, /* ARGUS consumer only (CONSUMER flag); resource = finding_sequence; ring push refuses it */
192 ARGUS_EV_CONTAINMENT_DECIDED = 91, /* gate via bridge; outcome OK=GRANT DENIED=DENY ERROR=ESCALATE; code = WHY; resource = decision_id */
193 ARGUS_EV_CONTAINMENT_EXECUTED = 92, /* executor via bridge; code = authority rc; resource low32 = slots revoked, high32 = refused */
194 ARGUS_EV_AUTHORITY_ESCALATED = 93, /* Omega rx_aegis ESCALATE record; code = RX_AEGIS_WHY_*; resource = requested resource */
195 ARGUS_EV_KIND_MAX = 93
196};
197
198/* Effect class of the operation the event describes. Mirrors RX_WORK_* + none. */
199enum {
200 ARGUS_EFFECT_NONE = 0,
201 ARGUS_EFFECT_EPHEMERAL = 1, /* reversible, inside a World */
202 ARGUS_EFFECT_EVIDENCE = 2, /* durable evidence write */
203 ARGUS_EFFECT_EXTERNAL = 3, /* irreversible, leaves the system */
204 ARGUS_EFFECT_MAX = 3
205};
206
207/* Outcome as decided by the producer's authority; `code` carries its result code. */
208enum {
209 ARGUS_OUTCOME_OK = 1,
210 ARGUS_OUTCOME_DENIED = 2,
211 ARGUS_OUTCOME_ERROR = 3,
212 ARGUS_OUTCOME_MAX = 3
213};
214
215/* Flags. Bits 0-1 are markers; bits 2-15 are the producer STREAM id (14 bits, 0 = default).
216 * Sequence streams are keyed by (machine_id, stream id, CONSUMER bit), so each producer
217 * thread/ring owns a stream and its own monotonic sequence. */
218#define ARGUS_FLAG_SYNTHETIC 0x0001u /* produced by a test or replay, not a live producer */
219#define ARGUS_FLAG_CONSUMER 0x0002u /* synthesized by ARGUS itself (e.g. TELEMETRY_DROPPED) */
220#define ARGUS_FLAG_STREAM_SHIFT 2u
221#define ARGUS_FLAG_STREAM_MASK 0xFFFCu
222#define ARGUS_FLAG_KNOWN 0xFFFFu
223/* Every flag bit is now meaningful; "reserved bits" checks no longer apply in v1.1. */
224#define ARGUS_STREAM_OF(flags) ((uint16_t)(((flags) & ARGUS_FLAG_STREAM_MASK) >> ARGUS_FLAG_STREAM_SHIFT))
225#define ARGUS_STREAM_MAX 16384u
226#define ARGUS_STREAM_BRIDGE 16383u /* reserved for the serialized ARGUS/AEGIS bridge producer */
227
228/* Layout-identical to AienosCapRef in native/capability/aienos_capability.h. */
229typedef struct {
230 uint32_t cap_id;
231 uint64_t generation;
232} ArgusCapRef;
233
234/* Exactly ARGUS_EVENT_SIZE bytes on the wire, in this order. */
235typedef struct {
236 uint8_t version; /* off 0 = ARGUS_ABI_VERSION */
237 uint8_t class_; /* off 1 ARGUS_CLASS_* */
238 uint16_t kind; /* off 2 ARGUS_EV_* */
239 uint8_t effect_class; /* off 4 ARGUS_EFFECT_* */
240 uint8_t outcome; /* off 5 ARGUS_OUTCOME_* */
241 uint16_t flags; /* off 6 ARGUS_FLAG_* */
242 uint64_t sequence; /* off 8 producer-local, strictly increasing from 1 */
243 uint64_t tick; /* off 16 authority logical clock (aienos_cap_clock), 0 if unknown */
244 uint32_t principal; /* off 24 authority subject */
245 int32_t code; /* off 28 authority/producer result code (AIENOS_CAP_*, RX_GEN_*, 0) */
246 uint32_t cap_id; /* off 32 0 = the authority office capability; ARGUS_CAP_NONE = none */
247 uint32_t object_id; /* off 36 RxGenObject id, lease id, or 0 */
248 uint64_t cap_generation; /* off 40 */
249 uint64_t world_generation; /* off 48 rx_generation World generation id (64-bit), 0 = unknown */
250 uint64_t resource; /* off 56 authority resource, rights mask, or count */
251 uint8_t machine_id[ARGUS_MACHINE_ID_LEN]; /* off 64 PROVISIONAL */
252 uint8_t evidence_digest[ARGUS_DIGEST_LEN]; /* off 96 digest of the referenced object/artifact/policy, or zero */
253} ArgusEvent; /* end 128 */
254
255/* ---- Findings: evidence, never authority ---------------------------------- */
256
257enum {
258 ARGUS_SEV_INFO = 1, ARGUS_SEV_LOW, ARGUS_SEV_MEDIUM, ARGUS_SEV_HIGH, ARGUS_SEV_CRITICAL
259};
260enum {
261 ARGUS_CONF_DETERMINISTIC = 1, /* the only class permitted in ARGUS-0 */
262 ARGUS_CONF_STATISTICAL = 2, /* reserved for ARGUS-5+, must not appear in ARGUS-0 */
263 ARGUS_CONF_HYPOTHESIS = 3 /* reserved for ARGUS Hunt */
264};
265
266/* Stable finding codes. One per hard invariant. Append only. */
267enum {
268 ARGUS_F_NONE = 0,
269 ARGUS_F_FORGED_CAPABILITY = 1, /* used/granted ref never minted in shadow state, or authority said forged */
270 ARGUS_F_STALE_GENERATION = 2, /* ref generation older than the shadow's current generation for that slot */
271 ARGUS_F_REVOKED_CAPABILITY_USED = 3, /* shadow says revoked, event says outcome OK */
272 ARGUS_F_ARTIFACT_DIGEST_UNEXPECTED = 4, /* activated/used digest not admitted, or admitted digest changed */
273 ARGUS_F_SIGNATURE_INVALID = 5, /* producer reported a signature failure on a trusted-path object */
274 ARGUS_F_CREDENTIAL_SCOPE_VIOLATION = 6, /* lease used by other subject or outside its scope, outcome OK */
275 ARGUS_F_MACHINE_IDENTITY_MISMATCH = 7, /* event machine_id not the one recorded at join, or unknown machine */
276 ARGUS_F_EFFECT_CLASS_UNAUTHORIZED = 8, /* effect class exceeds what the capability's rights permit, outcome OK */
277 ARGUS_F_WORLD_PROVENANCE_INCONSISTENT = 9, /* WorldCommitted generation not prior+1, or digest conflicts */
278 ARGUS_F_QUARANTINED_USE = 10, /* provider/machine used after quarantine, outcome OK */
279 ARGUS_F_TELEMETRY_LOSS = 11, /* CRITICAL/SECURITY events were dropped: evidence gap */
280 ARGUS_F_SEQUENCE_ANOMALY = 12, /* replayed or out-of-order sequence from a producer */
281 ARGUS_F_AUTHORITY_REPLAY = 13, /* GRANTED not above shadow generation, or REVOKED of an unseen slot (core) */
282 ARGUS_F_SUBJECT_MISMATCH = 14, /* capability used with outcome OK by a principal other than the granted subject */
283 ARGUS_F_TRUST_ESCALATION = 15, /* TRUST_CHANGED/JOINED attempted to raise trust; ignored */
284 ARGUS_F_MALFORMED_EVENT = 16, /* validate rejected the event; core-raised, not applied */
285 /* v1.2: raised by argus_contain only; DETERMINISTIC, containment NONE, sync 0; never propose (no recursion). */
286 ARGUS_F_CONTAINMENT_DECISION_UNMATCHED = 17, /* HIGH: 91 unknown/closed request, digest/target echo mismatch, bad transition, foreign 90 */
287 ARGUS_F_CONTAINMENT_EXECUTION_UNAUTHORIZED = 18, /* CRITICAL: 92 DONE/PARTIAL or kind 4 on a target while not GRANTED (I5.d) */
288 ARGUS_F_CONTAINMENT_EXECUTION_UNCONFIRMED = 19, /* HIGH: 92 DONE with no matching kind 4 since the GRANT */
289 ARGUS_F_CONTAINMENT_UNANSWERED = 20, /* MEDIUM: no next step within ARGUS_CONTAIN_TIMEOUT_EVENTS; expires */
290 ARGUS_F_CONTAINMENT_SCOPE_EXCEEDED = 21, /* CRITICAL: GRANTed revoke produced > 1 kind 4, or 92 resource low32 != 1 (I1.b) */
291 ARGUS_F_MAX = 21
292};
293
294/* Recommended containment class. Advisory. AEGIS decides. Values 1..10 are the ARGUS-1
295 * request types (unchanged). None grants, mints or widens anything (I5.c). ARGUS-1: only
296 * REVOKE_CAPABILITY has a LIVE executor (I1); the other nine are SYNTH (typed and decided,
297 * executed only by a labelled test executor with ARGUS_CREQ_SYNTHETIC).
298 * FREEZE_PRINCIPAL is a stand-in with no executor (I2). */
299#define ARGUS_CONTAIN_LIVE_TYPE ARGUS_CONTAIN_REVOKE_CAPABILITY /* the only LIVE type in ARGUS-1 */
300enum {
301 ARGUS_CONTAIN_NONE = 0,
302 ARGUS_CONTAIN_REVOKE_CAPABILITY,
303 ARGUS_CONTAIN_FREEZE_PRINCIPAL,
304 ARGUS_CONTAIN_RESTRICT_PRINCIPAL,
305 ARGUS_CONTAIN_QUARANTINE_MACHINE,
306 ARGUS_CONTAIN_QUARANTINE_PROVIDER,
307 ARGUS_CONTAIN_REVOKE_CREDENTIAL_LEASE,
308 ARGUS_CONTAIN_REJECT_ARTIFACT,
309 ARGUS_CONTAIN_REQUIRE_REATTESTATION,
310 ARGUS_CONTAIN_RAISE_EFFECT_CLASS,
311 ARGUS_CONTAIN_PAUSE_EXTERNAL_EFFECTS,
312 ARGUS_CONTAIN_MAX = ARGUS_CONTAIN_PAUSE_EXTERNAL_EFFECTS
313};
314
315typedef struct {
316 uint16_t code; /* ARGUS_F_* */
317 uint8_t severity; /* ARGUS_SEV_* */
318 uint8_t confidence; /* ARGUS_CONF_DETERMINISTIC in ARGUS-0 */
319 uint8_t sync_allowed; /* 1 only if pre-established policy permits synchronous refusal at the boundary */
320 uint8_t containment; /* ARGUS_CONTAIN_* recommendation */
321 uint16_t detector; /* detector id (== code for hard invariants) */
322 uint64_t sequence; /* the triggering event */
323 uint64_t prior_sequence; /* the earlier evidence event (e.g. the revocation), 0 if none */
324 uint32_t principal;
325 uint32_t cap_id;
326 uint64_t cap_generation;
327 uint8_t machine_id[ARGUS_MACHINE_ID_LEN];
328 uint8_t event_digest[ARGUS_DIGEST_LEN]; /* digest of the triggering event bytes */
329} ArgusFinding;
330
331/* Typed proposal to AEGIS (spec section 2). A request is not authority; only an AEGIS GRANT is.
332 * ARGUS-0 fields keep their order and meaning; v1.2 appends after them. The authority side
333 * declares a layout-identical AienosContainRequest (every offsetof equal, lane G test).
334 * In-memory offsets are NOT the wire offsets (ArgusCapRef is 16 bytes in memory, 12 on the
335 * wire); the canonical encoding is ARGUS_CONTAIN_REQUEST_SIZE packed little-endian bytes. */
336typedef struct {
337 /* ARGUS-0 fields, unchanged wire offset */
338 uint64_t incident_id; /* 0 first_sequence of the (principal, code) incident; 0 = untracked */
339 uint8_t containment; /* 8 ARGUS_CONTAIN_* (request type, 1..ARGUS_CONTAIN_MAX) */
340 uint8_t severity; /* 9 of the triggering finding */
341 uint16_t finding_code; /* 10 ARGUS_F_* */
342 uint32_t principal; /* 12 target subject, or the finding's principal */
343 ArgusCapRef target; /* 16 cap_id (u32), 20 generation (u64): FROM ARGUS SHADOW (I1.d) */
344 uint8_t machine_id[ARGUS_MACHINE_ID_LEN]; /* 28 */
345 uint8_t finding_digest[ARGUS_DIGEST_LEN]; /* 60 argus_finding_digest of the trigger (I1.c) */
346 /* v1.2 appended */
347 uint64_t request_id; /* 92 per ARGUS instance, strictly increasing from 1 */
348 uint64_t finding_sequence; /* 100 sequence of the triggering event (I1.c); never 0 */
349 uint32_t target_object; /* 108 lease id / store id, 0 if n/a */
350 uint32_t target_rights; /* 112 RESTRICT: rights to remove; 0 otherwise */
351 uint8_t target_digest[ARGUS_DIGEST_LEN]; /* 116 artifact digest / provider id, zero if n/a */
352 uint16_t flags; /* 148 ARGUS_CREQ_* */
353 uint8_t version; /* 150 = ARGUS_CONTAIN_REQUEST_VERSION */
354 uint8_t reserved; /* 151 = 0, decode rejects nonzero */
355} ArgusContainmentRequest; /* wire end 152 */
356
357#define ARGUS_CONTAIN_REQUEST_SIZE 152u /* canonical encoding bytes; request digest = SHA-256 of them */
358#define ARGUS_CONTAIN_REQUEST_VERSION 2u /* request.version; independent of the event version byte */
359/* Request flags (request.flags). Decode rejects any other bit. */
360#define ARGUS_CREQ_SYNTHETIC 0x0001u /* test authorizer/executor or SYNTH type (I2) */
361#define ARGUS_CREQ_SATURATION 0x0002u /* table-saturation request (2.2): ask, never auto */
362#define ARGUS_CREQ_KNOWN 0x0003u
363
364/* Status carried in 90-92 object_id bits 8..15 (spec section 3). */
365enum {
366 ARGUS_CSTATUS_PROPOSED = 0, /* 90 */
367 ARGUS_CSTATUS_GRANT = 1, /* 91, outcome OK */
368 ARGUS_CSTATUS_DENY = 2, /* 91, outcome DENIED */
369 ARGUS_CSTATUS_ESCALATE = 3, /* 91, outcome ERROR */
370 ARGUS_CSTATUS_DONE = 4, /* 92, outcome OK */
371 ARGUS_CSTATUS_PARTIAL = 5, /* 92, outcome OK */
372 ARGUS_CSTATUS_FAILED = 6, /* 92, outcome DENIED or ERROR */
373 ARGUS_CSTATUS_UNAVAILABLE = 7, /* 92, outcome ERROR (no live executor for the type) */
374 ARGUS_CSTATUS_FAILED_SCOPE = 8, /* 92, outcome ERROR (I1.b) */
375 ARGUS_CSTATUS_MAX = 8
376};
377/* object_id = type | (status << 8) | (finding_code << 16) for kinds 90-92. */
378#define ARGUS_CONTAIN_PACK(type, status, code) \
379 ((uint32_t)(uint8_t)(type) | ((uint32_t)(uint8_t)(status) << 8) | ((uint32_t)(uint16_t)(code) << 16))
380#define ARGUS_CONTAIN_TYPE_OF(object_id) ((uint8_t)((object_id) & 0xFFu))
381#define ARGUS_CONTAIN_STATUS_OF(object_id) ((uint8_t)(((object_id) >> 8) & 0xFFu))
382#define ARGUS_CONTAIN_CODE_OF(object_id) ((uint16_t)((object_id) >> 16))
383
384/* argus_contain tables and limits (spec 4, 4.1, 4.2). Time = ingested events, never a clock.
385 * ARGUS_CONTAIN_WINDOW_MAX is I3.b enforcement: changing it is a spec change. */
386#define ARGUS_CONTAIN_PENDING 32u /* open requests */
387#define ARGUS_CONTAIN_RECENT 128u /* closed keys remembered for dedup / cooldown */
388#define ARGUS_CONTAIN_WINDOW_EVENTS 4096u /* proposal budget window */
389#define ARGUS_CONTAIN_WINDOW_MAX 16u /* proposals per window, globally (I3.b) */
390#define ARGUS_CONTAIN_TIMEOUT_EVENTS 16384u /* no next step -> EXPIRED, code 20 */
391#define ARGUS_CONTAIN_COOLDOWN_EVENTS 65536u /* re-proposal after DENY/EXPIRED/FAILED/FAILED_SCOPE */
392#define ARGUS_CONTAIN_RETRIES 1u /* re-proposals per key per lifetime */
393
394/* ARGUS-side mirrors for the never-propose filter (4.2 rule 2; defence in depth, not
395 * authority). libargus never includes aienos_capability.h; a test asserts equality. */
396#define ARGUS_CAP_RIGHT_REVOKE 0x020u /* == AIENOS_CAP_RIGHT_REVOKE */
397#define ARGUS_CAP_RIGHT_PRIVILEGED 0x3F0u /* == AIENOS_CAP_RIGHT_PRIVILEGED (MINT|REVOKE|RECLAIM|EPOCH|CLOCK|PROMOTE) */
398#define ARGUS_SUBJ_AEGIS 41u /* == RX_AEGIS_SUBJ (Omega rx_aegis.h) */
399#define ARGUS_SUBJ_AEGIS_ROOT 42u /* == RX_AEGIS_ROOT_SUBJ */
400/* AIENOS_CONTAIN_SUBJ (the gate's executor subject) is defined by the gate (lane G), not here. */
401
402/* Synchronous-eligible policy, ratified as DATA ONLY (spec section 7, I4; none wired):
403 * bit c set = argus_hard_detectors[] entry for code c has sync_allowed 1 (codes 1,2,3,4,5,8,10,14). */
404#define ARGUS_SYNC_RATIFIED_MASK \
405 ((1u << 1) | (1u << 2) | (1u << 3) | (1u << 4) | (1u << 5) | (1u << 8) | (1u << 10) | (1u << 14))
406
407/* argus_contain health (spec 4.3). ARGUS's own claims; never input to the I5.d audit. */
408typedef struct {
409 uint64_t requested, granted, denied, escalated, confirmed, failed, failed_scope, unavailable, expired;
410 uint64_t suppressed_dedup, suppressed_cooldown, suppressed_budget, suppressed_protected, pending_full;
411 uint64_t decisions_unmatched, executions_unauthorized, executions_unconfirmed;
412} ArgusContainHealth;
413
414/* ---- Shadow state view: what detectors may ask the core ------------------- */
415
416enum { ARGUS_SHADOW_UNSEEN = 0, ARGUS_SHADOW_LIVE = 1, ARGUS_SHADOW_REVOKED = 2, ARGUS_SHADOW_REJECTED = 3, ARGUS_SHADOW_REMOVED = 4 };
417enum {
418 ARGUS_TRUST_UNKNOWN = 0, ARGUS_TRUST_TRUSTED, ARGUS_TRUST_OBSERVED, ARGUS_TRUST_RESTRICTED,
419 ARGUS_TRUST_QUARANTINED, ARGUS_TRUST_UNTRUSTED, ARGUS_TRUST_REATTESTATION_REQUIRED
420};
421
422typedef struct {
423 uint32_t cap_id;
424 uint64_t generation; /* highest generation seen for this slot */
425 uint32_t state; /* ARGUS_SHADOW_* */
426 uint32_t subject;
427 uint32_t rights; /* AIENOS_CAP_RIGHT_* mask as granted */
428 uint64_t resource;
429 uint64_t granted_sequence;
430 uint64_t revoked_sequence;
431} ArgusCapShadow;
432
433typedef struct {
434 uint8_t machine_id[ARGUS_MACHINE_ID_LEN];
435 uint32_t trust; /* ARGUS_TRUST_* */
436 uint64_t joined_sequence; /* 0 = not joined or tombstoned by REMOVED (trust preserved) */
437 uint64_t changed_sequence;
438} ArgusMachineShadow;
439
440typedef struct {
441 uint8_t digest[ARGUS_DIGEST_LEN];
442 uint32_t state; /* LIVE = admitted, REJECTED, UNSEEN */
443 uint64_t sequence;
444} ArgusArtifactShadow;
445
446typedef struct {
447 uint32_t lease_id; /* event object_id */
448 uint32_t subject;
449 uint64_t scope; /* event resource at creation */
450 uint32_t state;
451 uint64_t sequence;
452} ArgusLeaseShadow;
453
454typedef struct {
455 uint8_t provider_id[ARGUS_DIGEST_LEN]; /* event evidence_digest at discovery */
456 uint32_t state; /* LIVE, REVOKED = quarantined */
457 uint64_t sequence;
458} ArgusProviderShadow;
459
460typedef struct {
461 uint32_t store_id; /* WORLD_COMMITTED object_id; the core keeps ARGUS_WORLD_STORES (8) of these */
462 uint64_t generation; /* last committed World generation (64-bit), 0 = none */
463 uint8_t digest[ARGUS_DIGEST_LEN];
464 uint64_t sequence;
465} ArgusWorldShadow;
466#define ARGUS_WORLD_STORES 8u
467#define ARGUS_USE_FLUSH_OPS 4096u /* default per-thread flush threshold for use summaries */
468
469typedef struct ArgusStateView ArgusStateView; /* opaque, owned by argus_core */
470
471/* Lookups return ARGUS_OK and fill *out, or ARGUS_ERR_STATE when unseen.
472 * All are O(1) or O(log n) over bounded tables. None allocate. */
473typedef struct {
474 int (*cap)(const ArgusStateView *v, uint32_t cap_id, ArgusCapShadow *out);
475 int (*machine)(const ArgusStateView *v, const uint8_t id[ARGUS_MACHINE_ID_LEN], ArgusMachineShadow *out);
476 int (*artifact)(const ArgusStateView *v, const uint8_t digest[ARGUS_DIGEST_LEN], ArgusArtifactShadow *out);
477 int (*lease)(const ArgusStateView *v, uint32_t lease_id, ArgusLeaseShadow *out);
478 int (*provider)(const ArgusStateView *v, const uint8_t id[ARGUS_DIGEST_LEN], ArgusProviderShadow *out);
479 int (*world)(const ArgusStateView *v, uint32_t store_id, ArgusWorldShadow *out);
480 /* Expected digest of the trusted policy / runtime build last announced. Zero digest = none. */
481 int (*policy_digest)(const ArgusStateView *v, uint8_t out[ARGUS_DIGEST_LEN]);
482 int (*runtime_digest)(const ArgusStateView *v, uint8_t out[ARGUS_DIGEST_LEN]);
483} ArgusStateOps;
484
485/* A detector sees the event and the shadow state BEFORE the core applies the
486 * event's own update. It writes up to `cap` findings and sets *n_out. It must
487 * be pure: no allocation, no I/O, no global state, no clock. */
488typedef int (*ArgusDetectorFn)(const ArgusStateOps *ops, const ArgusStateView *v,
489 const ArgusEvent *ev, ArgusFinding *out, size_t cap, size_t *n_out);
490
491typedef struct {
492 uint16_t id; /* == ARGUS_F_* it can raise */
493 uint8_t sync_allowed; /* policy: may a synchronous boundary refusal cite this? */
494 uint8_t containment; /* default ARGUS_CONTAIN_* */
495 const char *name;
496 ArgusDetectorFn fn;
497} ArgusDetector;
498
499/* ---- Lane entry points (declared here, implemented per lane) --------------- */
500
501/* argus_event.c (lane B): canonical encoding, validation, digests. */
502int argus_event_encode(const ArgusEvent *ev, uint8_t out[ARGUS_EVENT_SIZE]);
503int argus_event_decode(const uint8_t in[ARGUS_EVENT_SIZE], ArgusEvent *out); /* validates; rejects malformed */
504int argus_event_validate(const ArgusEvent *ev);
505uint8_t argus_event_min_class(uint16_t kind); /* weakest class allowed for a kind (see argus_event.c table) */
506void argus_event_digest(const ArgusEvent *ev, uint8_t out[ARGUS_DIGEST_LEN]);
507void argus_chain_extend(uint8_t chain[ARGUS_DIGEST_LEN], const ArgusEvent *ev); /* chain = H(chain || bytes) */
508void argus_finding_digest(const ArgusFinding *f, uint8_t out[ARGUS_DIGEST_LEN]);
509/* v1.2 (lane B): containment request canonical encoding (spec section 2). Encode never
510 * validates. Decode validates: containment 1..ARGUS_CONTAIN_MAX, severity valid, version
511 * ARGUS_CONTAIN_REQUEST_VERSION, reserved 0, flags within ARGUS_CREQ_KNOWN, request_id != 0,
512 * finding_sequence != 0; else ARGUS_ERR_MALFORMED / ARGUS_ERR_VERSION. */
513int argus_contain_request_encode(const ArgusContainmentRequest *r, uint8_t out[ARGUS_CONTAIN_REQUEST_SIZE]);
514int argus_contain_request_decode(const uint8_t in[ARGUS_CONTAIN_REQUEST_SIZE], ArgusContainmentRequest *out);
515void argus_contain_request_digest(const ArgusContainmentRequest *r, uint8_t out[ARGUS_DIGEST_LEN]); /* SHA-256 of the 152 bytes */
516
517/* argus_ring.c (lane B): single-producer/single-consumer bounded ring of events. */
518typedef struct ArgusRing ArgusRing;
519size_t argus_ring_footprint(uint32_t capacity_pow2); /* bytes needed for argus_ring_init */
520int argus_ring_init(ArgusRing **ring, void *memory, size_t bytes, uint32_t capacity_pow2);
521int argus_ring_push(ArgusRing *ring, const ArgusEvent *ev); /* producer; ARGUS_ERR_FULL never blocks */
522int argus_ring_pop(ArgusRing *ring, ArgusEvent *out); /* consumer; ARGUS_ERR_STATE when empty */
523size_t argus_ring_pop_batch(ArgusRing *ring, ArgusEvent *out, size_t max);
524typedef struct {
525 uint64_t pushed, popped;
526 uint64_t refused[ARGUS_CLASS_MAX + 1]; /* per class, index by class; index 0 = malformed pushes (never a loss) */
527 uint64_t critical_overflow; /* sticky count: evidence gap */
528 uint32_t depth, capacity;
529} ArgusRingStats;
530void argus_ring_stats(const ArgusRing *ring, ArgusRingStats *out);
531/* Consumer-side: turn accumulated refusals into TELEMETRY_DROPPED events (flag CONSUMER); returns count written. */
532size_t argus_ring_drain_drops(ArgusRing *ring, ArgusEvent *out, size_t max, uint64_t *next_sequence);
533/* Ring depth at which pushes of class_ start being refused (0 if capacity invalid). */
534uint32_t argus_ring_saturation_point(uint32_t capacity_pow2, uint8_t class_);
535
536/* argus_detect.c (lane E): the hard-invariant detector table. */
537extern const ArgusDetector argus_hard_detectors[];
538extern const size_t argus_hard_detector_count;
539int argus_detect_run(const ArgusStateOps *ops, const ArgusStateView *v, const ArgusEvent *ev,
540 ArgusFinding *out, size_t cap, size_t *n_out);
541
542/* argus_core.c (lane D): resident deterministic state engine. */
543typedef struct ArgusCore ArgusCore;
544size_t argus_core_footprint(void);
545int argus_core_init(ArgusCore **core, void *memory, size_t bytes); /* zero malloc after this */
546/* validate -> detect (pre-state) -> apply -> return findings. Deterministic for a given event stream. */
547int argus_core_ingest(ArgusCore *core, const ArgusEvent *ev, ArgusFinding *out, size_t cap, size_t *n_out);
548const ArgusStateView *argus_core_view(const ArgusCore *core);
549const ArgusStateOps *argus_core_ops(void);
550void argus_core_state_digest(const ArgusCore *core, uint8_t out[ARGUS_DIGEST_LEN]); /* canonical digest of all shadow tables */
551typedef struct {
552 uint64_t events_received, events_rejected, findings_emitted, incidents_open;
553 uint64_t detector_ns_total; /* only when the caller supplies timings; 0 in library */
554 uint64_t incidents_untracked; /* (principal, code) pairs beyond the incident table */
555 uint64_t producers_untracked; /* sequence streams beyond the producer table */
556 uint64_t tables_full; /* ingest calls that returned ARGUS_ERR_FULL */
557 uint64_t events_not_applied; /* detected but not applied (anomaly, replay, lease reuse, world skip) */
558 uint8_t chain[ARGUS_DIGEST_LEN];
559} ArgusCoreHealth;
560void argus_core_health(const ArgusCore *core, ArgusCoreHealth *out);
561/* v1.2 (lane D): first_sequence of the open (principal, code) incident -> ARGUS_OK, else ARGUS_ERR_STATE. */
562int argus_core_incident(const ArgusCore *core, uint32_t principal, uint16_t code, uint64_t *first_sequence);
563
564/* ---- v1.2 additivity proof: the v1.1 event layout is frozen ---------------- */
565_Static_assert(sizeof(ArgusEvent) == ARGUS_EVENT_SIZE, "ArgusEvent is 128 bytes");
566_Static_assert(offsetof(ArgusEvent, version) == 0, "v1.1 offset version");
567_Static_assert(offsetof(ArgusEvent, class_) == 1, "v1.1 offset class_");
568_Static_assert(offsetof(ArgusEvent, kind) == 2, "v1.1 offset kind");
569_Static_assert(offsetof(ArgusEvent, effect_class) == 4, "v1.1 offset effect_class");
570_Static_assert(offsetof(ArgusEvent, outcome) == 5, "v1.1 offset outcome");
571_Static_assert(offsetof(ArgusEvent, flags) == 6, "v1.1 offset flags");
572_Static_assert(offsetof(ArgusEvent, sequence) == 8, "v1.1 offset sequence");
573_Static_assert(offsetof(ArgusEvent, tick) == 16, "v1.1 offset tick");
574_Static_assert(offsetof(ArgusEvent, principal) == 24, "v1.1 offset principal");
575_Static_assert(offsetof(ArgusEvent, code) == 28, "v1.1 offset code");
576_Static_assert(offsetof(ArgusEvent, cap_id) == 32, "v1.1 offset cap_id");
577_Static_assert(offsetof(ArgusEvent, object_id) == 36, "v1.1 offset object_id");
578_Static_assert(offsetof(ArgusEvent, cap_generation) == 40, "v1.1 offset cap_generation");
579_Static_assert(offsetof(ArgusEvent, world_generation) == 48, "v1.1 offset world_generation");
580_Static_assert(offsetof(ArgusEvent, resource) == 56, "v1.1 offset resource");
581_Static_assert(offsetof(ArgusEvent, machine_id) == 64, "v1.1 offset machine_id");
582_Static_assert(offsetof(ArgusEvent, evidence_digest) == 96, "v1.1 offset evidence_digest");
583_Static_assert(sizeof(ArgusCapRef) == 16 && offsetof(ArgusCapRef, generation) == 8, "ArgusCapRef layout");
584_Static_assert(ARGUS_ABI_VERSION == 1u, "event version byte unchanged in v1.2");
585/* The ARGUS-0 request fields keep their in-memory offsets. */
586_Static_assert(offsetof(ArgusContainmentRequest, incident_id) == 0 &&
587 offsetof(ArgusContainmentRequest, containment) == 8 &&
588 offsetof(ArgusContainmentRequest, severity) == 9 &&
589 offsetof(ArgusContainmentRequest, finding_code) == 10 &&
590 offsetof(ArgusContainmentRequest, principal) == 12 &&
591 offsetof(ArgusContainmentRequest, target) == 16 &&
592 offsetof(ArgusContainmentRequest, machine_id) == 32 &&
593 offsetof(ArgusContainmentRequest, finding_digest) == 64,
594 "ARGUS-0 request fields unchanged");
595/* Wire size = sum of the field sizes (packed, target = 4 + 8). */
596_Static_assert(8 + 1 + 1 + 2 + 4 + (4 + 8) + ARGUS_MACHINE_ID_LEN + ARGUS_DIGEST_LEN + 8 + 8 + 4 + 4 +
597 ARGUS_DIGEST_LEN + 2 + 1 + 1 == ARGUS_CONTAIN_REQUEST_SIZE, "request wire size 152");
598_Static_assert(ARGUS_F_MAX == ARGUS_F_CONTAINMENT_SCOPE_EXCEEDED && ARGUS_EV_KIND_MAX == ARGUS_EV_AUTHORITY_ESCALATED,
599 "v1.2 maxima");
600
601#endif /* ARGUS_ABI_H */