0056 · Temporary credentials
- Status: accepted (2026-12-04). Omar approved the three product and security decisions recorded in §1–§3.
- Date: 2026-12-04
- Builds on: item sections and authenticated encryption in
klav-core(docs/especificacion-cripto.md§7), environments per repository (ADR 0032), agent and Sentinel credential sharing (ADR 0036, ADR 0055), and database/API-key items (ADR 0054).
Context
Developers regularly handle short-lived secrets: a deployment token for one incident, a temporary API key for a migration, a database credential for a contractor, or a value that should exist only while a repository task runs. Today every Klav item is permanent unless a person remembers to delete it. Deletion is easy to forget, and Trash retention keeps the ciphertext recoverable after the operational need has ended.
Omar wants temporary credentials to be ordinary encrypted items so they automatically work with klav run, klav.toml, agents, Sentinel, projects, and cross-device sync, without a second secret format or special-case cryptography.
Decision
1. Temporary credentials are ordinary items with authenticated expiry
An item of any kind may carry:
"expires_at_ms": 1800003600000The value is a Unix timestamp in milliseconds, serialized as a signed JSON integer (i64, the timestamp convention already used by klav-core). The field is optional in both item sections:
- overview (
0x10), so a client with onlylistcan show and enforce expiry without opening secret details; - details (
0x11), so every secret-reading path has the expiry authenticated together with the value it is about to use.
The two copies must be exactly equal. Rebuilding an item whose overview and details disagree fails closed with SectionMismatch, following the same discipline as kind and the other duplicated metadata. Both copies are inside the AEAD plaintext; no expiry is ever trusted from plaintext metadata alone.
A permanent item omits the key in both sections. Because serialization uses skip_serializing_if = "Option::is_none", all items and test vectors written before this ADR remain byte-for-byte identical. There is no binary format, label, kind byte, header, key-wrap, AAD, or wire breakage for existing blobs.
Both section schemas already reject unknown keys. Therefore a client older than this ADR rejects or skips a newly created temporary item instead of silently treating it as permanent. That is deliberate fail-closed behavior for a security-critical field. Older clients continue to read all permanent items unchanged. Layers 2–4 must make this rollout visible and must not create temporary items until the server and the person's active clients support them.
2. Expiry is immediate, offline, and inclusive; purge is automatic and hard
At the boundary itself the item is expired:
expired(now_ms, expires_at_ms) <=> now_ms >= expires_at_msOnce expired, clients, klavd, the CLI, agents, and Sentinel must treat the item as expired/not found for secret reads: no read, fill, inject, proxy use, TOTP use, reveal, or resolution. This check uses the authenticated expiry inside the item and the local wall clock supplied by the caller. It runs before any background cleanup and does not require connectivity.
Expiry is wall-clock time, not a monotonic lease. A server timestamp is never accepted as a substitute for the device's own clock. Malware or a person with control over the operating system clock can move that clock backwards; that is the same device-compromise boundary already documented in the threat model. Server-side cleanup uses the server clock only to delete ciphertext, never to extend what a client accepts.
Expired items are purged automatically, not sent to Trash:
- each client/daemon runs a background sweep while online or unlocked;
- the server also keeps a nullable plaintext
expires_atcolumn on the item row and hard-purges ciphertexts and attachments whose expiry has passed, even when no device is online.
The plaintext column exists only so the server can enforce expiry autonomously. It is NULL for permanent items and for every item written before this feature. For a temporary item it is a copy of authenticated expires_at_ms copied by the client that writes the item. The server never sees an expiry for permanent items.
This is an explicit privacy trade-off. On temporary items only, the server learns that the item is temporary and when it expires; it does not learn the title, kind, project name, value, or why the credential exists. The overview copy is also visible to holders of the list permission, like the item title and tags; that is deliberate so countdowns and list-level enforcement do not require opening secrets. This metadata is accepted because autonomous server purge substantially reduces how long ciphertext and attachments remain available after compromise or loss of all devices. The threat model records the residual metadata risk.
The plaintext column is not security evidence. Clients compare it exactly with the authenticated value:
| authenticated inside item | server expires_at |
result |
|---|---|---|
None |
NULL |
permanent item, valid |
Some(x) |
x |
temporary item, valid |
Some(x) |
NULL |
stripped expiry: reject as tampered |
Some(x) |
y ≠ x |
shortened/extended expiry: reject as tampered |
None |
x |
forged expiry: reject as tampered |
A mismatch must not be “corrected” by trusting either side. It is a sync/integrity error and the item is unavailable for secret use. Layer 2 defines the exact server error and sync representation; the pure comparison helper is in layer 1.
3. Creation bounds and human TTLs
Creation and editing validate expiry with the pure helper:
validate_item_expiry(expires_at_ms, now_ms)Rules:
expires_at_msmust be strictly afternow_ms;- the lifetime must be at least 1 minute;
- the lifetime must be at most 365 days.
The core TTL parser accepts one or more <number><unit> components with units s, m, h, and d (for example 30m, 1h, 8h, 24h, 7d, and 1d12h) and already enforces the 1-minute/365-day range. This is intentionally separate from task-request duration parsing, which historically accepts only s, m, and h and has task-specific limits; the shared digit/unit scanner is reused without changing task semantics.
Quick presets for layers 2–4 are 1h, 8h, 24h, and 7d, plus a custom duration or date. Planned entry points include:
klav item add ... --expires 24h;klav env set ... --ttl 8h;- Mac and iOS New/Edit item expiry selector;
- countdown badge, with actions to extend the expiry or make the item permanent.
Changing expiry is an ordinary item edit: it increments the item version and rewrites both authenticated sections atomically. Making an item permanent removes the key from both sections. A client must validate the new expiry before writing. An already expired item cannot be resurrected from an old ciphertext because its old authenticated expiry remains expired; a person must write a new version before purge or recreate the item after purge.
Layered rollout
Layer 1 — klav-core, specification, and deterministic vectors (this PR)
- optional authenticated
expires_at_msin item overview and details, omitted on permanent items; - exact overview/details equality check;
- pure helpers for TTL parsing, creation validation, inclusive expiry checks, and server/authenticated consistency;
- deterministic vectors in
docs/vectores/temporales.json; - crypto specification and threat-model documentation;
- no server, sync, CLI, daemon, FFI, or UI behavior yet.
Layer 2 — server, sync, and purge
- nullable plaintext
expires_atitem column and migration; - exact-match enforcement between the column and authenticated item expiry in client sync;
- server-side hard purge of expired ciphertexts and attachments;
- background client/daemon sweep and sync semantics for expired/missing items;
- server feature/version signaling so updated clients do not create temporary items against a server that cannot purge them;
- agent/Sentinel enforcement: stale grants, item-key shares, cached ciphertexts, and in-memory values are not usable after expiry.
Layer 3 — clients, daemon, CLI, SDK, and FFI
- creation/edit APIs that validate expiry;
- local enforcement in every secret read/fill/inject/proxy/TOTP/reveal path;
klav item add ... --expires <ttl|date>andklav env set ... --ttl <ttl>;- expired/not-found behavior and errors;
- countdown/expiry data in FFI for apps.
Layer 4 — Mac and iOS UI
- expiry selector in New/Edit item;
- countdown badges and expired state;
- extend and make-permanent actions;
- environment and Sentinel presentation of temporary credentials;
- warning when old devices would not understand temporary items.
Security consequences
The important integrity property is that expiry is authenticated in the same ciphertext as the item. A malicious server cannot:
- strip expiry from a temporary item and make it permanent;
- extend expiry so a secret remains usable beyond its intended life;
- forge expiry on a permanent item;
- alter only one section, because overview/details equality is checked;
- move expiry to another item, version, project, vault, or account, because the existing AAD already binds the ciphertext to that context.
A malicious server can always delete ciphertext early or refuse service; expiry does not attempt to solve availability against the server. The server purge column improves confidentiality after expiry but does not authenticate correctness.
Expiry does not create a new rollback defense. A server cannot edit expiry inside a ciphertext, but it can try to serve an older version of the same item — for example a permanent version written before the person made it temporary, or a version with a longer expiry. The existing monotonic item versions and high-water marks detect that rollback on every device that has already synchronized the newer version. A brand-new device inherits the existing first-sync rollback limitation in the threat model. Layer 2 must treat expiry changes as ordinary versioned edits and must never use the plaintext column to override those high-water marks.
A value already decrypted and copied before expiry cannot be made unknown. Expiry bounds future use of the item; it does not erase memory in an agent that already received the value. This is consistent with the existing agent threat model and is another reason reveal remains exceptional.
Test vectors
docs/vectores/temporales.json covers:
- valid and invalid TTL strings;
- creation validation boundaries, including minimum and maximum lifetimes;
- inclusive expiry at
now == expires_at_ms; - permanent items never expiring;
- exact server/authenticated consistency, stripped expiry, extended expiry, and forged expiry;
- authenticated encryption/decryption round trips of a temporary API-key item;
- byte-level omission of
expires_at_mson the same permanent item.
All pre-existing vector files are unchanged.