CapstoneVol. 19 · Part XIX
0 / 0

Trails / Capstone

CP·211H

The Operations Layer: Observability and Security

TiffinBox made observable and secure to the capstone's lists: OpenTelemetry end to end, logs, metrics and traces that join up, dashboards per journey, SLOs with burn-rate alerts and runbooks, and on the security side OIDC sign-in, role- and object-based access, secrets management, a threat model of the whole system, dependency and supply-chain controls, and a tamper-evident audit log; with a lab on how quickly a canary reveals a bad release and how a hash chain exposes edited or deleted audit entries.

22 topics · ~11 min read · 16-question quiz
Updated Suggest a correction

Start here: knowing and defending

Two questions decide whether TiffinBox can be trusted in production:

  • Do we know what it's doing? When a customer says "my skip didn't save", can you find their request, see every step it took, and tell whether this is one person's problem or everyone's?
  • Can we stop and prove unauthorized behaviour? When someone tries another user's order ID, a stolen session, a malicious document, or an insider refund, is it blocked, and is there a record nobody can quietly erase?

The capstone's observability and security lists answer those questions:

Observability Security
OpenTelemetry everywhere OAuth 2.0 / OIDC sign-in
logs, metrics, traces that join up RBAC plus object-level checks
dashboards per user journey secrets in a manager, rotated
alerts on symptoms, with runbooks a threat model of the whole system
SLOs and error budgets dependency scanning and supply-chain controls
audit logging that resists tampering

Two measurements

How fast does a canary reveal a bad release? The lab simulated TiffinBox at 200 requests per second with a normal error rate of 0.5%, sending a slice of traffic to a new version and testing every minute:

Canary share New version's error rate Caught within 2 h Median time to catch
5% 0.6% (slightly worse) 86% of runs 47 min
5% 1.0% (doubled) 100% 3 min
5% 5.0% (badly broken) 100% 1 min
25% 0.6% 100% 13 min

Obvious breakage is caught almost immediately, but subtle regressions need more traffic or more time, which is why canary analysis runs long enough for the effects you care about, and why SLO burn-rate alerts back it up after full rollout.

Can someone quietly edit the audit log? In a hash-chained log, each entry includes the hash of the one before. Editing an entry (changing "exported 48,210 customers" to 12) or deleting it broke the chain at exactly that entry. Recomputing every hash after a deletion made the chain look intact again, but it no longer matched the latest hash stored elsewhere. Tamper-evidence needs both the chain and an anchor outside the attacker's reach.

How deep to go

Volume 17 defines six mastery levels. For the operations layer:

Level What you can do
L1 Name each observability and security requirement and its purpose
L2 Instrument the system, build dashboards and alerts, configure OIDC and roles
L3 Explain sampling, cardinality, burn rates, token flows, and hash chains from first principles
L4 Diagnose incidents from telemetry; find authorization and supply-chain weaknesses
L5 Design SLOs, alerting, the threat model, access control and audit for the system
L6 Run it: on-call, postmortems, red-team exercises, compliance evidence

Volumes 9 and 10 (chapters 97–113) teach every topic in depth.

Observability

Instrumentation

  • OpenTelemetry in every component: the browser (fetch spans and web vitals), the API and workers (Java agent or Micrometer with OTLP), the tracking gateway, the outbox relay. All export via OTLP to an OpenTelemetry Collector, which batches, samples, redacts and routes to the backends (a metrics store such as Prometheus/Mimir, a trace store such as Tempo or Jaeger, a log store such as Loki or the cloud's).
  • Context propagation across HTTP (traceparent) and Kafka headers, so one trace runs from the click to the notification.
  • Resource attributes on everything: service, version (the image digest's tag), environment, zone, pod.

Logs, metrics, traces that join up

  • Logs carry trace_id and span_id; dashboards link from a slow trace to its logs and back.
  • Metrics for rates and distributions: RED per route (rate, errors, duration as histograms), USE for resources (pool usage and waits, consumer lag, breaker state, outbox age, cache hit rate), and business metrics (skips per minute, orders confirmed at cut-off, assistant abstentions). Keep label cardinality low: route templates, not raw URLs; never user or order IDs.
  • Traces with tail sampling in the Collector: keep 100% of errors and slow requests, and a few percent of the rest.
  • Exemplars link a point on a latency histogram to an example trace.

Dashboards

One dashboard per user journey (subscribe, skip, track, kitchen prep, assistant), each showing the journey's SLIs, its dependencies' health, and recent deploys as annotations; plus one per component for engineers. A dashboard nobody looks at during an incident should be deleted.

SLOs and alerts

SLI SLO (30 days)
order, skip and payment API requests that succeed 99.9%
those requests answered within 300 ms (reads) or 800 ms (writes) 99%
tracking positions shown within 5 s 99% of position updates
assistant answers delivered (not errors or timeouts) 99.5%
events processed within 60 s of publication 99.9%
  • Burn-rate alerts (Volume 18, Phase 9's lab): page when the budget burns fast (14.4× over 1 h and 5 min, or 6× over 6 h and 30 min), open a ticket for slow burns (3× over 1 day and 2 h, or 1× over 3 days and 6 h).
  • Every page has a runbook in docs/runbooks/, linked from the alert: what it means, first checks, mitigations, escalation.
  • Error-budget policy agreed with the product owner: when the budget is spent, reliability work comes before features.
  • Canaries use the same SLIs for automated analysis (this chapter's lab), and synthetic checks run the critical journeys from outside every minute.

Security

Identity: OAuth 2.0 and OIDC

  • Customers, kitchen staff and operators sign in through an external identity provider with OIDC (authorization code + PKCE, via the BFF of chapter 211B).
  • MFA required for kitchen staff and operators; passkeys offered to customers.
  • Short access tokens, refresh tokens held server-side, session revocation on password change or suspicion.
  • Service-to-service calls inside the cluster rely on network policy plus workload identity; calls to external providers use per-environment credentials from the secret manager.

Authorization: roles and objects

Role May
customer manage own subscriptions, orders, payments, assistant conversations
kitchen_staff read and update orders and menus of kitchens they belong to
kitchen_owner the above plus staff membership and documents for their kitchens
support read customers' orders; issue refunds up to a limit
finance larger refunds; reports
admin role management (with approval), configuration

Roles grant actions; object-level checks in queries grant data (chapter 211C). High-risk actions (large refunds, role grants, data exports) require a second person's approval and are always audited.

Secrets

  • In the cloud secret manager, delivered to pods by the External Secrets Operator; never in Git, images, or environment files on laptops.
  • Rotated on a schedule and on any suspicion; database credentials ideally dynamic (short-lived per pod).
  • Secret scanning (gitleaks) in pre-commit and CI; a found secret is rotated, not just deleted.

Threat model

Draw the data-flow diagram (browser, CDN, BFF/API, database, Kafka, workers, object storage, model providers, payment provider, identity provider) and walk STRIDE over each element and flow:

Threat Example in TiffinBox Control
Spoofing stolen session cookie HTTP-only Secure SameSite cookies, short idle timeout, re-auth for sensitive actions
Tampering modified order total from the client server computes prices; signed payment webhooks verified
Repudiation "I never refunded that" audit log with actor, approval and hash chain
Information disclosure another customer's order by ID; personal data in logs object-level checks; redaction; private networking
Denial of service login flood; expensive assistant requests WAF and rate limits; token budgets; load shedding
Elevation of privilege injected document makes the assistant call admin tools tool allow-lists, user-scoped tools, confirmations

Review it at every milestone and whenever a new data flow appears.

Dependency and supply-chain controls

  • Dependency scanning (OWASP Dependency-Check, Trivy, or the platform's) on every build; renovate bots for updates; policy: no known critical vulnerabilities with an available fix in production.
  • Lockfiles and pinned versions (Gradle lockfiles, package-lock.json, base images by digest).
  • SBOMs generated and stored per image; signatures and provenance (SLSA level 2–3 style attestations) checked at admission (chapter 211G).
  • CI hardening: least-privilege tokens, pinned third-party actions by commit hash, protected branches, required reviews.

Audit logging

  • Record who did what to which object, when, from where, and with whose approval for every security-relevant or money-moving action: sign-ins, role changes, refunds, exports, configuration changes, assistant write actions.
  • Write audit events in the same transaction as the action (an audit table or the outbox), so an action can't happen without its record.
  • Make the store append-only (no update/delete grants; a write-once bucket for archives), hash-chain entries, and anchor the latest hash periodically somewhere separately controlled (this chapter's lab).
  • Retain per policy; make audit search available to security staff, and alert on suspicious patterns (many exports, self-granted roles).

Done when

  • A request can be followed from the browser to the database and into workers in one trace, with logs linked.
  • Each journey has a dashboard; each SLO has burn-rate alerts with runbooks that someone else has followed.
  • Canary analysis uses the SLIs; synthetic checks cover the critical journeys.
  • Sign-in uses OIDC with MFA for staff; authorization tests cover roles and objects; high-risk actions need approval.
  • No secrets in code, images or CI; rotation is routine and tested.
  • The threat model is current; scanning, SBOMs, signatures and provenance gate releases.
  • Audit entries are written transactionally, append-only, hash-chained and anchored; tampering is detected in a drill.

Common traps

  • Dashboards without SLOs; alerts without runbooks.
  • High-cardinality labels (user or order IDs) on metrics.
  • RBAC without object checks.
  • Secrets "temporarily" in environment files.
  • Audit logs the database owner can silently rewrite.

Lab: catching a bad canary, and a tamper-evident audit log

Setup. Python on the lab machine. Experiment A is a simulation; Experiment B runs the real hash-chain code.

Experiment A: how quickly does a canary reveal a bad release?

Model: 200 requests per second; the stable version's error rate is 0.5%. A share of traffic goes to the canary, whose error rate is set per scenario. Every minute, the canary's cumulative error rate is compared with 0.5% using a one-sided z-test, and the canary fails when z > 3. 2,000 simulated two-hour runs per scenario; "errors served" is the median number of failed canary requests before detection.

Canary share Canary error rate Detected within 2 h Median time Errors served to canary users by then
1% 0.6% 27% 40 min ~28
1% 1.0% 100% 12 min ~14
1% 5.0% 100% 1 min ~6
5% 0.6% 86% 47 min ~169
5% 1.0% 100% 3 min ~18
5% 5.0% 100% 1 min ~30
25% 0.6% 100% 13 min ~234
25% 1.0% 100% 1 min ~30
25% 5.0% 100% 1 min ~150

A canary identical to stable (5% share, 2 hours) was wrongly failed in 3.4% of runs: testing every minute gives chance many opportunities to cross the threshold.

Experiment B: a hash-chained audit log

Five audit entries (a refund, a role grant, a customer export of 48,210 rows, a role revoke, another refund). Each entry stores hash = SHA-256(previous hash + entry); verification recomputes the chain from the start.

Tampering Verification
none intact
entry 2 edited (rows: 48210 → 12) broken at entry 2
entry 2 deleted broken at entry 2
entry 2 deleted and every later hash recomputed intact, but the last hash doesn't match the copy anchored elsewhere

What it shows

  • Big regressions are caught in a minute; small ones take time and traffic. A 20% relative increase (0.5% → 0.6%) needed a median of 47 minutes at a 5% canary and was missed entirely in 14% of runs. Bigger canaries detect faster but expose more users. Choose the step durations from the smallest regression you need to catch.
  • Repeated checks inflate false alarms. Checking every minute for two hours gave a 3.4% false-failure rate with a strict threshold (z > 3); a looser threshold would fail good releases often. Sequential testing methods, or fewer, longer analysis windows, keep this under control.
  • A hash chain detects edits and deletions, unless the attacker rewrites the whole chain. Only an anchor they can't modify (a periodic checkpoint in another account, a write-once bucket, a transparency log) exposes that. Combine with append-only storage permissions so rewriting isn't easy in the first place.

Try it yourself

  1. Add latency as a second canary metric: the canary is 50 ms slower at p95. How long until a test on latency notices?
  2. Replace the per-minute z-test with a single test after 30 minutes and compare detection time and false alarms.
  3. Store the audit chain in PostgreSQL with REVOKE UPDATE, DELETE from the application role, and anchor the latest hash to a separate bucket every hour.
  4. Add an HMAC with a key held by a separate service, so even a full rewrite needs that key.

Revision sheet: observability and security

Key ideas

  • OpenTelemetry everywhere via a Collector; context through HTTP and Kafka; resource attributes.
  • Logs with trace IDs; RED/USE/business metrics with low cardinality; tail-sampled traces; exemplars.
  • Dashboards per journey; SLOs; burn-rate pages and tickets; runbooks; error-budget policy; canary analysis and synthetic checks on the same SLIs.
  • OIDC with PKCE via a BFF; MFA for staff; roles for actions, object checks for data; approvals for high-risk actions.
  • Secrets in a manager, rotated, scanned for.
  • STRIDE threat model of the data-flow diagram, reviewed per milestone.
  • Scanning, lockfiles, SBOMs, signatures and provenance; hardened CI.
  • Audit logs: transactional, append-only, hash-chained, anchored.

Numbers to remember

  • Lab: 5% canary — doubled error rate caught in ~3 min; +20% relative in ~47 min (86% of runs); false failures 3.4% with per-minute checks.
  • Burn-rate pages: 14.4× (1 h/5 min), 6× (6 h/30 min); tickets 3× (1 d/2 h), 1× (3 d/6 h).

Pitfalls

  • SLO-less dashboards; runbook-less alerts; cardinality explosions; RBAC without object checks; secrets in env files; rewritable audit logs.

Glossary

  • Tail sampling: deciding which traces to keep after seeing them whole.
  • Exemplar: a trace ID attached to a metric sample.
  • Synthetic check: a scripted journey run from outside on a schedule.
  • Provenance: signed metadata on how and from what an artefact was built.
  • Anchor: a copy of the latest audit hash kept outside the log's control.