Design note — Klaviyo W5 push reads the vault (klaviyo)

Target registry item: C1c (OB-GAP-7; checklist §5.3 — the W5 value-feed push authenticates from an environment variable, not the tenant's vault entry, so a completed Klaviyo card can leave W5 not_configured). Status: design note only — NOT built. Measured on 2026-10-12 in the worktree: services/measurement-rails/klaviyo_feed.py:47 API_KEY_ENV = "KLAVIYO_PRIVATE_API_KEY" (name only, default empty); health() (:131–143) reports not_configured until that env is non-empty; send_events() (:166–170) reads the env only on a live send and raises CredentialMissing when empty; the module docstring names vault wiring as "a later, deliberate step". services/measurement-rails/requirements.txt pins fastapi, uvicorn, pydantic, google-cloud-bigquery, PyYAML only — the image does NOT ship connector_credentials.py or any connectors-service module. CDoD points are tracked in docs/reports/ONBOARDING_CONNECTORS_STATE.md.

Auth

The W5 push authenticates with the tenant's own Klaviyo private key (Authorization: Klaviyo-API-Key …, fetched 2026-10-12). The key must come from the ONE vault entry mizoki-connector-{tenant}-klaviyo the Connectors card already writes (api_key), resolved per (tenant, provider); the process environment never serves it. The tenant is the one the send route already carries (tenant_id in send_klaviyo_value_events, ncm_feed_wiring.py:344), bound to the verified caller at the route — never a free field.

Semantics (D11, direct_connectors.resolve_provider_credentials): vault error → 503 fail-closed, because KLAVIYO_PRIVATE_API_KEY is process-GLOBAL and degrading to it would push one tenant's margin events into another tenant's Klaviyo account; vault absence → not_configured for that tenant and the send is refused before any transport call; no environment fallback at all. This is the deliberate opposite of LwaCredentials.for_tenant (connectors/amazon_sp/client.py), whose loud env degrade is safe only because its env names are tenant-prefixed.

Scope requirement (the fact that makes "never ask twice" non-trivial)

The pull half (klaviyo_connector.py, aggregate campaign values) needs read scopes; the W5 push creates events, which needs events:write (Klaviyo scopes are resource:read / resource:write; a key's scopes cannot be edited after creation — delete and recreate; fetched 2026-10-12). So the single api_key on the card must be a custom-scoped key carrying both the read scopes the pull uses and events:write. Consequences:

Schema (what changes, and what does not)

Vault payload: unchanged (api_key, optional webhook_secret). No new field.

klaviyo_feed.health() becomes per-tenant and reports credential_source: "vault" plus status ∈ {configured, not_configured, scope_insufficient, store_unavailable}; the credential_env key is retired from the readout (a reader must not be told an env name still matters). The /health aggregate without a tenant reports the rail flag and credential_source only — never a boolean pretending to be every tenant's truth.

Resolver placement — proposal and why

The vault read has to cross the image boundary. Three options were weighed:

option verdict
A. Vendor a resolver into measurement-rails (klaviyo_vault.py): one Secret Manager REST read over ADC, the naming formula duplicated from connector_credentials.secret_id with a parity test asserting the two agree — the exact precedent connectors/amazon_sp/client.py LwaCredentials._from_vault set, parity pinned by tests/connectors/test_amazon_sp.py. Proposed. Secrets never leave Secret Manager except into the process that uses them; no new network surface; the collision-suffix grammar (-h<12hex>) is reproduced, not reinvented.
B. An internal "read credentials" HTTP endpoint on service-marketing-connectors Rejected: it creates a credential-disclosing route. The onboarding rule says raw secrets never enter read responses; a 503-fail-closed resolver inside the consuming image is strictly smaller.
C. Ship the connectors module in the measurement-rails image Rejected: couples two deploy paths (rule 04 "a change that spans two services deploys asymmetrically") for one function.

Dependencies: google-auth and an HTTP client are not declared in requirements.txt. google-cloud-bigquery brings google-auth and requests transitively, but a transitive dependency is not a declared one and the resolver would then be a function of whatever the BigQuery client happened to pin. Declare them explicitly with upper bounds (google-auth>=2.29,<3, requests or httpx bounded the same way — rule 03), and add them to the ratchet's governed tuple in the same commit if the ratchet covers them.

topic posture
value events OUT (profile email / phone / external_id, plaintext by Klaviyo's own contract, value = margin never revenue) unchanged by this note; the merchant's own first-party ESP already holds the profile; the rail's dry-run default, KLAVIYO_FEED flag and injected-transport-only discipline all stay
credential the tenant's key; masked …tail on status; never logged, never in a dry-run artifact (today's artifact carries the env NAME — after wiring it carries credential_source: vault and no name)

No new data flows; this note moves where a secret is read from, not what is sent.

Mapper target

None — W5 is a value-feed OUT rail, not ingestion. Nothing is written to mizoki_unified_data by this change.

Failure modes → verdicts

Failure Verdict
Vault read error (IAM, network, non-200) 503 credential_store_unavailable; no env fallback; the send is refused.
No vault entry for the tenant not_configured (named gap connectors.klaviyo:not-configured already in tenant_economics.py vocabulary); send refused.
Key present but lacks events:write scope_insufficient; send refused; card asks for a replacement key once.
Rail flag off / no transport / dry_run unchanged: require_rail, require_transport, dry-run artifact.

Flag

No new flag. The rail already sits behind three independent gates (KLAVIYO_FEED default OFF, dry_run=True default, injected-transport-only), all pinned by fail-if-flipped tests; this change replaces the credential source under them. The env read is REMOVED, not kept as a fallback, and a source-literal test asserts os.environ is never consulted for the key (the "no module imports or constructs" assertion shape from rule 01). Tests run in both directions: a stub vault that errors must produce 503; a stub that returns the key must produce a live send through the injected transport.

Owner / operator gates

Vendor references

← All docsView source on GitHub →