Executive Talents · API Gateway — Wire Contract

Rendered from this repo's docs/gateway/CONTRACT.md.

API Gateway Contract (contract_version 3)

This is the authoritative wire contract between the edge (cmd/gateway) and the control plane (cmd/controlplane), and between the control plane and any application that registers with it. Both binaries live in this repo; this document exists anyway because they are still two independently deployable processes that must agree on wire shape without sharing Go types across a process boundary (they share Go types only where genuinely safe to — internal/verify.Claims/JWK/JWKS, used by both the edge's Verify and the control plane's Sign).

0. History

1. Actors and authentication

Actor Authenticates via Verified by
A registered application (machine client) POST /oauth/token → EdDSA JWT The edge, entirely offline, against the JWKS in its config snapshot
Browser / console session traffic Whatever the destination application's own session mechanism is The destination application itself — the edge does not authenticate passthrough traffic
The edge, pulling config/pushing usage Static bearer GATEWAY_INTERNAL_TOKEN The control plane
Admin tooling / developers, registering/granting/minting Static bearer CONTROLPLANE_ADMIN_TOKEN, or a per-developer/console token minted via controlplane token create (§13) The control plane

The control plane has no user/session system of its own by design — admin tooling is trusted to report who is acting via each mutating request's optional actor field, recorded as a free-text label (created_by/ granted_by), not a foreign key to any user table.

2. Application manifest

Every application that wants to plug into the gateway exposes:

GET /.well-known/gateway-manifest
{
  "appId": "hr-service",
  "name": "HR Service",
  "description": "Employee management system",
  "version": "1.0.0",
  "baseUrl": "https://hr.internal",
  "health": "https://hr.internal/.well-known/health",
  "documentation": "https://hr.internal/.well-known/openapi.json",
  "owner": "HR Team",
  "contact": "hr@company.com",
  "scopes": [
    { "key": "employee.read", "description": "Read employee records" }
  ],
  "routes": [
    { "path": "/employees", "method": "GET", "scope": "employee.read" },
    { "path": "/status" }
  ],
  "allowedOrigins": ["https://console.etdevops.io"]
}

The control plane never invents a scope, route, or allowed origin: everything it stores about an application comes from what that application declared here.

3. Registration, grants, credentials

4. Token issuance

POST /oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials&client_id=...&client_secret=...

Returns {"access_token": "...", "token_type": "Bearer", "expires_in": 900}. The JWT's scopes claim is exactly the set of <providerSlug>:<scopeKey> strings the consumer application currently holds via gateway_scope_grants — computed fresh at issuance, not cached.

Optional narrowing (RFC 6749 §3.3, added 2026-10-08). Add scope=<providerSlug>:<scopeKey> [...] (space-separated) to mint a token that carries only those scopes — least privilege per call, for a caller that holds a broad grant but runs a job that only needs to read. Every requested scope must be currently granted, otherwise the request fails with 400 CP1002 (invalid_scope) rather than silently issuing less. A narrowed response also echoes "scope": "<the scopes issued>". Omitting scope keeps the behaviour above (every granted scope), so existing callers are unaffected. sub is app:<applicationId>, iss/aud are etg-gateway-control/etg-gateway — opaque internal claim identifiers, not a reference to any specific business application.

GET /.well-known/jwks.json — public, unauthenticated, includes active and retiring signing keys (retiring keys stay published so tokens they already signed keep verifying until they expire).

5. Config snapshot (edge ⇄ control plane)

GET /api/v1/gateway/internal/config
Authorization: Bearer <GATEWAY_INTERNAL_TOKEN>
If-None-Match: <previous config_etag>

304 Not Modified on an unchanged etag; otherwise 200 with:

{
  "contract_version": 3,
  "generated_at": "2026-07-28T00:00:00Z",
  "config_etag": "<sha256 hex>",
  "default_route_class": "passthrough",
  "routes": [
    {
      "prefix": "/hr-service/employees",
      "class": "blocked",
      "required_scope": "",
      "service": "hr-service",
      "upstream_url": "https://hr.internal",
      "strip_prefix": "/hr-service",
      "allowed_origins": ["https://console.etdevops.io"],
      "app_id": "0b6f3c3e-7d2a-4f1e-9c55-2b8a4e1d9f10",
      "header_secret_epoch": 1,
      "methods": {
        "GET": { "class": "machine", "required_scope": "hr-service:employee.read" }
      }
    }
  ],
  "rate_limits": { "per_client_rpm": 600, "per_tenant_rpm": 1200, "passthrough_ip_rpm": 1200 },
  "jwks": { "keys": [ { "kty": "OKP", "crv": "Ed25519", "kid": "...", "x": "...", "use": "sig", "alg": "EdDSA" } ] }
}

5.1. Namespacing (ADR-GW-2)

Every route is published under /<owner-slug><raw-path> — e.g. hr-service's manifest declares /employees; the public path is /hr-service/employees — regardless of class. The edge strips strip_prefix (/hr-service) from the request path before forwarding, since the application itself only knows /employees.

This is what lets two different applications each declare /employees without colliding: they land at different public paths by construction, whether either one is machine-class or not. Before ADR-GW-2 (v2, §0), only machine-touched routes were namespaced this way — a pure passthrough/blocked route (typically one application's entire browser-facing surface) stayed at its raw, unnamespaced path, uniqueness enforced across applications at registration time. That meant two applications could never both register if they shared any overlapping raw passthrough surface — the common case for a monolith mid-split, where a newly-split-out service still carries most of the original app's routes. Universal namespacing removes that ceiling entirely: raw-path collision across applications is now structurally impossible, so there's nothing left to reject at registration time.

The cost: a caller that used to reach an application directly at its own raw path (e.g. https://api.appa.com/api/customers) now reaches it at https://<gateway-host>/appa/api/customers once that application is registered and the caller's base URL is repointed at the gateway — the path itself is unchanged, but every caller (human session or machine) now goes through the same namespaced URL, no raw alias. See APP_INTEGRATION_GUIDE.md's ADR-GW-2 section for what this means in practice for a frontend that used to call its backend directly.

5.2. Per-request auth dispatch (ADR-GW-2, extended by ADR-GW-3)

Because every route lives at one URL for every kind of caller now, the class declared in the manifest no longer picks which URL a request has to hit to be treated as machine vs. passthrough — it's decided per request, by whether the presented credential actually verifies. ADR-GW-3 removes the one place that per-request dispatch didn't yet reach: previously, a route with required_scope empty (class: "passthrough") never even attempted verification, so a genuine machine caller hitting a route nobody had declared a specific scope for was silently treated as anonymous. That's gone — verification is attempted on every non-blocked route now, regardless of required_scope:

One consequence worth naming explicitly (carried over from ADR-GW-2, still true under ADR-GW-3): a route with required_scope set can express "must be authorized to reach this on a machine's behalf" but never "must ONLY ever be reached by a machine, reject an ordinary unauthenticated request outright" — there is no edge-level way to say that for any route class. A route that declares required_scope is always machine-preferred-with-passthrough- fallback, never machine-only; a route with required_scope empty is always machine-accepted-with-passthrough-fallback, never machine-required. An application that genuinely needs "reject unless X-Gateway-Client-Id is present" enforcement for a specific route has to do that check itself, downstream — the same "compose, don't replace" pattern every application already needs for a route that serves both a human session and a machine caller (APP_INTEGRATION_GUIDE.md).

CORS note (ADR-GW-3): Access-Control-Allow-Credentials eligibility now follows the actual per-request outcome, not the route's static class — a required_scope-declared route that falls back to passthrough for a given request (no verifying bearer presented) is genuinely being served as passthrough for that request, and gets the same declared-origin credential grant a passthrough-classed route would. Previously this was gated on the static class alone, so a real browser session hitting a scoped route never got credentialed CORS treatment even though it was, in fact, being served as passthrough underneath.

Observability note: because a failed machine-auth attempt now falls through to passthrough rather than being rejected, it's logged as an ordinary passthrough request (§6) with whatever status the destination app happened to return — not as a distinct machine-auth-failure event the way v2's GW1001/GW1002 responses were. GW1001 and GW1002 are retired as of v3: the edge no longer emits either (§8).

5.3. Why (ADR-GW-2)

v2's design assumed passthrough was rare and narrow — "one application's whole browser-facing surface, typically a catch-all /." In practice, an application mid-split from a shared monolith (the common real case, not a hypothetical) carries most of its sibling's routes for a long transitional period, and every one of those overlapping routes is genuinely passthrough (each app's own frontend calls its own copy directly) until the split finishes. Under v2, the second such application could never register at all — not "some of its routes conflict," all registration failed outright the moment its manifest declared one path collision (CP1004), since POST /applications validates the whole manifest transactionally. The only v2-compatible fixes were: don't register the second app at all (defeats the purpose), or mark the shared routes machine-class to dodge the raw-path collision (actively wrong — see api-gateway.md rule 2: machine-class is for another application calling on its own behalf, and marking a frontend's own session traffic machine-class gets it rejected at the edge with GW1002 instead, the single most common integration bug this contract warns about). Universal namespacing (§5.1) removes the underlying constraint that forced that choice; dynamic per-request dispatch (§5.2) is what makes namespacing-everything actually workable without regressing the "human vs. machine" auth story a static per-route class used to provide.

6. Usage ingest

POST /api/v1/gateway/internal/usage
Authorization: Bearer <GATEWAY_INTERNAL_TOKEN>
{"events": [{"request_id": "...", "client_id": null, "tenant_id": null,
             "route_prefix": "/employees", "method": "GET", "status": 200,
             "duration_ms": 12, "route_class": "machine", "service": "hr-service"}]}

202 Accepted. Idempotent on request_id (ON CONFLICT DO NOTHING) — the edge's usage sink is fire-and-forget, at-least-once delivery; this is aggregate metering, not a billing-of-record system.

route_prefix is the request path with any secret path segment redacted (everything after a configured marker such as /integrations/payslips/download becomes [REDACTED]; README "Secret path segments"). The edge redacts before sending; the control plane redacts again before storing, so an older edge cannot write a secret into gateway_usage_log.

service is the owning application's slug (Route.Service, §5) — empty/ absent when no route matched at all (a true GW1006). Optional on the wire so an edge binary predating this field still ingests cleanly. Unlike client_id (only ever known for machine-class, caller-authenticated requests), service is set for every route class the edge actually matched, including passthrough — it's what makes §14's per-app request log group passthrough (human/browser) traffic by app too, not just machine calls.

7. Forwarded headers (edge → upstream)

The edge strips any inbound X-Gateway-* header — X-Gateway-App-Auth and X-Gateway-Auth included — before setting its own (clients cannot forge trusted identity, and a value a client sends is never passed on), then stamps:

Which secret header an upstream sees depends on the rollout step (design docs/design/xl1-per-app-gateway-secret.md §5.3; README.md "Gateway header secrets" has the step list):

Header Today, and after P1 (gateway release with GATEWAY_HEADER_MASTER_KEY unset) After P2 (master key set on edge and control plane) After P7 (legacy unset on the edge)
X-Gateway-App-Auth never verified machine requests only verified machine requests only
X-Gateway-Auth every forwarded request, both classes every forwarded request, both classes never

Status 2026-10-06: the XL1 gateway code (W1–W3, PRs #38/#39) is not merged to development, so every environment is in the "Today" column.

Client address (G3, 2026-10-26). Every forwarded request, both classes, carries exactly one X-Real-IP: the client address the edge resolved (§10), full address for IPv6 too. Any X-Real-IP the client sent is dropped first, so an application behind the gateway can use this value as far as it trusts the gateway itself. Underscore spellings (X_Real_IP, X_Forwarded_For, X_Gateway_*), which CGI/WSGI-style servers map to the same variable as the real header, are dropped too, and an inbound Connection header may not name X-Real-IP, X-Forwarded-For or any X-Gateway-* header (the reverse proxy removes every header Connection lists after the edge has set its own, so those tokens are removed first; other tokens are kept). X-Forwarded-For is left to the standard reverse-proxy behaviour: the chain the edge received (written by nginx, possibly prefixed by the client) with the edge's own TCP peer appended. Its left-hand entries are client-controlled; an application must not key anything on them.

Host header (2026-10-07). By default the edge forwards the Host it received (e.g. api.gateway.etdevops.io) unchanged, on both classes; applications on the shared Docker network ignore it, and some route by it (AnooreHR's partner portals). An application on shared web hosting picks the site by Host and rejects the gateway's name. For such an application an operator sets PUT /applications/{id}/upstream-host {"upstreamHost": "base_url", "actor": "..."}: the edge then sends the host of the application's own baseUrl and passes the received one on as X-Forwarded-Host. The setting travels per route in the config snapshot (rewrite_host), so the edge applies it on its next poll. It is never taken from the manifest. First used for talentsapartments (https://v3.talentsapartments.com), whose every request was reset by its host.

For a request that falls through to passthrough — whether because the route is passthrough-class, or because it's machine-class but the presented credential didn't verify (§5.2) — the client's own Authorization header is forwarded unchanged, and no X-Gateway-Client-Id/X-Gateway-Scopes/ X-Gateway-App-Auth are set. The destination application remains its own authenticator for that request.

The correct application-side check, composing with (not replacing) your own session auth:

  1. If X-Gateway-Client-Id is absent, run your normal session/Bearer check, unmodified. Never require or inspect a secret header on that path.
  2. If it's present, accept the gateway identity only when
    • X-Gateway-App-Auth equals one of the application's own accepted per-application secrets (GATEWAY_APP_HEADER_SECRETS, one to three values), compared in constant time against every configured value with no early exit, or
    • only during the overlap, while the application still has the legacy value configured (until its own step P6): X-Gateway-Auth equals GATEWAY_SHARED_HEADER_SECRET, compared in constant time.
  3. Anything else is a reject (401, in the application's own error shape) — never a fall-through to session auth, never "trust the headers anyway". With neither value configured, every machine claim is rejected (fail closed).

The secret check is what stops a direct caller that bypasses the gateway from forging X-Gateway-Client-Id/X-Gateway-Scopes. With per-application secrets, a leaked value lets someone forge identity to that one application only. During the overlap the legacy value is still accepted, so the gateway-wide exposure ends only when every provider application is strict (P6) and the edge stops sending it (P7). Accepting more than one value is the temporary relaxation of the "present but mismatched is always a reject" wording that the overlap needs (design §4, §8 Q4): a request is rejected unless at least one accepted credential matches. Logging, configuration and per-language code: APP_INTEGRATION_GUIDE.md §3.

8. Error envelope

{"error": {"code": "GW1003", "message": "...", "request_id": "..."}}
Code Status Meaning
GW1000 503 / 502 No config loaded, edge busy (503 with Retry-After: 1), or invalid/unreachable/timed-out upstream for a matched route (502)
GW1001 401 Retired as of v3 (ADR-GW-2) — a missing/malformed/expired bearer token on a machine-class route no longer rejects; it falls through to passthrough (§5.2). Reserved, never emitted by the edge.
GW1002 401 Retired as of v3 (ADR-GW-2) — same fallback as GW1001 for an unknown kid/signature failure. Reserved, never emitted by the edge.
GW1003 403 Valid, verified machine token, insufficient scope — still a hard reject, unchanged from v2
GW1004 403 Route explicitly blocked
GW1005 429 Rate limit exceeded (Retry-After set)
GW1006 404 No application registered a route for this path
GW1007 429 Rate limiter at capacity: the per-IP limiter is tracking as many callers as it may and could not add this new one (Retry-After: 10). Not this caller's own budget; see §10

Upstream wait. The edge waits up to GATEWAY_UPSTREAM_RESPONSE_TIMEOUT_SECONDS (default 35 s, gateway-wide, 1 to 300) for a provider application's response headers. A provider that has not started answering by then gets 502 GW1000; the provider may still finish the work, so a caller that retries must reuse its idempotency key. A provider route whose own server budget is longer than this needs the setting raised, not a per-route override (there is none). The whole exchange, upstream wait plus response write, is bounded by GATEWAY_WRITE_TIMEOUT_SECONDS (default 120 s, at least the upstream wait

Busy edge. At most GATEWAY_MAX_INFLIGHT_UPSTREAM requests (default 512) are proxied at once, and at most GATEWAY_MAX_INFLIGHT_PER_SERVICE (default 128) to any one provider application. Over either, the edge answers 503 GW1000 with Retry-After: 1 immediately and does not forward the request, so the provider never saw it and a retry after the delay is always safe.

The control plane uses its own CP1xxx codes for its admin/public API (internal/controlplane/api.go) — a separate namespace, since it's a different HTTP surface with different failure modes (validation, conflict, not-found) than the edge's hot-path codes above.

9. Lifeline floor (edge-side, independent of served config)

Two paths are always forced to passthrough, regardless of what the config snapshot says, so an operator can never be locked out of fixing a bad routing rule by that same rule:

This is deliberately narrow and lives only in internal/gwconfig/config.go — it does not depend on the control plane refusing to create a bad rule (a migration, a restore, or a future control-plane bug bypasses that guard entirely; see the 2026-07-25 incident documented in that file). A third prefix, /api/v1/platform/gateway (the admin API), was part of this floor under v1 — it's gone under v2 because that API no longer flows through the edge's route table at all; it's reached directly, on its own address, and so can no longer be locked out by anything in this table.

10. Rate limiting

In-memory, single-instance (internal/ratelimit), token bucket per client:<id> (machine) or ip:<addr> (passthrough). ratelimit.Limiter is the seam for a shared (e.g. Redis) implementation if the edge is ever horizontally scaled — not built yet because it isn't, today.

Machine callers are limited by client_id only (per_client_rpm), never by IP: two applications behind one shared egress address (every app on the shared box) each get their own bucket, and a client that rotates source addresses stays in its one bucket. They use their own limiter, separate from the per-IP one and with no key cap (its keys are registered client_ids, so the credential registry bounds it): a flood of passthrough IPs can never fill a cap that locks a machine client out.

Client address (ip:<addr>, and the control plane's own per-IP admin limit) comes from one resolver, internal/clientip, in both binaries:

  1. If the TCP peer (RemoteAddr) is not a trusted proxy, the peer is the address. X-Real-IP and X-Forwarded-For are ignored entirely, so a direct caller cannot choose its own bucket.
  2. If the peer is a trusted proxy and X-Forwarded-For is present: the right-most entry that is not itself a trusted proxy (entries further left were written by the client and are never used). If there is none, or a malformed entry stops the walk, the peer. X-Real-IP is not consulted.
  3. If the peer is trusted and there is no X-Forwarded-For: X-Real-IP, when it is exactly one header line holding exactly one valid IP; otherwise the peer.

The limiter key is that address for IPv4 and its /64 for IPv6 (one subscriber is routinely given a whole /64). Logs and the upstream X-Real-IP (§7) carry the full address.

The per-IP limiter tracks at most GATEWAY_RL_MAX_BUCKETS keys on the edge (CONTROLPLANE_RL_MAX_BUCKETS for the control plane's admin limiter): an integer from 1 to 1000000, default 100000 (about 15 MB); anything else makes the binary refuse to start, so the memory guard cannot be switched off by configuration. When the map is full it first drops buckets that have fully refilled (at most once every 10 s; such a bucket holds no budget state, but its key must then win a slot again like any new key). If it is still full, a request for a new key gets 429 with Retry-After: 10 and code GW1007 (edge) or CP1007 (control plane), distinct from an ordinary GW1005/CP1006; keys already tracked carry on. That is fail-safe: a flood of fresh keys cannot grow memory until the container is killed. In the request log a cap denial is a 429 row like any other (the log has no reason column); the response code and a WARN ratelimit: bucket cap ... line, logged at most once a minute with the count of denials since the last one, tell them apart.

Trusted proxies come from GATEWAY_TRUSTED_PROXIES (CIDRs or bare IPs, comma-separated; set on both binaries). Unset means loopback only (127.0.0.0/8, ::1). A set value replaces that default. The binary refuses to start on an unparseable entry, a CIDR with host bits set (172.22.0.1/16: write 172.22.0.0/16 or 172.22.0.1), an IPv4 prefix broader than /8 or an IPv6 prefix broader than /32 (so 0.0.0.0/0, 0.0.0.0/1, ::/0, ::ffff:0.0.0.0/96 are all refused). It starts but logs a WARN for a non-loopback entry broader than /16 (IPv4) or /48 (IPv6), or a public range wider than one host. The nginx in front must send X-Forwarded-For $proxy_add_x_forwarded_for (appends the real peer on the right) and should set X-Real-IP $remote_addr; both dev sites do. Behind Docker's userland docker-proxy (a port published on 127.0.0.1), the container sees the network's bridge gateway (e.g. 172.22.0.1), not 127.0.0.1 — list that one address (/32), never the whole Docker subnet, whose other containers are real direct callers.

11. Developer portal (public, unauthenticated)

Matches ETOPS Integration Standard §8 ("the Gateway never writes API documentation. Instead it indexes it"):

None of this is reverse-proxied through the edge (like the rest of the admin surface, §9) — reached directly, on the control plane's own loopback port in development (docs/gateway/DEV_ROLLOUT.md) or however staging/ production choose to route it.

12. One public hostname, split by path (api.*)

Superseded design (v2, until now): a dedicated docs.* host proxied every request straight to the control plane, with a short-path alias (/{slug} → /apps/{slug}/docs) that only fired on that host. That's gone.

Current design: the control plane and the edge now share the same public hostname (api.gateway.etdevops.io / gateway.etdevops.io) — there is no docs.* host anymore. A reverse proxy in front of both (real nginx in production, tools/devproxy locally) splits every request by path, not Host:

Path Routes to
/, /docs, /openapi.json, /apps, /apps/{slug}/..., /developer-portal, /oauth/token, /applications/..., /credentials/..., /grants/..., /.well-known/jwks.json, /getting-started, /contract, /claude/... The control plane
Everything else — i.e. /<app-slug>/<path> The edge (proxying to that application, §5)

This works because reservedAppSlugs (internal/controlplane/manifest.go) already forbids an application from registering under any of the control plane's own top-level path names — Manifest.Validate() rejects appId values in docs, apps, developer-portal, oauth, applications, credentials, grants, healthz, api, getting-started, contract, claude at registration time. So the path split above is exhaustive and never ambiguous: a first path segment is either one of those reserved names (→ control plane) or it's a real, registered application's slug (→ edge), never both.

There is no shorter alias for an application's docs page anymore — a bare /{slug} now always means "call that application's real API" (via the edge), matching the same shape every other proxied call already uses (/hr-service/employees, §5). An application's docs stay reachable at the existing long form, /apps/{slug}/docs / /apps/{slug}/openapi.json, on the same hostname as everything else.

/api/v1/gateway/internal/* (§5's edge⇄control-plane contract) is deliberately not part of the public split above — it stays reachable only over the shared Docker network / loopback, authenticated separately by GATEWAY_INTERNAL_TOKEN, exactly as before (docs/gateway/DEV_ROLLOUT.md "What's deliberately NOT exposed").

Unlike the old docs.*-only posture, the admin API (/applications, /credentials, /grants, and friends — §3) is now reachable on this same public hostname, not loopback-only. See §13 for the credential model that makes that safe to expose, and internal/controlplane/api.go's withAdminIPRateLimit / withSecurityHeaders for the accompanying hardening (per-IP rate limiting, standard security response headers) that came with making a mutating admin surface public.

13. Admin API tokens (terminal-only)

Every admin-API request (§1, §3) authenticates with a bearer token that is either:

controlplane token create -name "alice@company.com" [-actor "who ran this"] [-ttl 720h]
controlplane token list
controlplane token revoke [-reason "..."] [-actor "..."] <id>
controlplane token rm <id>

14. Request log / observability API

Every request the edge actually classified (i.e. everything except a request that arrived while no config snapshot was loaded at all) reaches gateway_usage_log via §6, grouped by owning application via service. Two admin-authed read endpoints expose it — same bearer as every other admin-API call (§13), no new auth mechanism:

Neither endpoint is a substitute for the org-wide structured logging/error- tracking conventions in .claude/rules/observability.md — it's a gateway-specific, per-app status view, scoped to what the edge itself saw (status code, method, timing, route class), not a general log search or error-tracking tool.

15. Per-application header secrets: rotation policy (admin API) and the terminal-only CLI

XL1 (design docs/design/xl1-per-app-gateway-secret.md, §5.5/§5.6/§9). Each provider application's gateway header secret K(app, epoch) is derived from the master key GATEWAY_HEADER_MASTER_KEY (internal/hdrsecret); only the integer header_secret_epoch is stored, and it rides in the config snapshot (§5) as app_id + header_secret_epoch.

No HTTP endpoint returns, derives or rotates a secret. Showing and rotating are the terminal-only controlplane header-secret subcommands (same stance as §13: they need direct database access, never just a bearer token):

controlplane header-secret status [<app>] --actor <who> [--env <name>]
controlplane header-secret show   <app>   --actor <who> [--reason <why>] [--env <name>]
controlplane header-secret rotate <app>   --actor <who> --reason <why> [--prepare] [--env <name>]

Provider application side (§7). The application holds only its own values, never the master key, in GATEWAY_APP_HEADER_SECRETS: a comma-separated list of one to three etgh1_ values. One value at steady state; two during a rotation: current + next from rotate --prepare until rotate activates it, then current + previous until overlapEndsAt, after which the previous value is removed. The edge only ever sends the current epoch's value, so the list is what makes a rotation zero-downtime. Each value is compared by its 8-hex fingerprint (fp(K) = first 8 hex of SHA-256 of the value, as printed by the CLI and logged by the application at start-up), never by looking at it.

Rotation policy — an environment default plus an optional per-application override; settings, editable at runtime, never rotating anything themselves (a reminder logs rotation DUE lines when GATEWAY_HEADER_MASTER_KEY is set). Admin-authed like every §3 endpoint: