Commit graph

13 commits

Author SHA1 Message Date
trvon
31e44caab0
cli: honor <group> --help, and add fleet run for a standalone central node
`strawberry fleet --help` reported "unknown subcommand 'fleet --help'" and
then dumped the group's usage, even though docs/cli-ux.md promises that
`strawberry <cmd> --help` prints the same text as `strawberry help <cmd>`.
A group word followed by -h/--help now prints the group listing.

Centralized training had no single entry point: `fleet train` and
`fleet overlay` had to be run by hand (or through Salt), so a standalone
central node had no "run" command at all. `strawberry fleet run <bundle_dir>
[--out DIR]` trains and builds the overlay by calling the same two code paths,
so the behaviour cannot diverge, and prints the model/overlay paths.

It deliberately does not distribute to nodes, apply the overlay, or promote a
model: distribution stays behind the Salt canary cycle and promotion stays
behind `model promote` plus the fleet promotion gate. The JSON output carries
distributed=false and promoted=false so a script cannot mistake it.

Tests: fleet --help and fleet -h print the group without error; fleet run maps
to --fleet-run with optional dir, --out/--seed/--epochs passthrough, rejects
unknown options; a bare `fleet` still explains itself. Verified end to end on
two seeded bundles: model + overlay written to the requested directory.
2026-11-18 12:11:34 -07:00
trvon
69d86bbbc3
Rules R1: ship pinned yara-forge-core source snapshot in the release (no per-node fetch)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-11 13:21:12 -07:00
trvon
43efeac44c
Release: one version source, CI version contract, scripts/release.sh
Some checks failed
release / draft (push) Has been skipped
release / build (debian:trixie, trixie) (push) Has been cancelled
release / build (ubuntu:24.04, noble) (push) Has been cancelled
release / publish (push) Has been skipped
The version lived in three hard-coded copies (CLI `version`, daemon status,
banner); v0.2.0 shipped with the CLI still saying 0.1.0. meson.build is now
the only source: it passes STRAWBERRY_VERSION to every target, and the CLI
test requires the exact version.

packaging/ci/build-release.sh refuses to publish a tag build unless
meson.build, the tag and the built binary's `strawberry version` agree; CI
never rewrites the version.

scripts/release.sh X.Y.Z is the one manual release step: on a clean main
equal to forgejo/main it bumps meson.build, makes a signed commit and a
signed tag, and pushes both (--dry-run shows the plan). The Security Hub
release channel deploys signed tags only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:55:05 -07:00
trvon
29e490dcab
Replay: add strict read-only training summaries
Reuse the existing resolver/sampler for opt-in aggregate training summaries. Reject incomplete or undecodable snapshots without usable partial reports, retain best-effort readers elsewhere, and document cooperative extent checks rather than atomic snapshot guarantees. Include command-table/help, JSON, fixture and corruption regressions; no model training or promotion.
2026-11-03 06:54:17 -07:00
trvon
36982c4b56
Doctor: detect and retire findings for hashes you have since allowlisted
Some checks failed
Build and Test / build (debug, clang) (push) Has been cancelled
Build and Test / build (debug, gcc) (push) Has been cancelled
Build and Test / build (release, clang) (push) Has been cancelled
Build and Test / build (release, gcc) (push) Has been cancelled
Build and Test / macos (push) Has been cancelled
Build and Test / docker (push) Has been cancelled
Allowlisting a hash suppresses new detections but does not delete findings
already stored for it (e.g. the /usr/bin/ss false-positive storm). That cleanup
now lives in doctor instead of a one-off compaction.

- DetectionPipeline::retire_allowlisted_findings(dry_run): a finding is stale
  when it references at least one hash and every hash it references (from
  metadata "hashes" and file_<sha256> nodes) is allowlisted, so a finding that
  also implicates a non-allowlisted binary is never dropped. Mirrors
  retire_superseded_findings (retire_finding + transaction).
- node_ids.hpp gains content_hash_of_file_node_id() (the inverse of
  file_node_id for the content case) so the pipeline parses file ids through the
  canonical helper, not a "file_" literal (source invariant R8).
- Doctor check findings.allowlisted (warn) with maintenance action
  retire-allowlisted-findings; DoctorInputs.allowlisted_findings gathered by the
  daemon; run_maintenance handles the action; CLI `doctor fix` help + completion
  and API_CONTRACT updated.

Tests: test_retire_allowlisted_findings (two execs of a flagged binary -> a
finding; allowlist the hash -> dry-run lists it, apply retires it, idempotent);
doctor check ok/warn cases; CLI completion string. Suite 50/50; clang static
analyzer, clang-tidy and source invariants clean on the changed TUs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-28 11:37:52 -06:00
trvon
8f6bd1d4e0
Privacy: attribute tracker contacts to programs via OpenSnitch events
Some checks failed
Build and Test / build (debug, clang) (push) Has been cancelled
Build and Test / build (debug, gcc) (push) Has been cancelled
Build and Test / build (release, clang) (push) Has been cancelled
Build and Test / build (release, gcc) (push) Has been cancelled
Build and Test / macos (push) Has been cancelled
Build and Test / docker (push) Has been cancelled
Second piece of tracker attribution (docs/tracker-attribution.md): which
programs reach domains on a trackers list. Advisory only: never a block,
never a finding (source invariant R11).

- OpenSnitch event listener: OpenSnitch's JSON "remote" logger is the
  hostname source (Strawberry's eBPF connects have none). It streams over
  TCP and cannot leave fields out, so events carry command lines and
  environments. The listener binds 127.0.0.1 at a port below 1024 (only
  root can), accepts only root-owned peers (/proc/net/tcp), bounds
  clients/object size/buffering, and reads only pid, uid, path,
  destination and action; arguments and environment are never copied.
- TrackerContacts: per program x domain, bounded at 20000 keys. A root-only
  tracker_contact telemetry record (type 25) on the first contact, then at
  most hourly with the count since.
- Status `privacy` block; control verb privacy-trackers; CLI
  `strawberry privacy trackers [--json]`.
- `strawberry opensnitch enable-events` adds the logger to OpenSnitch's
  config (with a .bak); the installer runs it when OpenSnitch is present,
  unless privacy_trackers=false. Config: privacy_trackers (default true),
  opensnitch_events (default 127.0.0.1:979).
- EasyPrivacy is a default trackers feed (GPL-3.0+ or CC-BY-SA-3.0,
  downloaded at run time).

Tests: E1-E7 (test_opensnitch_events: event fields, stream splitting,
peer uid, address rules, listener end to end, contacts and record, config
editor), the control verb, CLI translation and help, daemon status. New
fuzz_opensnitch_events (90 s clean).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 06:15:28 -06:00
trvon
bbfda149a5
Stage 4: execute a promoted model's inspections, under guardrails
Some checks failed
Build and Test / build (debug, clang) (push) Has been cancelled
Build and Test / build (debug, gcc) (push) Has been cancelled
Build and Test / build (release, clang) (push) Has been cancelled
Build and Test / build (release, gcc) (push) Has been cancelled
Build and Test / macos (push) Has been cancelled
Build and Test / docker (push) Has been cancelled
A promoted model (promoted.sbm, written only by `model promote` after the
gate) can now request real inspections. Only two, both additive:

- memory_scan: through the daemon's memory-scan queue;
- deep_rescan: the root's image re-scanned on demand; new matches are
  recorded as indicators of kind model_inspection (findings titled "YARA
  match found by a deeper rescan the inspection model requested") and
  positive labels.

watch_subtree has no mechanism and rescan_on_next_rules is the retro-hunt's
job, so both are masked out of acting decisions (kExecutableActions), and
replay's policy evaluation uses the same action set.

Guardrails:
- InspectionExecutor (bounded queue, one low-priority worker, submit()
  never blocks); WorkClass::model_inspect lets the governor defer it, and
  a deferred decision is dropped.
- Each action rechecks that the promoted model is still active at the
  decision's generation (demoting or replacing it revokes queued work),
  that the root's node id and raw image path still match (decisions carry
  root_image, not the feature template), and skips protected processes.
  A deep rescan discards its result if the process, image or rules changed
  during the scan.
- An acting decision is durably written before it is dispatched; every
  attempt becomes an inspection_outcome record (queued, scanned, skipped,
  deferred, revoked, queue_full, failed).
- Source invariant R10: no file may couple learning types to the
  exec-guard, OpenSnitch or policy APIs (daemon_app.cpp and main.cpp, the
  wiring points, are reviewed by hand). Models never block, contain, kill
  or create findings directly.
- Config model_act and model_lambda; status model block reports acting
  stats; timings.model_inspection.

docs/evaluation/stage4-execution-gate.md amends the gate's method (not its
thresholds): executable action set, greedy promoted decisions, budgets as
estimated inspection seconds by scan profile.

Also: TerminalSafeBuf's destructor no longer lets an exception escape;
the health message clamps huge durations; replay timestamp overflow; the
Docker test build runs with -j2.

Tests: test_inspection_executor (every skip and execute path, revocation,
queue limits); shadow and replay acting cases; R10 fixture; fault injection
and invariant updates. Validation reported by the session that wrote it:
48/48 local, 46/46 Docker plus privileged live checks, 20 fuzz targets
(9.5M runs), three paired KPI runs without regressions (no acting model
was loaded, so active-inspection cost is not measured yet).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 21:03:57 -06:00
trvon
b6d667b797
Stage 4: evaluate inspection policies in replay; gated promotion
Some checks failed
Build and Test / build (debug, clang) (push) Has been cancelled
Build and Test / build (debug, gcc) (push) Has been cancelled
Build and Test / build (release, clang) (push) Has been cancelled
Build and Test / build (release, gcc) (push) Has been cancelled
Build and Test / macos (push) Has been cancelled
Build and Test / docker (push) Has been cancelled
- replay --policy-eval: over ranked windows, simulates the model and
  rarity-greedy (the same chooser, rarity score / 48 as the value), each
  with its own hourly budget, and tallies the shadow decisions the daemon
  logged. Hits are inspected "extra" positives: late labels or injected
  evaluation traces on windows rules did not flag at exec time. Labels are
  known after the fact, so every action's payoff is computable without
  propensity weighting. Reports CPU-seconds, inspections, hits, recall,
  hits per CPU-second and budget refusals.
- docs/evaluation/stage4-promotion-gate.md (pre-registered): at least 10
  extra positives, model efficiency >= 1.5x rarity-greedy, model recall
  not lower. promotion_gate() checks it.
- strawberry model promote [--inject FILE] [--warmup H] [--yes]: replays
  with the shadow model, applies the gate and only then writes
  promoted.sbm; asks for confirmation.
- learn/inspection.hpp: options, the greedy chooser and the
  inspection_action record, shared by shadow mode and the evaluation.
- Fix: the hourly budget reset whenever a window closed with an earlier
  timestamp than the hour's start (windows close roughly, not strictly,
  in time order), letting spend exceed the budget; in both shadow mode
  and the evaluation.

Tests: test_replay R11 (gate criteria; extra positives exclude rule-flagged
windows; spend within the budget; logged shadow decisions joined to their
windows); CLI translations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 12:41:20 -06:00
trvon
6a3efbc22a
Stage 4: train the inspection model offline from replay
Some checks failed
Build and Test / build (debug, clang) (push) Has been cancelled
Build and Test / build (debug, gcc) (push) Has been cancelled
Build and Test / build (release, clang) (push) Has been cancelled
Build and Test / build (release, gcc) (push) Has been cancelled
Build and Test / macos (push) Has been cancelled
Build and Test / docker (push) Has been cancelled
- Replay builds each window's WindowSummary as it goes (exec depth and
  locations, connections, writes, ptrace, module loads, scan outcomes,
  surprisal) and can collect training examples: features, a label (a
  detection or late label touched the window), time, root program and the
  rarity score. Sampled to at most 50k: positives up to a fifth,
  negatives by reservoir with at most 1% per root program.
  --inject-train traces become positive examples and are not evaluated.
- learn/train: the value head (and hidden layers) learn P(teacher
  positive) with a class-weighted log loss and Adam; positive-unlabeled
  data, so unlabeled is "not known bad", documented. Split by time
  (newest 20% tested); reports test loss, top-k hits and ROC AUC for the
  model and for the rarity baseline. Refuses with fewer than 5 positives.
  Deterministic for a seed. The policy head waits for shadow-mode
  inspection outcomes.
- CLI: `strawberry model train [store_dir] [--inject-train FILE]
  [--epochs N] [--seed N] [--out FILE] [--json]` writes the shadow model
  (generation after the newest existing one, a note saying what it was
  trained on); `strawberry model show [file]`; `strawberry replay --model
  FILE` ranks windows (and evaluates injections) by the model's value.
  Config model_dir (default /var/lib/strawberry/model).
- doctor: the model check loads promoted.sbm and shadow.sbm; an invalid
  file is a problem (it is never used).

Tests: test_train (gradients against finite differences, skipping steps
that cross a ReLU kink; a planted pattern learned to high AUC; determinism;
refusal without labels; roc_auc); test_replay R10 (examples, labels,
per-program cap, training traces, model ranking); CLI and doctor cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 11:26:12 -06:00
trvon
cedd7e7ad9
test_cli: completions list --yes for doctor fix
Some checks failed
Build and Test / build (debug, clang) (push) Has been cancelled
Build and Test / build (debug, gcc) (push) Has been cancelled
Build and Test / build (release, clang) (push) Has been cancelled
Build and Test / build (release, gcc) (push) Has been cancelled
Build and Test / docker (push) Has been cancelled
Fixes the test left failing by 47c3af7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 09:45:12 -06:00
trvon
47c3af735c
CLI: exit code 3 for "could not run here", confirm destructive actions
Some checks failed
Build and Test / build (debug, clang) (push) Has been cancelled
Build and Test / build (debug, gcc) (push) Has been cancelled
Build and Test / build (release, clang) (push) Has been cancelled
Build and Test / build (release, gcc) (push) Has been cancelled
Build and Test / docker (push) Has been cancelled
Decided 2026-10-27 (docs/cli-ux.md):
- Exit codes: 0 done/healthy, 1 negative result (unhealthy, not found,
  daemon refused), 2 usage, 3 could not run here (daemon unreachable,
  permission denied, store not readable, feature not built). Daemon
  unreachable used to exit 2, like a usage error.
- Process kill/suspend, quarantine, allowlist-add, protection-set to
  enforce, store compact and doctor fix (without --dry-run) say what they
  will do and ask "Proceed? [y/N]" on a terminal; Enter or EOF is no.
  Without a terminal they need --yes, else exit 2 with nothing done.
  This applies to the flag form too (--policy-set process-kill ...).
  The desktop app talks to the control socket directly and is unaffected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 09:44:52 -06:00
trvon
bf1e779706
CLI: safe terminal output, completions, no accidental daemons; UX guide
Some checks failed
Build and Test / build (debug, clang) (push) Has been cancelled
Build and Test / build (debug, gcc) (push) Has been cancelled
Build and Test / build (release, clang) (push) Has been cancelled
Build and Test / build (release, gcc) (push) Has been cancelled
Build and Test / docker (push) Has been cancelled
- Evidence strings are attacker-controlled: every CLI command's stdout
  and stderr now pass through a filter that shows control characters
  (C0, DEL, C1) and invalid UTF-8 as \xNN (src/term_safe.hpp), so a
  crafted process name or path cannot inject terminal escape sequences.
  The daemon's journal output is unchanged.
- `strawberry` alone prints help; an unknown word (`strawberry fix`) is an
  error with a "did you mean" hint. Both used to start a daemon as the
  calling user with the word as its config path. Config paths (contain
  '/' or end in .conf) still run the daemon, for older units.
- Shell completions generated from the command table: `strawberry
  completion bash|zsh|fish`; install.sh installs them under
  /usr/local/share.
- One correlation pass at daemon start (stored findings catch up with the
  current rules, e.g. stable ids), and retire-superseded-findings
  correlates first, so replacements exist before old copies are retired.
  The user's first run reported "no duplicates" for that reason.
- docs/cli-ux.md: CLI UX rules adapted from yams (grammar, flags, human
  and JSON output, status words, security rules for output, help and
  completions, adding a command, known gaps). Exit code 3 and
  confirmation prompts are proposed there, pending a decision. AGENTS.md
  and CLAUDE.md point to it.

tests/test_cli.cpp: bare and unknown words, terminal_safe and the stream
filter, completion scripts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 09:41:19 -06:00
trvon
fb6b905860
CLI: yams-style commands, with doctor and doctor fix
Some checks failed
Build and Test / build (debug, clang) (push) Has been cancelled
Build and Test / build (debug, gcc) (push) Has been cancelled
Build and Test / build (release, clang) (push) Has been cancelled
Build and Test / build (release, gcc) (push) Has been cancelled
Build and Test / docker (push) Has been cancelled
strawberry [--config PATH] [--json] <command> [<subcommand>] [args] [--flags]

status, doctor, doctor fix <action>, daemon run, findings list/show/
correlate, process search/trace/trace-node/suspend/resume/kill, scan
file/processes/memory, rules reload/update/check/fetch, policy show/set,
opensnitch enable-checksums, store verify/compact, replay, demo seed,
help [command], version.

One table in src/cli_commands.cpp defines each command (words,
positionals, flags, help) and how it maps onto the existing flag form,
which main() still parses; help is generated from the same table.
Unknown options and wrong arity print the command's usage. Process
actions validate node ids before building their JSON payload.

The older flag form (strawberry --status, strawberry <config>) still
works. The systemd units now run `strawberry daemon run --config ...` and
`strawberry rules fetch --config ...`. README, AGENTS.md and the
false-positive guide use the command form.

doctor renders the daemon's checks with their fixes; doctor fix runs a
maintenance action (with --dry-run). Against an older daemon the CLI says
to reinstall rather than "unknown command". replay explains that
telemetry is root-only instead of reporting zeros, and keeps config
output out of --json.

tests/test_cli.cpp: translations, flag-form passthrough, errors, help.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 09:32:02 -06:00