6 of 7 services that mint a credential from auth (agent, card-issuance,
tenant-registry, webhook-ingestion, cli, tui) called authclient.Dial(addr)
with zero DialOptions, while loading and correctly applying mTLS creds to
every OTHER peer dial in the same binary. gateway was the only caller that
got this right (authMTLS/authDialCreds pattern).
Reproduced live: with AUTH_MTLS_ENABLED=true (generated via
infra/dev-ca/generate-dev-ca.sh, the exact production-hardening path
docs/SCALE-EXPANSION.md section 8 documents), auth's server correctly
requires and verifies a client cert (tls.RequireAndVerifyClientCert) — a
plaintext dial against it doesn't degrade gracefully, it fails the TLS
handshake outright ("error reading server preface: EOF"/connection reset).
Confirmed with the real pre-fix card-issuance binary: it crashes at startup
("mint operator JWT: ... error reading server preface: EOF") the moment
mTLS is actually turned on, for every one of the 6 affected services.
Also found and fixed a second instance of the same root cause while
checking sibling call sites: the CLI's apikey issue/revoke/list and tenant
create/list commands each dial auth directly (bypassing clients.go's
dialClients entirely) and never attached mTLS creds either; tenant
create/list's own tenant-registry dial had the identical gap. Added a
shared dialAuthClient() helper in clients.go so this bug class can't
quietly reappear a 6th time within the same CLI binary.
Verified live end-to-end against the real 8-service bare-metal stack with
mTLS fully enabled (dev-ca-generated certs for every service): auth,
card-issuance, tenant-registry, webhook-ingestion, gateway, and agent all
now mint/verify successfully over mTLS at startup; a full CLI cycle (seed,
status, apikey issue/list/revoke, tenant create/list, card issue,
simulate-deposit --late, agent auto-grant, audit-check, verify-chain) ran
clean end to end. Re-verified the default mTLS-disabled path (every prior
round's own verification baseline) is completely unaffected by re-running
the identical demo cycle with mTLS off.
go build/go vet clean across all 11 go.work members, gofmt clean on every
touched file, go test clean for every affected package (0 regressions).
ration status (the single most-run command in this repo, per round 13's
own framing)'s printTenantHeader printed tenant.Name completely raw, with
no sanitization at all. Same gap, same root cause, across the TUI: the
Tenants tab table, the Activity tab's per-row TenantName, and the card
form's tenant picker + adjust-limit infoLine all rendered a Tenant's own
Name raw too. services/tenant-registry's Create only validates name
non-emptiness, no charset check — round 16 already proved a raw ESC byte
survives into a persisted Tenant record via "tenant create --name".
Rounds 13/16/23 sanitized CardholderName, the CLI's own tenant-create
echo, and the Activity feed's Summary, but never Tenant.Name as read
back through these five separate call sites.
Reproduced live against the real bare-metal 8-service stack
(scripts/start-individually.sh): created a tenant with
--name $'Evil\x1b[31;1mINJECTED\x1b[0m Status Co', then byte-counted real
stdout — `ration status --tenant <id>` carried 2 raw ESC bytes pre-fix,
0 after. Drove the real bin/tui through a tmux pty: Tenants tab and the
card-issue form's tenant picker both rendered the literal bracket text
pre-fix verification showed was otherwise a live ANSI escape (confirmed
via `tmux capture-pane -e` byte inspection, distinguishing it from tmux/
lipgloss's own legitimate styling codes).
Fix: sanitizeControlChars(tenant.Name) in status.go's printTenantHeader;
format.SanitizedCell(t.GetName(), ...) in tui/view/tenants.go;
textsanitize.StripControlChars on ActivityRow.TenantName in
tui/view/activity.go; and on both the tenant picker's display name and
newAdjustLimitForm's tenantName param in tui/model/cardform.go — all via
the same helpers this repo's prior sanitization rounds already
established.
go build/go vet/go test clean for services/cli and services/tui (0
regressions), gofmt clean, full make build-go (10 binaries) clean.
services/gateway/internal/grpcserver/server.go's publish() calls embed
IssueCard's raw CardholderName and AdjustCardLimit's raw Reason
directly into the activity feed's Summary string, with no
sanitization anywhere upstream. Round 13 fixed this exact
vulnerability class for CLI status/card list and the TUI's Cards
tab/adjust-limit modal; round 16 fixed a sibling case on `tenant
create`'s own printout — neither ever looked at the gateway's
StreamActivity Summary field, a separate code path feeding the TUI's
Activity tab.
Reproduced live: issued a card via the real 8-service bare-metal
stack with --cardholder containing a raw ESC byte + ANSI color code,
watched the TUI's Activity tab through a real tmux pty — tmux
capture-pane -e showed a genuine, uninterpreted `^[[31mINJECTED^[[0m`
escape sequence sitting in the pane content, not literal bracket
text. Confirmed the same gap on AdjustCardLimit's --reason.
Fix: strip control characters (pkg/textsanitize.StripControlChars,
same helper decisions.go already uses) on Summary at the render
boundary in services/tui/internal/view/activity.go, covering both
call sites (and any future free-text field embedded in a published
activity Summary) with one change. Re-verified the identical live
repro for both IssueCard and AdjustCardLimit: both now render as
literal bracket text, matching the established lipgloss styling
codes elsewhere in the same pane which still show their real `^[`
prefix.
go build/go vet/go test ./... clean for services/tui (0 regressions),
gofmt -l clean. Full module-by-module build (pkg + every service +
sdk/go/ration) clean.
CardholderName is operator-authored free text (ration card issue
--cardholder, and the TUI's own issue-card form) — the same class of
terminal-escape-injection risk already closed for Trigger/Rationale/
PolicySnapshotJson. card.go's printCard (card issue/get/adjust-limit/
close) already sanitized it, but status.go's printCards (used by both
`ration status` and `ration card list`) printed it raw, and the TUI's
Cards tab table (view/cards.go) and the adjust-limit modal's infoLine
(model/cardform.go) did too. A cardholder name containing an ANSI
escape sequence would inject into `ration status` output — the single
most commonly run command in this whole repo's demo flow — and into
the TUI dashboard a judge/operator is meant to watch live.
Fixed all three raw render sites to go through the same
sanitizeControlChars/format.SanitizedCell/textsanitize.StripControlChars
helpers already used everywhere else free text is displayed.
Verified live against the real bare-metal 8-service stack: issued a
card with a cardholder name containing a real ESC (0x1b) byte +
"[31;1mINJECTED[0m", confirmed `ration status` and `ration card list`
output now contain zero raw ESC bytes (byte-counted, not just visual),
and drove the real TUI through a tmux pty — both the Cards tab table
and the adjust-limit modal's header render the literal bracket text
with no live escape sequence. go build/go vet/go test clean for cli
and tui, gofmt clean, 0 regressions.
PLAN-2026-10-23-DEEP.md's own "Remaining" note for the Cards tab was
still true: no in-TUI IssueCard/AdjustCardLimit form, CLI/API only.
Round 7 closed the CLI half of this gap; this closes the TUI half.
- New modal (services/tui/internal/model/cardform.go,
internal/view/cardform.go): press `n` on the Cards tab to issue a
card (tenant picker defaulting to the selected row's owner,
cardholder/limit/interval/currency fields), `a` to adjust an
existing card's limit (pre-filled from the selected row). Submits
via two new client.Clients methods (IssueCard/AdjustCardLimit) that
call the same gateway RPCs the CLI's `ration card` commands use.
On success the form closes and triggers an immediate refresh; on
failure (validation or a real RPC rejection) it stays open with the
error shown and prior input preserved, so the operator can fix and
retry without re-entering everything.
- Real bug found live, not by reading code: the field-typing handler
only ever appended msg.Runes[0], assuming one KeyMsg per keystroke.
bubbletea's input reader batches consecutive printable bytes read
in one syscall into a single KeyMsg carrying multiple runes — typing
(or pasting) a cardholder name arrived as one such batched message,
so every character after the first was silently dropped. Fixed to
append every rune in the batch; re-verified with multi-character
names/limits typing correctly.
Verified live against the real bare-metal 7-service stack (audit-log,
ledger-core, auth, tenant-registry, card-issuance, webhook-ingestion,
gateway — started individually with inter-service delays, the same
round-6/7-documented workaround for this shared box's sibling-agent
load), driven through a real pty via tmux send-keys (not code reading):
seeded 3 tenants, opened the issue-card form, picked a tenant, typed
cardholder "Jane Operator", limit 250000, interval daily, submitted —
card appeared in the Cards tab and in `ration status`'s independent
CLI output (card_7816bf..., ACTIVE, $2,500.00, daily). Opened
adjust-limit on that card, backspaced/retyped the limit to 500000,
submitted — `ration status` confirmed $5,000.00 and the correct new
Held balance. Checked both error paths live: empty cardholder is
rejected client-side before any RPC; a limit request exceeding the
tenant's real reserve-floor headroom returns the actual
card-issuance rejection into the still-open form. `go build`/`go vet`/
`go test ./...` clean for services/tui; full `make build` (Rust+Go+SDK)
clean.
Also added scripts/start-individually.sh, a reusable version of the
manual individual-service-startup workaround rounds 6/7's build logs
already documented ad hoc for this box's contention — same PID-file
format as run-demo.sh, so scripts/stop-demo.sh tears it down too
(verified: it did).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
docs/THREAT-MODEL.md states plainly: "The TUI does not currently
display rationale/agent decisions at all — only tenants, deposits,
cards, and the live activity stream." Add a 5th tab (new
view/decisions.go, wired into model.go/state.go's tab state) that
fetches every tenant's ListAgentDecisions each refresh, sorted newest
first across tenants, and renders WHEN/TENANT/TRIGGER/ACTION/
RATIONALE/POLICY SNAPSHOT.
Extract the CLI's existing sanitizeControlChars into pkg/textsanitize
and apply it (via the new format.SanitizedCell, sanitize-then-truncate)
to every LLM-authored field this new tab renders, closing the same
terminal-escape-sequence injection gap for this surface at the same
time it's built, not after.
docs/THREAT-MODEL.md names this "the biggest one" sub-gap of item 1:
cli/tui/agent (and gateway's own forwarding, card-issuance,
webhook-ingestion, tenant-registry) all dial ledger-core directly,
bypassing gateway's internal/tenantauth entirely, so any operator or
compromised caller could act as any tenant_id against the system's
actual source of truth regardless of what gateway enforces upstream.
Add services/ledger-core/src/tenantauth.rs (authorize_tenant /
authorize_operator, checking x-api-key / authorization: Bearer headers
against a new src/authclient.rs that dials Auth's VerifyAPIKey/
VerifyJWT directly) and call it from every LedgerCore RPC handler.
RATION_LEDGER_REQUIRE_TENANT_AUTH defaults to true; ledger-core refuses
to start with it on but no AUTH_GRPC_ADDR configured.
Every direct ledger-core caller now mints and presents its own
operator-scoped credential: cli/tui/agent (reusing their existing
gateway credential), and new internal/authclient packages for gateway,
card-issuance, webhook-ingestion and tenant-registry.
Verified end-to-end against the live demo stack (seed, simulate-deposit,
status, and the agent's poll/bridge-funding loop all succeed with the
new enforcement on; zero Unauthenticated/PermissionDenied anywhere in
any service's logs).
Close THREAT-MODEL.md's top-named gap end-to-end: services/cli,
services/tui and services/agent each mint an operator-scoped
credential (new internal/authclient in all three, mirroring gateway's
existing authclient) at startup and attach it as x-api-key/
authorization metadata on every gateway call, so
RATION_GATEWAY_REQUIRE_TENANT_AUTH now defaults to true instead of
false.
Also close the two named sub-gaps this left open:
- GetCard/AdjustCardLimit carry only card_id, not tenant_id, so
tenantauth and ratelimit previously passed them through unscoped.
Add internal/gateway/cardtenant, a cached card_id -> tenant_id
resolver backed by card-issuance, and use it in both interceptors.
- StreamActivity accepted an empty tenant_id (meaning "all tenants")
from any caller, authenticated or not. Add
tenantauth.StreamServerInterceptor: a non-operator credential may
only subscribe to its own tenant_id; only an operator credential may
request the all-tenants view.
Phase 2 service decomposition per docs/SCALE-EXPANSION.md section 1: extracts
internal/{airwallex,bridge,card,tenant,httpserver} out of the monolithic
gateway into four independently deployable gRPC services (each own go.mod,
Dockerfile, and tests), with gateway now a thin BFF that fans out through new
cardissuanceclient/webhookeventsclient gRPC clients. gateway.proto's external
surface is unchanged — agent/tui/cli still talk to gateway exactly as before.
Verified: all 10 go.work modules build and `go test ./...` passes across
every one, including the new gateway client packages against the live split
services (via `make build && make test`).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Six services, independently built then integrated:
- services/wal (C): crash-safe write-ahead log, CRC32-checksummed
frames, torn-write recovery via truncate-to-last-valid-frame.
- services/ledger-core (Rust): double-entry ledger over the C WAL via
FFI, reserve-floor enforcement BEFORE any WAL write, idempotent
ApplyEntry, full LedgerCore gRPC service.
- services/gateway (Go): Airwallex Issuing/Global-Accounts client
(mock mode default, live mode ready), the actual rationing math
(reserve floor, 60% bridge cap, 24h velocity cap, partial-over-decline).
- services/agent (Go): deterministic hard-rule policy envelope computed
BEFORE any LLM call; Claude only decides within that pre-approved
envelope; every decision audit-logged even when the LLM call fails.
- services/tui (Go, Bubble Tea) + services/cli (Go, cobra): the only
UI — no web frontend, per explicit direction.
Integration found and fixed three real bugs, not just compile errors:
- proto regen collision shadowing checked-in pkg/pb packages
- ledger-core/gateway address-variable mismatch (stack would never
actually connect on default config)
- the big one: MarkDepositReceived never credited the ledger, so every
tenant's balance was permanently stuck at 0 and bridge-funding could
only ever decline — the core agentic-rationing feature could never
produce a real grant. Fixed at the ledger level with idempotent
mark-and-credit in one WAL frame, covered by 3 new tests.
End-to-end verified live, reproducibly: seed -> simulate a late deposit
-> agent grants a partial bridge with a computed rationale -> second
grant correctly declines once the 24h velocity cap engages. Verified
independently by the orchestrator too: 'make build' and 'make test'
both clean (Rust: 29 tests; Go: all packages; C: WAL test suite).
Airwallex sandbox credentials still pending organizer approval —
tracked as an owner blocker in docs/AIRWALLEX-SETUP.md, not a code gap.