auditexport

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package auditexport serialises the tamper-evident audit trail into the formats a compliance pipeline consumes (Task 20167).

Three writers, one interface:

jsonl  one JSON object per line — lossless, the format to keep
csv    a flat table — the format a human opens in a spreadsheet
cef    ArcSight Common Event Format — the format a SIEM ingests

The package deliberately holds no database handle and no file handle: it writes events from a slice to an io.Writer. That keeps the format rules (which are fiddly, especially CEF's two-level escaping) testable against golden fixtures without a SQLite dependency, and lets the same code serve both the CLI's `--output file` and a future HTTP download.

Hashes are carried through every format. An export that dropped prev_hash and row_hash would be a list of claims about the past with no way to check them; carrying them means a recipient can re-run the chain verification against the export itself.

Index

Constants

This section is empty.

Variables

AllFormats lists the supported formats in the order help text shows them.

Functions

func Severity added in v0.0.6

func Severity(ev Event) int

Severity is an event's importance on CEF's 0–10 scale, the ranking the CEF header carries: what the audit forwarder maps onto a syslog severity, so the two formats rank an event alike (Task 20426).

func Write

func Write(w io.Writer, events []Event, opts Options) error

Write serialises events to w in the requested format.

Types

type Event

type Event = statedb.AuditEvent

Event is the row shape being exported, re-exported so callers need not import pkg/statedb just to name the type.

type Format

type Format string

Format selects the serialisation.

const (
	// FormatJSONL writes one JSON object per line. Lossless.
	FormatJSONL Format = "jsonl"

	// FormatCSV writes a header row followed by one row per event.
	FormatCSV Format = "csv"

	// FormatCEF writes ArcSight Common Event Format records.
	FormatCEF Format = "cef"
)

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat resolves a user-supplied format name, case-insensitively. "json" is accepted as an alias for jsonl: it is the name people reach for, and refusing it teaches nothing.

type Options

type Options struct {
	// Format selects the serialisation. Zero value is FormatJSONL.
	Format Format

	// ProductVersion is stamped into the CEF header so a SIEM can attribute
	// a record to the binary that produced it. Ignored by the other formats.
	// Defaults to "dev" when empty.
	ProductVersion string

	// MaxPayloadBytes truncates the payload field in CEF output. CEF has no
	// formal size cap but collectors routinely drop records past a few
	// kilobytes, and a step payload can be large. 0 selects the default;
	// negative disables truncation.
	MaxPayloadBytes int

	// JSONPayloadLimit bounds the payload of a JSONL record, for a transport
	// with a message size limit (the audit forwarder's syslog sink, Task
	// 20426). Zero, the default, never cuts: an export is lossless. A
	// payload over the limit is left out of the record, which says so —
	// payload_truncated, the payload's length and SHA-256, and an excerpt —
	// rather than arriving cut and looking whole.
	JSONPayloadLimit int

	// Provenance labels each record with the chain it came from and the hub
	// that sent it, for a stream that mixes chains (Task 20426). Nil leaves
	// the records as a single-chain export writes them.
	Provenance *Provenance
}

Options tunes an export run.

type Provenance added in v0.0.6

type Provenance struct {
	// Source is the chain's role: control-plane or project.
	Source string
	// Dir is the directory whose .cloop/state.db holds the chain.
	Dir string
	// Hub names the hub that sent the row. Empty leaves it out.
	Hub string
}

Provenance is where a row came from.

type Summary

type Summary struct {
	Format     Format
	Events     int
	FirstID    int64
	LastID     int64
	Actors     []string
	EventTypes []string
}

Summary describes an export run, for the CLI to report on stderr without polluting the exported stream on stdout.

func Summarize

func Summarize(events []Event, format Format) Summary

Summarize describes a set of events without serialising them.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL