8 Commits
Author SHA1 Message Date
lotherk 32ece44c58 apex-twin 1.0.4: detailed README, CNCL license, scope edge tests
- README rewritten for a first-time reader: the gate and its rule order, quick
  start, all 45 tools by group, transports, proxy and rewrite rules, findings/
  assets/traffic/reports, state layout, security model, limits, build and
  release targets, install layout, environment, source layout, 1.x promise.
- License changed to CNCL 1.1 (Could Not Care Less License). LICENSE carries the
  unchanged text; README, SECURITY.md and the man page point at it. make dist and
  make install ship LICENSE.
- Scope gap tests: deny_ip beats allow_ip, port range endpoints and neighbours,
  /25 boundary, IPv6 CIDR accept/refuse, apex vs subdomain vs wildcard matching
  (*.name not matching the apex), embedded host:port, trailing FQDN dot, and a
  failed scope_reload closing the gate. scope.c 75.9% -> 82.8%, total 79.4%.

397 checks, analyze clean, release-check green including distcheck 1.0.4.
2026-11-21 10:42:27 +00:00
lotherk b4af387333 apex-twin 0.30.0: install the doc set and a man page
make install now ships five documents into $PREFIX/share/doc/apex-twin/
(README, CHANGELOG, SECURITY, operations, artex-port) and a new apex-twin(1)
man page into $PREFIX/share/man/man1/. MANDIR is overridable like the other
directories; DESTDIR works as before.

docs/apex-twin.1 covers the five modes, the scope rule order, every environment
variable (state, scope, rewrite, serial, dry-run, timeouts, webhook, proxy and
HTTP caps, audit and evidence limits), the state files, examples for --check and
curl -x, the hard limits, and pointers to the longer docs. mandoc -T lint is
clean and groff renders it.

Verified: make install DESTDIR=/tmp/apex-install-test lists the four units/docs
plus man page with modes 644/755; make test 334/334; release-check green
including distcheck 0.30.0.
2026-11-21 09:43:07 +00:00
lotherk eebec07b80 apex-twin 0.29.0: cap evidence_save
APEX_EVIDENCE_MAX_BYTES (default 16 MiB, 0 unlimited) bounds one evidence blob.
Over the cap, t_evidence returns an error that names the variable and the actual
size, writes no file, and writes an audit deny line. --check and capabilities
report evidence_max_bytes.

Tests in a fresh state dir: 500 bytes under a 1000-byte cap is written; 2000
bytes is refused with APEX_EVIDENCE_MAX_BYTES in the message, evidence_list
still shows one file, and the audit has the deny; a limit of 0 accepts the same
2000 bytes. Red proof: disabling the check gives four red checks.

334 checks, coverage 76.9%, release-check green including distcheck.
2026-11-21 09:36:32 +00:00
lotherk d4192f95e1 apex-twin 0.28.0: bound the MCP HTTP face and time out half requests
The HTTP face forked a child per connection without a limit and read the head
with a blocking read, so a local client could hold children forever.

- APEX_HTTP_MAX_CHILDREN (default 64, max 1024) with a SIGCHLD handler,
  waitpid(WNOHANG) reaping and a counter. At the cap the parent answers 503
  'http busy' and audits it; a failed fork serves in the parent.
- APEX_HTTP_HEAD_TIMEOUT_MS (default 20000, 0 disables) is a deadline for the
  whole head and body using poll with the remaining time; expiry answers 408
  Request Timeout.
- Rejections (503, 408) half-close and drain what the client already sent before
  closing: closing with unread bytes sends RST and can swallow the response.
  http_send now has reason phrases for 408 and 503.
- --check and capabilities report both values.

Tests: cap of 1 with a held partial request -> second gets 503 'http busy';
after closing, the slot is reused and a valid initialize gets 200. A 500 ms head
timeout closes a half-sent head with 408 in under 2.5 s. Red proof: disabling
both turns those two checks red.

327 checks, coverage 76.9%, release-check green including distcheck.
2026-11-21 09:27:32 +00:00
lotherk f44df202ba apex-twin 0.27.0: rotate the audit log under flock
audit.log grew without a bound. APEX_AUDIT_MAX_BYTES (default 10 MiB, 0
disables) rotates it to audit.log.1 when the next line would cross the limit:
the size is checked, then re-checked under flock(LOCK_EX) on audit.log.lock, so
only one proxy child renames. Lines are still one write() each, so a line never
mixes with another writer. A child with an already-open fd keeps writing to the
renamed file, which is still a valid log; new writers open the new file.
audit_log reads the current file only. --check and capabilities report
audit_max_bytes.

Tests with a 300-byte cap and 12 audited calls: audit.log.1 exists, every
non-empty line in both files parses as JSON, audit_log still answers, and
APEX_AUDIT_MAX_BYTES=0 produces no .1. Red proof: disabling the rotation call
fails the rotation and rotated-file checks.

323 checks, coverage 77.1%, release-check green including distcheck.
2026-11-21 09:16:42 +00:00
lotherk 0309e04011 apex-twin 0.25.0: cap concurrent proxy children, fix concurrent audit
APEX_PROXY_MAX_CHILDREN (default 64, max 1024) bounds proxy children. SIGCHLD
now sets a flag and the parent reaps with waitpid(WNOHANG); at the cap the parent
answers 503 Service Unavailable with a 'proxy busy' reason and audits it instead
of forking. A failed fork still serves in the parent. --check and capabilities
report proxy_max_children.

The concurrency test exposed a real audit bug: append_line() wrote the JSON line
and the newline as two writes. With parallel children the writes interleaved and
audit_log() returned '{...}{...}' - invalid JSON at the caller. append_line()
now builds line+newline and writes once; audit_tail() reads with getline so a
command over 8 KiB is not split into half objects.

Tests: two slow requests fill a limit of 2, the third connection gets 503 with
'proxy busy', the refusal is audited, and a slot is usable after the children
exit. Red proof: removing the cap check turns the 503 and audit checks red.
One earlier run also showed the test racing a readiness child; the test now
retries admission and waits for both in-flight requests before probing.

309 checks, coverage 76.7%, release-check green including distcheck.
2026-11-21 08:54:51 +00:00
lotherk 1bb6f957e8 apex-twin 0.24.0: serve proxy connections in parallel
The proxy forks one child per accepted connection (SIGCHLD ignored, parent
closes the socket). A CONNECT tunnel no longer blocks the next request; each
child inherits the scope and the rewrite rules loaded at fork, and SIGHUP in the
parent reloads the rules for connections accepted afterwards. A failed fork
serves the connection in the parent instead of dropping it.

Concurrent captures are safe: apex_traffic_add reserves the id with O_EXCL on
tNNNN.json, creates the raw file O_EXCL (replacing a stale raw from a crashed
run), writes raw then JSON, and unlinks both on failure. The scan-then-write
race that would have let two children overwrite one record is gone.
next_traffic_id() is removed.

Tests: a CONNECT tunnel is held open against a silent TCP server; a GET through
the same proxy answers in under 2 s, three more parallel GETs all answer, and
the five captures (1 CONNECT, 4 GET) have unique ids. Red proof: putting the
serial accept loop back fails both timing checks.

303 checks, coverage 76.6%, release-check green including distcheck.
2026-11-21 08:41:55 +00:00
lotherk 6b52bcc547 apex-twin 0.20.0: operations run book, security policy, release tarball
docs/operations.md is the run book: install with DESTDIR/PREFIX, the two
systemd units and their hardening, the state directory and what to back up,
scope lifecycle and rule order, proxy/rewrite/webhook operation, upgrade and
rollback, limits (8 MiB MCP body, 1 MiB proxy body/response, 1024 findings per
report) and troubleshooting by refusal reason.

SECURITY.md states the trust boundaries and the threat model: the scope file and
webhook URL are operator-owned, loopback listeners have no auth, CONNECT is a
blind tunnel, target content is data, and a missing gate is the highest severity
report. It includes a hardening checklist and the non-goals.

make dist reads APEX_VERSION from src/apex.h and writes apex-twin-<version>.tar.gz
with Makefile, README, SECURITY, .gitignore, src/, vendor/, tests/, docs/,
examples/ and systemd/; object files, gcov data, __pycache__, build dirs, the
binary and .git are excluded. 48 entries, no forbidden path.

Verified: make dist -> 0.20.0 tarball; extract to /tmp, make, full suite 298/298;
repo suite 298/298; analyze 0 warnings. README links the new docs.
2026-11-21 08:14:26 +00:00