mirror of
https://github.com/morluto/rea.git
synced 2026-12-02 19:57:58 +00:00
* feat(artifacts): inventory auditd logs offline (#11345)
An acquired Linux audit.log can only be read today with ausearch or
aureport, which means letting a host tool interpret the file. Add a
read-only inventory that joins records on the full audit event identity:
timestamp seconds, milliseconds and serial, never the serial alone,
because auditd reuses serials across boots and on wraparound.
The first increment reports line, record and event totals, per-type
counts, the malformed line count with a bounded sample, and the duplicate,
out-of-order and interleaved records it found, with a bounded window of
events whose totals still cover the whole file. Record bodies are not
decoded yet: key-value fields, hex and escaped values, argument ordering
and decoded syscall or permission meanings are named as limitations, and
the reader treats the log as neither complete nor authentic.
An auditd log declares no members, so the inventory is attached to the
root occurrence and open() refuses every entry.
Verified: npm run check:fast (typecheck, lint, architecture guards) and
npm run docs:check pass; 89 tests across the new reader test, format
descriptors, target-format vocabularies, recognition, graph, snapshot and
subject suites pass. No built or packaged CLI/MCP workflow was run.
* style(auditd): format the auditd reader and its test
format:check failed on src/domain/linux/auditdLog.ts and its reader test in CI; applying oxfmt is the whole change.
* fix(auditd): key repeated records on the PATH item index
Repeated types were joined on items=, which is the path count on a SYSCALL record, not a per-record index. Every PATH record of a multi-path event therefore shared one key: the second path was reported as a duplicate and the per-event PATH count came out as one. Use item= instead, and cover a two-path event.
* fix(auditd): join events per host and bound retained state
Address the review on #12062:
- Include the node= prefix in the event join key. Timestamp plus serial is
only unique within one host, so a centralized log merged records from
different hosts into one event. The reported event_id carries the node.
- Bound retained event state to a window. Duplicate and interleaving
detection kept every PendingEvent for the whole file; records past the
window are counted in the totals and a limitation says their status is
not established.
- Pad the reported event timestamp millis to three digits so
audit(1700000000.005:12) no longer reads as 500 ms, while still joining a
padded record to an unpadded peer (via the numeric key).
- Detect duplicates per record content instead of record type plus item=,
so split EXECVE continuations are counted, not called duplicates.
- Re-check cancellation after the coverage callback resolves, so an abort
during the final await reports cancelled rather than success.
- Account for bytes dropped after a line overflows, so EOF trailing_bytes
covers the whole tail.
- Drop docs/specs/linux/auditd-log/, which conflicts with AGENTS.md.
* style(auditd): wrap the retained-window guard to the repo width
oxfmt --check failed on this line after 053151eaf: the guard exceeds the
80-column print width, so Static checks never reached typecheck or lint.
* fix(auditd): count interleaved events past the display sample
interleaved_event_count scanned #sampleOrder, which holds only the first
AUDITD_INLINE_EVENT_LIMIT (32) events. An event whose resumption arrives
after the 32nd event was marked interleaved in the retained map but never
reached by the count, so a log of 34 events reported 0 interleaved where
one was actually interrupted. Every retained event is still tracked, so
this undercount had nothing to do with the retention window.
Count the transition once, where the flag is set, and read that counter in
the inventory. The per-event flag still drives the inline detail.
* fix(artifacts): keep an auditd log a resource, not an executable
The auditd-log descriptor inherited roleContainer: false from plain, and
artifactRoleForFormat falls through to "executable" for any format whose
bytes classify as neither file nor a container. Inspecting a text audit log
therefore reported and saved artifact_kind: executable.
Give the descriptor an explicit non-executable role and consult it before
that fallback. Only formats that declare a role are affected, so the other
descriptors keep their current kind.
* fix(auditd): keep event totals exact past the window and hash raw record bytes
Two review findings on the bounded-window rewrite were real:
- Past the 4096-event retention limit every record of an event that was not
retained incremented the beyond-window tally, so a later event whose records
are contiguous was counted once per record (4096 + SYSCALL/EXECVE/PATH
reported 4099 events, not 4097). Only a record whose identity differs from
the previous record can be shown to start an event there; counting just
those keeps a contiguous tail exact, and an interleaved one a lower bound.
- Duplicate detection hashed the decoded body text, so two records differing
only in bytes UTF-8 cannot represent both decoded to U+FFFD and were
reported as byte-identical duplicates. Hash the line's raw bytes instead.
Since joins stop at the window, event_count and omitted_events can be lower
bounds there; the metadata now says so with event_count_lower_bound and the
limitation text reads "at least N further events".
* style(auditd): format auditdLog.ts to satisfy oxfmt
The static checks lane failed only on format:check: the chained
createHash(...).update(...).digest(...) call was wrapped over three lines,
which the repository formatter joins into one. Running the formatter
rewrites that single expression; no behaviour changes.
* fix(auditd): accept a line-separator character in a record body
RECORD_HEADER's body group used `.*`, and JavaScript's dot excludes U+000D, U+2028 and U+2029. A record whose opaque body carried one of them failed the header match, so the scanner dropped it (or, as the first line, failed auditd-log recognition outright) and reported a malformed header even though the header itself was valid. Body interpretation is out of scope for this inventory, so match it with [\s\S]* and keep the record.
* test(auditd): align auditd inventory and stable artifact suites with main
Merging main brought two contract changes these tests still asserted the old shape for: #14225 moved an invalid chunk size to an internal invariant violation and an impossible descriptor byte count to io, and #14189 added contentArchitecture to the classification role. The auditd role test added here predates the new field, so Source tests failed on contentArchitecture: null and shard 9 failed on the two stable-artifact reasons.
Assert the reasons and fields the producers now return so both lanes match the intended contract.
* fix(auditd): report the tail event total as an upper bound and bound record digests
The retained-window counter increments once per run of records that does not continue the previous identity, so an interleaved tail event (A, B, A) is counted once per run and the total is an upper bound, not a lower bound as the flag and limitation claimed. The flag is renamed to event_count_upper_bound and set only when a tail identity repeats, which is the case where the count can exceed the evidence.
Duplicate detection also kept one digest per distinct record body of a retained event until EOF, so a single event with a long run of records could grow without bound inside the admitted 4 GiB. Digests are now capped per event and records past the cap are counted but not checked, with a limitation naming duplicate_record_count as a lower bound.
* fix(auditd): name the type-sample omission and type the 4 GiB ceiling refusal
An event with more than 16 record types listed only 16 of them in its sample and said nothing about the rest, so a reader comparing record_types against record_count saw a silent loss. The inventory now carries a limitation naming how many sampled events were cut. The over-4-GiB refusal carried only a boundary, so CLI and MCP could not report it as a typed fixed ceiling; it now goes through artifactFixedLimitFailure with the 4 GiB allowance, registered as pending a control under #11345.
* fix(auditd): publish inventory metadata only after the source re-verifies
The final source read checks that the file did not change while it was decoded. Assigning #metadata and #limitations before that read meant a failed entries() still exposed an inventory through formatMetadata(), which is unvalidated Evidence rather than a refusal.
* test(auditd): feed the auditd role test through the classification probe
Static checks failed to typecheck this file on the PR: the new test built
ArtifactClassificationEvidence by hand as {prefix, asarHeader}, which predates
main's xmlPlistSignature, fatHeader and fatSliceHeadersByOffset members. Every
sibling assertion in the same file builds evidence with
createArtifactClassificationProbe(), so construct it the same way instead of
repeating the interface as a literal that breaks whenever the probe gains a
field.
* fix(auditd): raise a malformed log as a malformed target after the main merge
Main renamed the region decoder's format kind to malformed (#14265), so the auditd branch's `kind: "format"` no longer compiles. Keep the same behaviour through main's naming: the domain scanner reports `malformed`, and the reader turns it into `malformedArtifact` instead of building a bare `format` failure, matching DecodedRegionArtifactReader.
* fix(pe): accept auditd-log as a PE overlay leading format
The auditd-log recognizer was registered on main while this branch added
PE_OVERLAY_LEADING_FORMATS entries, so recognizeLeadingFormat's return
type no longer assigned to PeOverlayLeadingFormat and typecheck failed.
Recognizers can name auditd-log, so the overlay leading-format list has
to include it.
* fix(auditd): bound retained type state and carry type omissions
Two retained tables grew with the file rather than with the fixed budgets:
the whole-file per-type totals kept every distinct type= label a crafted
log named, and a single event kept one per distinct label it met. Both are
now capped, and records under a label past a cap are still counted in
record_count/line_count while the omitted labels are reported: the file
total names its omission in a limitation, and a sampled event carries
record_types_omitted next to record_types.
The tail event bound also now distinguishes an upper bound (a repeat while
other tail identities were held) from a lower bound (the single tail
identity repeated) and from no bound at all (an identity could not be
held), so event_count no longer claims a direction it cannot support.
* fix(auditd): judge ordering per node and keep header identity byte-faithful
Four review findings against the auditd inventory:
- Ordering compared every record against one global maximum, so a centralized
log with two hosts reported normal mixed-node acquisitions as out of order.
Track the greatest identity per node, bounded like the type table.
- Header bytes were decoded lossily, so two node/type values differing only in
bytes UTF-8 cannot represent collapsed to the same U+FFFD and joined as one
event. Decode each byte to its own code point so identity is preserved.
- The per-event type cap counted records rather than distinct labels, so two
records of one 65th type reported two omitted labels and two affected events
for a single event. Count distinct labels in a set.
- A tail run that reclaimed a retained identity still reported the total as an
exact count or a lower bound. Any repeat inflates the total, so only the upper
bound holds; event_count_lower_bound is now always false.
- The reader blamed the bytes before re-verifying the source, so a file that
changed mid-read reported as malformed. Re-verify before translating.
* fix(auditd): bound omitted labels per event and report source text as written
The per-event set of labels named past the type cap grew with the file, so a
crafted log could retain millions of strings after the event and digest caps
were full. It is now bounded by AUDITD_RETAINED_OMITTED_TYPE_LIMIT; past it the
event reports record_types_omitted_exact: false and a limitation says the count
is a lower bound.
The byte-faithful header mapping kept identities apart but was also returned as
text, so a UTF-8 node, type or malformed-line excerpt such as hôte or échec was
reported as different characters. Lookup keys stay byte-faithful; reported text
is decoded as UTF-8, with a *_hex field carrying the raw bytes only when they
are not valid UTF-8. event_id percent-encodes the node bytes so distinct raw
nodes still never share an identity. Recognition now reads the first line
through the same decoding as the scanner.
* fix(auditd): decode long candidate prefixes in bounded chunks
Format recognition hands every candidate the whole leading buffer, and the
byte-faithful header mapping spread its code points into one
String.fromCodePoint call. A prefix of a few hundred kilobytes therefore
overflowed the call stack, so a large text member surfaced as an adapter
failure instead of a refused auditd claim. Nine ReleaseExposureReader
members with oversized text hit this.
Decode in fixed-size chunks so the argument list stays bounded; the mapping
is unchanged, and 4 MiB of prefix now answers instead of throwing.
---------
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>