6 Commits

Author SHA1 Message Date
6f5cff1b57 fix(gateway): REST facade's JSON body decode had no size cap — a single unauthenticated request could balloon memory by the full body size
decodeJSONBody (IssueCard, AdjustCardLimit, RationBridgeFunding,
SimulateDeposit) read r.Body with a bare json.NewDecoder and no bound,
before any auth check ever ran. Reproduced live: one unauthenticated
300MB POST to /v1/cards drove gateway's RSS from ~20MB to ~1.3GB in
~5.6s. Capped at 1MB via http.MaxBytesReader (same limit and
justification services/webhook-ingestion's handler already uses for
the identical class of payload), mapped to a 413 instead of the
existing 400. Verified live post-fix: the same 300MB body now returns
413 in ~2.5ms with RSS flat at ~25MB; real IssueCard/AdjustCardLimit/
SimulateDeposit/RationBridgeFunding round-trips through the REST
facade with a real minted API key still succeed unchanged. go build/
go vet/go test clean for services/gateway, full make build (Rust+Go+
SDK) clean, 0 regressions.
2026-10-29 16:22:51 +03:00
31be78e465 fix(gateway): REST facade's unscoped routes shared one rate-limit bucket across every caller
GetDashboardSnapshot and StreamActivity (empty tenant_id, the documented
"all tenants" mode) carry no tenant_id/card_id, so internal/ratelimit's
gRPC-layer interceptor falls back to peer-address keying. But the REST
facade reaches gateway's own gRPC server over one single, long-lived
self-dial connection (cmd/gateway/main.go's selfConn) — so every REST
caller of GET /v1/dashboard/snapshot, GET /v1/dashboard/activity/stream,
and GET /v1/activity (no tenant_id) collapsed into ONE shared token
bucket, the opposite of "one noisy caller can't starve every other
caller" that package promises. Most exposed on the dashboard: a public,
zero-login, judge-facing page explicitly designed for multiple
simultaneous viewers.

Add a second, HTTP-layer limiter keyed by the real client's remote
address, applied only to those three call sites — every tenant/card-
scoped route keeps its existing, already-correct gRPC-level protection
untouched.

Verified live against the real bare-metal stack: a concurrent burst of
40 connections to /v1/dashboard/activity/stream now correctly splits
30 (burst) succeed / 10 rejected with 429, keyed per real client IP;
confirmed tenant-scoped /v1/activity calls are unaffected (10/10 200s).
go build/vet/test clean for services/gateway, 0 regressions.
2026-10-29 15:35:47 +03:00
cda90fcef4 feat(gateway): add a judge-facing live web dashboard
STRATEGY-2026-10-23.md names the exact risk this closes: "Ration's
actual differentiators... are invisible in a UI-less terminal demo
unless explicitly called out on screen." A judge can now open a
shareable gateway URL instead of running the TUI locally.

Add gateway.proto's GetDashboardSnapshot RPC (aggregates ListTenants +
per-tenant GetBalance/CheckReserveFloor + ListAgentDecisions into one
round trip — the same ledger-core data services/tui already fetches
per-tenant, just server-side aggregated for a browser) and three new
httpapi routes: GET /v1/dashboard (a single self-contained HTML/CSS/JS
page, zero external dependencies so it renders on a network-isolated
judging box), GET /v1/dashboard/snapshot (polled every 3s for
per-tenant reserve-floor headroom gauges and recent agent-decision
rationale), and GET /v1/dashboard/activity/stream (a true
text/event-stream SSE framing of StreamActivity for the page's
EventSource, separate from the existing NDJSON /v1/activity).

The dashboard is deliberately credential-free (GetDashboardSnapshot
carries no tenant_id/card_id, which internal/tenantauth's own
documented behavior already passes through unscoped); its activity SSE
stream presents gateway's own operator-scoped credential
(Handler.SetDashboardOperatorToken) specifically because
internal/tenantauth's StreamServerInterceptor requires some credential
on every streaming call — scoped narrowly to this one new route so the
existing, still-credentialed /v1/activity route's security posture is
unchanged.

Verified live: snapshot JSON returns correct per-tenant
available/held/headroom; the SSE stream delivers a real simulated-
deposit event end-to-end with zero auth errors; the page itself serves
at 200 text/html.
2026-10-23 19:38:22 +03:00
ed0dbe14b5 feat(gateway,cli,tui,agent): enforce tenant-scoped auth by default
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.
2026-10-23 18:09:11 +03:00
ecb3242edc fix(card-issuance): surface unknown card IDs as gRPC NotFound, not Unknown
cardsvc.Service.GetCard/AdjustCardLimit wrapped a missing card as a plain
fmt.Errorf(..., airwallex.ErrNotFound), which the gRPC runtime downgrades
to codes.Unknown by default — the gateway's REST facade (services/gateway/
internal/httpapi/cards.go) documented this exact gap as its own TODO: an
unknown card_id surfaced as HTTP 500 instead of 404 for every
GatewayClient caller (TUI, CLI, both SDKs, the REST facade).
grpcserver.Server now wraps cardsvc's not-found error in
status.Error(codes.NotFound, ...) before it leaves card-issuance, so the
existing NotFound->404 mapping downstream works as originally intended.
RED->GREEN with new grpcserver tests; cleared the now-resolved TODOs in
cards.go and updated docs/THREAT-MODEL.md's "Known gaps" list, which
still read webhook rate-limiting/replay-window as open after an earlier
commit had already fixed both. Full go/rust suite green.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-21 16:18:38 +03:00
521d6176c4 feat(ration): REST/JSON facade over gateway, final phase-2 doc updates
Phase 2 section 7 (the other half, alongside sdk/go/ration and
sdk/rust/ration-client already pushed in c5297e4/8215fb8): a hand-rolled
internal/httpapi on services/gateway translating JSON <-> the gRPC source
of truth (cards, deposits, bridge funding, activity), documented as a
convenience facade over gRPC, not a parallel implementation. Also folds in
the remaining phase-2 doc updates (ARCHITECTURE/RUNBOOK/THREAT-MODEL/
AIRWALLEX-SETUP/SUBMISSION, ADR 0003/0004) and docker-compose/Makefile/
.env.example wiring from the resumed phase-2 workflow's final agents.

Verified: go build/vet/test clean across all 10 services + both new SDKs,
`make build && make test` clean end to end (C WAL, Rust ledger-core + the
new Rust SDK, every Go module including sdk/go/ration).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-19 12:56:58 +03:00