apex-twin 0.11.0: package the binary, the docs and the units

make install now installs four things, with DESTDIR/PREFIX respected:
  $PREFIX/bin/apex-twin
  $PREFIX/share/doc/apex-twin/README.md
  $PREFIX/lib/systemd/system/apex-twin.service
  $PREFIX/lib/systemd/system/apex-twin-proxy.service

--check and the capabilities tool report rewrite_rules and
webhook_configured (a boolean: the URL is never printed), so an operator can
see whether the proxy will rewrite and whether a critical finding will wake
anyone, without starting a server or reading the env.

Tests: --check counts two rules from a temp rewrite.json, reports the webhook
when APEX_WEBHOOK is set and keeps the URL out of its output, survives an
invalid rewrite file (0 rules, old behaviour), and capabilities returns the same
state to the model. make install DESTDIR=/tmp/apex-install-test was run by hand:
four files, modes 755/644/644/644.

45 tools, 239 checks. Red proof: hardcoding both operational fields to 0/false
turned three checks red.
This commit is contained in:
lotherk committed 2026-11-21 07:22:32 +00:00
1 parent 01dc9f39c0
commit f385979be9
6 files changed
+88 -13

No files matched your search

+8 -2
View File
@@ -3,6 +3,9 @@ CFLAGS ?= -std=c99 -O2 -Wall -Wextra -Wpedantic -Werror \
-D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE
LIBDIR ?= vendor/libmcp
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
DOCDIR ?= $(PREFIX)/share/doc/apex-twin
UNITDIR ?= $(PREFIX)/lib/systemd/system
SRC := $(wildcard src/*.c)
OBJ := $(SRC:.c=.o)
@@ -18,8 +21,11 @@ test: apex-twin
./tests/run.sh
install: apex-twin
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp apex-twin $(DESTDIR)$(PREFIX)/bin/
mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(DOCDIR) $(DESTDIR)$(UNITDIR)
install -m 0755 apex-twin $(DESTDIR)$(BINDIR)/apex-twin
install -m 0644 README.md $(DESTDIR)$(DOCDIR)/README.md
install -m 0644 systemd/apex-twin.service $(DESTDIR)$(UNITDIR)/apex-twin.service
install -m 0644 systemd/apex-twin-proxy.service $(DESTDIR)$(UNITDIR)/apex-twin-proxy.service
clean:
rm -f apex-twin $(OBJ)
+22 -7
View File
@@ -18,10 +18,16 @@ separate, explicitly armed switch.
```sh
make # apex-twin, ~239 kB static-ish binary, zero warnings under -Werror
make test # 232 end-to-end checks, no mocks
make install # /usr/local/bin/apex-twin
make test # 239 end-to-end checks, no mocks
make install # binary, README and both systemd units (DESTDIR/PREFIX respected)
```
`make install` puts the binary in `$PREFIX/bin`, the README in
`$PREFIX/share/doc/apex-twin/` and both units in `$PREFIX/lib/systemd/system/`,
so a package can use `DESTDIR=/tmp/pkg make install` without surprises. The
proxy unit is separate: an engagement box may want the MCP server without an
open listener.
Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
`-D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE`.
@@ -246,7 +252,7 @@ plus a note per tool on what people get wrong with it.
apex-twin # MCP over stdin/stdout (one JSON-RPC line each way)
apex-twin --http 8797 # MCP over HTTP on 127.0.0.1:8797, POST /mcp
apex-twin --proxy 8798 # forward proxy on 127.0.0.1:8798 (curl -x)
apex-twin --check # scope, tool count and state dir as JSON, then exit
apex-twin --check # scope, tool count, rewrite rules, webhook state, exit
```
HTTP and the proxy bind **loopback only**. A service that can scan and transmit
@@ -255,6 +261,11 @@ must not appear on a LAN by accident; reach it through a tunnel.
that: loopback ports, a 0700 state dir, `dialout` for the radio, and a capability
bounding set without `CAP_NET_RAW` (connect scans need none).
`--check` answers the operational questions without starting a server:
`rewrite_rules`, `webhook_configured` (a boolean; the URL is never printed) and
the loaded scope, alongside the version and tool count. `capabilities` returns
the same two fields to the model.
## The radio
The Marauder bridge speaks the firmware CLI at 115200 baud, and it refuses to talk
@@ -311,7 +322,7 @@ finding and the next report no longer mentions it.
make test
```
232 checks, real binary, real DNS, real files written; no mocks. The suite was
239 checks, real binary, real DNS, real files written; no mocks. The suite was
seen red on purpose: with the "no scope" branch disabled by `if (0 && ...)`,
three checks fail, because they assert the *reason* and not merely that an error
came back — a gate that falls through to the next deny branch looks identical
@@ -333,7 +344,9 @@ the risk grade fell to low and the missing Secure/HttpOnly issues disappeared.
Disabling the notification severity floor made a low finding post, and "a low
finding stays quiet" went red. Making the rewrite matcher return -1 turned seven
checks red: headers stayed, the block rule did not block, the traffic record lost
the rule name, and the rewrite audit was empty.
the rule name, and the rewrite audit was empty. Hardcoding the new operational
fields to 0/false turned three checks red: the rule count and the webhook state
disappeared from `--check` and `capabilities`.
A port is never assumed: an earlier version of the HTTP test used 18797, which on
this host is an SSH forward to another machine, and a foreign server answered
@@ -341,7 +354,7 @@ this host is an SSH forward to another machine, and a foreign server answered
## Status
0.10.0. Built and run: 45 tools, 232 checks. The loop closes: a probe captures
0.11.0. Built and run: 45 tools, 239 checks. The loop closes: a probe captures
the exchange as a pair, a finding points at it, `finding_update` gives it a
state, an asset records the host it came from, `cors_check`/`cookie_audit`/
`http_options` turn a web answer into a graded lead, `report_markdown` turns
@@ -349,6 +362,8 @@ findings and inventory into one Markdown or CSV file, and
`evidence_read`/`traffic_read` get the proof back. `--proxy` puts the same gate
in front of curl and a browser, with optional rewrite rules that can set or
remove a header or block a path, and `APEX_WEBHOOK` wakes someone when the
severity floor is crossed. Not yet wired into a fleet router.
severity floor is crossed. `make install` ships the binary, this README and both
units; `--check` reports the operational state without starting a server. Not yet
wired into a fleet router.
Licence: AGPL-3.0, same as ARTEX.
+8 -2
View File
@@ -6,7 +6,8 @@
*
* apex-twin MCP over stdin/stdout, one JSON-RPC line each way
* apex-twin --http 8797 Streamable HTTP on 127.0.0.1:8797
* apex-twin --check print the scope, the tool count and the host, exit
* apex-twin --check print scope, tool count, rewrite rules and webhook
* state as JSON, exit
* apex-twin --version print the version
*
* The scope is loaded at start and on every scope_reload call. A scope that
@@ -25,6 +26,7 @@
#include "apex.h"
#include "proxy.h"
#include "rewrite.h"
#include "tools.h"
#define MAX_BODY (8u << 20)
@@ -307,11 +309,15 @@ int main(int argc, char **argv)
if (strcmp(argv[i], "--check") == 0) {
mcp_buf b;
(void)apex_rewrite_load();
mcp_buf_init(&b);
apex_scope_json(&b);
printf("{\"version\":\"%s\",\"tools\":%lu,\"home\":\"%s\","
"\"rewrite_rules\":%d,\"webhook_configured\":%s,"
"\"scope\":%s}\n", APEX_VERSION,
(unsigned long)g_srv.ntools, g_cfg.home, b.p);
(unsigned long)g_srv.ntools, g_cfg.home,
apex_rewrite_count(),
g_cfg.webhook[0] != '\0' ? "true" : "false", b.p);
mcp_buf_free(&b);
return 0;
}
+1 -1
View File
@@ -15,7 +15,7 @@
#include "mcp.h"
#define APEX_VERSION "0.10.0"
#define APEX_VERSION "0.11.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+5 -1
View File
@@ -29,6 +29,7 @@
#include "apex.h"
#include "notify.h"
#include "rewrite.h"
#include "tools.h"
/* --------------------------------------------------------------- helpers */
@@ -931,7 +932,10 @@ static void t_capabilities(mcp_conn *c, const mcp_json *args, void *user)
}
mcp_buf_puts(&b, "},\"scope_loaded\":");
mcp_buf_puts(&b, g_scope.loaded ? "true" : "false");
mcp_buf_puts(&b, "}");
(void)apex_rewrite_load();
mcp_buf_printf(&b, ",\"rewrite_rules\":%d,\"webhook_configured\":%s}",
apex_rewrite_count(),
g_cfg.webhook[0] != '\0' ? "true" : "false");
mcp_reply_json(c, b.p);
mcp_buf_free(&b);
}
+44
View File
@@ -1057,6 +1057,50 @@ with open(fake, "w") as f:
res, _ = run([call(1, "marauder_info")], extra_env={"APEX_SERIAL": fake})
check("a non-tty serial port fails loudly", err(res[0]), text(res[0]))
print("\n== operational visibility ==")
ops_home = tempfile.mkdtemp(prefix="apex-ops-")
write_scope(ops_home, SCOPE)
with open(os.path.join(ops_home, "rewrite.json"), "w") as f:
json.dump({"rules": [
{"match_host": "example.com",
"set": [{"name": "X-A", "value": "1"}]},
{"match_host": "*", "match_path_prefix": "/x", "block": True},
]}, f)
def check_json(extra_env=None):
e = dict(os.environ)
e["APEX_HOME"] = ops_home
if extra_env:
e.update(extra_env)
p = subprocess.run([BIN, "--check"], capture_output=True, text=True,
env=e, timeout=30)
return json.loads(p.stdout), p.stdout
chk, _ = check_json()
check("--check counts the rewrite rules", chk["rewrite_rules"] == 2, chk)
check("--check reports webhook_configured=false",
chk["webhook_configured"] is False, chk)
chk_hook, out_hook = check_json({"APEX_WEBHOOK": "http://127.0.0.1:9/hook"})
check("--check reports the webhook", chk_hook["webhook_configured"] is True,
chk_hook)
check("--check never prints the webhook URL", "127.0.0.1:9" not in out_hook,
out_hook[:200])
res, _ = run([call(1, "capabilities")], home=ops_home,
extra_env={"APEX_WEBHOOK": "http://127.0.0.1:9/hook"})
caps = json.loads(text(res[0]))
check("capabilities reports the operational state",
caps["rewrite_rules"] == 2 and caps["webhook_configured"] is True, caps)
check("capabilities does not leak the webhook URL",
"127.0.0.1:9" not in text(res[0]), text(res[0])[:200])
with open(os.path.join(ops_home, "rewrite.json"), "w") as f:
f.write("{not json")
chk_bad, _ = check_json()
check("--check survives an invalid rewrite file", chk_bad["rewrite_rules"] == 0,
chk_bad)
shutil.rmtree(ops_home, ignore_errors=True)
print("\n== summary ==")
print("%d passed, %d failed" % (passes, len(fails)))
if fails: