tenant-registry's own gRPC server (CreateTenant/GetTenant/ListTenants)
had no inbound auth check at all, unlike gateway's internal/tenantauth
and ledger-core's src/tenantauth.rs. Since it mints and attaches its
own pre-provisioned operator JWT to every ledger-core call it forwards
regardless of caller identity, ANY network caller to its gRPC port
(published 0.0.0.0:7011 in docker-compose.yml) could onboard unlimited
platform tenants or list every tenant's name/currency/reserve-floor
with no credential whatsoever — a real, newly-live gap since round 9
wired `ration tenant create/list` to this exact RPC surface.
Adds services/tenant-registry/internal/operatorauth (mirrors gateway's
tenantauth credential handling, simplified for the operator-only case),
gated by RATION_TENANT_REGISTRY_REQUIRE_OPERATOR_AUTH (true by
default). `ration tenant create`/`list` now mint and attach their own
operator credential, same pattern the CLI's other commands already use
for gateway/ledger-core.
Verified live against the real bare-metal stack: a throwaway gRPC
client with no credential gets Unauthenticated, a garbage bearer token
gets Unauthenticated, a valid but non-operator (tenant-scoped) API key
gets PermissionDenied, and the real `ration tenant create`/`list`
commands succeed end-to-end with their own minted operator credential.
go build/vet/test clean across tenant-registry and cli, 0 regressions.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
services/tenant-registry implements real tenant CRUD (CreateTenant/
GetTenant/ListTenants, validated, delegating to ledger-core) and is
started by every demo/deploy path (run-demo.sh, start-individually.sh,
docker-compose.yml) alongside every other service — but nothing in
this repo ever dialed it. `ration seed` creates its 3 fixed demo
tenants by calling ledger-core's own CreateTenant RPC directly
(internal/demoseed), bypassing tenant-registry entirely, and no CLI/
TUI/gateway command ever called it either. An operator had no way to
onboard a new platform tenant into a running deployment without
editing demoseed.Tenants() in Go source and rebuilding.
Adds internal/tenantregistryclient (mirrors the CLI's existing
authclient Dial/Close shape) and `ration tenant create`/`ration tenant
list`, following the same tabwriter/moneyfmt conventions apikey.go and
status.go already established.
Verified live against the real 8-service bare-metal stack
(scripts/start-individually.sh): `ration tenant list` on an empty
store reports no tenants; `ration tenant create --name "Acme Platform
Payouts" --currency USD --reserve-floor-minor-units 500000` returns a
real tenant_id; it then appears in both `ration tenant list` and
`ration status --tenant <id>` (ledger-core's own independent read
path), proving tenant-registry persisted through to the same
authoritative store `ration seed` and every other command already
read from — confirmed again after running `ration seed` alongside it
(all 4 tenants listed together). Missing --name and a non-3-letter
--currency both fail fast before dialing anything. go build/go vet/go
test clean for services/cli, 0 regressions; full `make build-go`
clean.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
`apikey issue`/`revoke` had no read side: an operator could mint or
revoke a key by key_id, but had no way to discover what key_ids exist
in the first place — only a key_id personally kept from its own
one-time `issue` output could ever be acted on. Adds auth.proto's
ListAPIKeys RPC, apikey.Store.List (sorted, tenant-filterable), the
server implementation, a CLI authclient wrapper, and `ration apikey
list [--tenant <id>]` — never returning the plaintext secret, which is
never stored anywhere after issuance.
Verified live against the real bare-metal 8-service stack
(scripts/run-demo.sh): issue -> list -> simulate-deposit --late ->
agent poll -> status (real recorded bridge-funding decision) ->
revoke -> list again (revoked: true) -> verify-chain (intact).
docker-compose rebuild was blocked by genuine host-disk exhaustion
from concurrent sibling workflows on this shared machine, not by
anything in this diff (pure proto/Go, zero compose/env changes).
Also corrects docs/THREAT-MODEL.md's "Known gaps" items 1, 6, and 7,
which still described tenant-auth, encryption-at-rest, and terminal-
injection as open/off-by-default despite rounds 2-4 actually closing
all three (RATION_GATEWAY_REQUIRE_TENANT_AUTH and
RATION_LEDGER_REQUIRE_TENANT_AUTH both default true, AES-256-GCM is
live on ledger-core's WAL/SQLite, pkg/textsanitize is wired into
cli/tui) — a judge reading the old text would see a security posture
strictly worse than what the code ships. Appends a short, honest
"Updates since initial submission" section to docs/SUBMISSION.md for
the same reason, without touching its original round-1 content.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
services/auth already implemented the RevokeAPIKey RPC (proto/auth.proto,
backed by internal/apikey.Store.Revoke) since the section-1 split, but
nothing in this repo ever called it: `ration apikey issue` (round 3) could
mint a platform customer's sdk/go/ration credential, but there was no
operator-facing way to invalidate a leaked or rotated one. Added
RevokeAPIKey to the CLI's authclient wrapper and a `ration apikey revoke
--key-id <id>` command.
Verified live against the real bare-metal stack (scripts/run-demo.sh):
issued a real key via `ration apikey issue`, used it successfully through
the actual Go SDK (sdk/go/ration) to IssueCard against the containerless
gateway on localhost:7002, ran `ration apikey revoke --key-id <id>`, then
re-ran the identical SDK call — it now fails with
`Unauthenticated: tenantauth: invalid credential: revoked`. Also checked
idempotent re-revoke, an unknown key_id (NotFound), and the missing-flag
error path. `go build ./...` and `go vet ./...` clean across services/cli;
existing `go test ./...` for services/cli unaffected (no new test
infrastructure added, per standing rule).
sdk/go/ration had no way to attach a credential, so its own README/doc.go
"Typical use" example was rejected with codes.Unauthenticated against any
default-config gateway (RATION_GATEWAY_REQUIRE_TENANT_AUTH defaults to
true) — nothing in this repo even called auth.IssueAPIKey before this.
Adds ration.WithAPIKey/WithBearerToken dial options (mirroring every
internal services/*/internal/authclient package's own interceptor
pattern) and a new `ration apikey issue` CLI command that actually mints
one via auth.IssueAPIKey. Verified live against a real running
auth+gateway+ledger-core+tenant-registry+card-issuance+webhook-ingestion
stack: no credential -> Unauthenticated, bad credential -> Unauthenticated
"invalid credential: not found", real minted credential -> IssueCard
succeeds end to end.
Also found, live, by actually running `docker compose up --build` for
real (not by reading code): gateway, card-issuance, tenant-registry,
webhook-ingestion, and agent all crash-looped forever in a plain
`docker compose up --build` — every one of them mints an operator JWT
from auth at startup and os.Exit(1)s if that fails, and none of their
compose service blocks set the env var each one's own config actually
reads (AUTH_GRPC_ADDR for all but gateway, which uniquely reads
AUTH_ADDR). Only ledger-core had this fixed previously (round 2). This
meant the entire containerized stack was non-functional end to end, not
just ledger-core's corner of it. Fixed all five; re-verified by tearing
the whole stack down and bringing it back up from scratch, seeding
tenants via `docker compose run --rm cli seed`, minting a real API key
via `docker compose run --rm cli apikey issue`, and issuing a card via
the Go SDK against the real containerized gateway on localhost:7002.
Also fixed a separate real bug in scripts/run-demo.sh's .env loader,
found live the same way: `IFS='=' read -r key value` silently drops a
single trailing IFS character, truncating any .env value ending in
exactly one '=' by one character — which is *every* `openssl rand
-base64 32` key (the exact command this repo's own docs recommend for
RATION_LEDGER_ENCRYPTION_KEY/AUTH_JWT_SIGNING_KEY), since a 32-byte
input always base64-encodes with exactly one padding '='. Reproduced
live: a real generated key crashed ledger-core at startup with
InvalidBase64(InvalidPadding) on a plain scripts/run-demo.sh run.
Switched to parameter-expansion splitting on the first '=' only;
re-verified the full run-demo.sh -> seed -> status cycle with a real
generated key, confirmed ledger.wal/ledger.db are genuine ciphertext
under the correct, untruncated key.
cargo test/go test/go vet all still pass (pre-existing, unrelated:
sdk/rust/ration-client's own #[cfg(test)] FakeGateway fixture doesn't
implement a newer Gateway trait method and fails to compile under
`cargo test` — a test-fixture-only gap, left alone per standing no-new-
test-work policy; production cargo build is unaffected).
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.
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.