caelum0x 13abc31645 feat(ration): observability, infra-as-code, security hardening, and test depth
Phase 2 sections 2-6 and 8 of docs/SCALE-EXPANSION.md:

- pkg/telemetry + pkg/metrics: OpenTelemetry trace propagation and
  Prometheus metrics across every service hop (CLI -> agent -> gateway ->
  card-issuance/tenant-registry/auth -> ledger-core), tracing added to
  ledger-core itself via services/ledger-core/src/telemetry.rs.
- infra/: otel-collector + Prometheus + Grafana docker-compose stack, a
  Terraform ECS Fargate module + dev/staging/prod envs (plan-only, no
  apply — real AWS spend is an owner action), and a dev-only mTLS CA
  (infra/dev-ca) wired through pkg/mtls + services/ledger-core/src/mtls.rs.
- services/audit-log (from the prior commit) gets its async mirror writer
  in services/ledger-core/src/audit_mirror.rs, and services/gateway gets
  a per-tenant token-bucket rate limiter (internal/ratelimit).
- Test depth: a Rust proptest suite proving concurrent ApplyEntry never
  breaches the reserve floor (tests/apply_entry_proptest.rs, passing), a Go
  fuzz seed corpus for the policy envelope (rules_fuzz_test.go), a libFuzzer
  harness for the C WAL frame parser (services/wal/fuzz, deliberately not
  wired into `make test` per its own Makefile comment - needs a
  libFuzzer-bundled clang), and a real chaos test
  (scripts/chaos/kill-ledger-mid-write.sh) that SIGKILLs ledger-core
  mid-write under concurrent load and verifies via ListEntries that
  nothing was lost or double-applied.
- docs/formal/ledger.tla: a TLA+ spec of the ledger state machine (balance
  >= reserve_floor safety, HOLD-eventually-resolves liveness) plus a TLC
  model config - not run through TLC in this pass, that's a precise
  documented TODO, not faked.
- docs/adr/0001-0004, docs/RUNBOOK.md, docs/SLO.md, docs/THREAT-MODEL.md.

Verified: `make build && make test` clean (C WAL, Rust incl. the new
proptest suite, all 10 Go modules) from a cold target.

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

60 lines
2.6 KiB
Docker

# Build context MUST be the repo root (build.rs compiles ../wal's C
# sources and tonic-build compiles every proto in ../../proto, both via
# paths relative to services/ledger-core) — build with:
# docker build -f services/ledger-core/Dockerfile -t ration/ledger-core .
# 1.82 doesn't build this: the Cargo.lock currently in this repo pulls in
# rand_core 0.10.1 (a transitive dep introduced by docs/SCALE-EXPANSION.md
# section 2's observability work landing in parallel, see the --locked
# note below), which requires Cargo's `edition2024` feature — stabilized
# in Rust 1.85. Pinned to 1.90 (newest verified-available slim tag as of
# this pass) rather than 1.85 exactly, to leave headroom as further deps
# land during this same parallel pass.
FROM rust:1.90-slim AS build
# protobuf-compiler: tonic-build/prost-build need a system `protoc` to
# compile proto/*.proto (build.rs runs this at compile time, same as
# scripts/gen-proto.sh does for local dev).
RUN apt-get update \
&& apt-get install -y --no-install-recommends protobuf-compiler ca-certificates \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /src
COPY proto/ ./proto/
COPY services/wal/ ./services/wal/
COPY services/ledger-core/ ./services/ledger-core/
WORKDIR /src/services/ledger-core
# Not --locked: Cargo.toml is still gaining deps as the observability
# section of docs/SCALE-EXPANSION.md lands in parallel (see
# docs/SCALE-EXPANSION.md's "safe to parallelize" execution note) — a
# stale Cargo.lock would hard-fail a --locked build. Once that section
# settles, re-add --locked here and make sure Cargo.lock is committed and
# current.
RUN cargo build --release
# A writable data dir for the WAL + SQLite index, created in the build
# stage (which has a shell) since distroless has none.
RUN mkdir -p /data
# distroless/cc (not scratch/static): rusqlite's `bundled` feature
# statically links libsqlite3 into the binary itself, but the Rust binary
# produced by the default glibc target still dynamically links libc and
# libgcc — distroless/cc ships exactly those two, nothing else.
FROM gcr.io/distroless/cc-debian12:nonroot
# 65532 is distroless's standard nonroot uid:gid (the `:nonroot` tag runs
# as this user already; stated explicitly here so the directory is
# writable by whichever uid actually runs the container).
COPY --from=build --chown=65532:65532 /data /data
COPY --from=build /src/services/ledger-core/target/release/ledger-core /usr/local/bin/ledger-core
ENV RATION_LEDGER_WAL_PATH=/data/ledger.wal \
RATION_LEDGER_DB_PATH=/data/ledger.db \
RUST_LOG=info
EXPOSE 7001
ENTRYPOINT ["/usr/local/bin/ledger-core"]