Credential cards and attachment API
This backend API has no dashboard yet. Existing account and object encryption formats are unchanged. Cards contain a separate opaque HPKE envelope: the server never receives a card's plaintext or private key. A delivered secret is readable by the agent and anything it runs.
Machine enrollment and owner confirmation
POST /auth/device/cards/enroll with the machine's rtm_ bearer token and {public_key, expected_version}. public_key is a 32-byte X25519 public key in standard padded base64. First enrollment uses expected_version 0. The response contains machine_id, public_key, key_version, fingerprint (SHA-256 hex of the raw public key), and confirmed. Repeating the same key is idempotent; rotation increments key_version and requires confirmation again.
A signed-in owner uses POST /api/cards/key with {machine_id}, then /api/cards/confirm with {machine_id, key_version, fingerprint}. Compare the fingerprint with the machine through a trusted channel. Machine tokens and agent API keys cannot act as the signed-in owner.
Owner card operations
POST /api/cards/save-v2 requires all these fields:
{
"format_version": 2, "incarnation": "a fresh UUID v4 for a new card",
"grant_id": "owner-use-grant-id",
"binding": {"env_name":"DEPLOY_TOKEN", "exec_root":"/absolute/project",
"delivery":"file", "session_id":"session-id"},
"card_id": "deploy-token", "machine_id": "machine-id",
"expected_revision": 0, "key_version": 1,
"secret_name": "DEPLOY_TOKEN", "secret_version": 1,
"envelope": {"enc": "standard base64", "ciphertext": "standard base64"},
"operators": ["operator-id"], "exec_roots": ["/absolute/project"],
"env_names": ["DEPLOY_TOKEN"], "deliveries": ["env", "file"],
"expires_at": 1793910000, "max_uses": 1
}
Use RFC 9180 base mode: DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, ChaCha20-Poly1305. info is UTF-8 roundtable/credential-card/v2. enc is 32 bytes; ciphertext includes the 16-byte authentication tag (plaintext 1–65536 bytes). AAD is the UTF-8, compact JSON array [2,account_id,machine_id,key_version,secret_name,secret_version,card_id,incarnation,revision,grant_id,binding.env_name,binding.exec_root,binding.delivery,binding.session_id,operators,expires_at,max_uses], in exactly that order; strings use JSON escaping, integer fields remain integers; expires_at is an integer Unix timestamp. The v2 schema normalizes integral numeric representations (including a trailing .0) before constructing AAD. revision is expected_revision + 1. Preserve operators array order. The incarnation is a client-generated lowercase UUID v4, kept across updates and never reused after deletion; the server persists a uniqueness tombstone. grant_id identifies this owner-approved credential-use grant, separately from the existing machine prompt grant. The binding is one exact session, root, environment name and delivery; its values must also be in the card’s policy arrays. Changing a binding requires fresh owner encryption. There are no wildcard bindings. The server checks envelope bounds and bindings but cannot authenticate ciphertext without the machine key. Consumers must reconstruct this array from the returned metadata, authenticate it, and compare tenant, recipient machine and session to trusted local identity before acting. Never decrypt using only a server-supplied aad array. This versioned format does not change any existing account/object encryption format. The legacy /api/cards/save format and stored envelopes remain readable via get, but cannot issue new deliveries: delivery_upgrade_required requires owner re-encryption using save-v2.
TTL is at most one day; max_uses is 1–1000. Save returns {card_id, incarnation, revision, aad}. Updating uses expected_revision from the current card. Explicit saves replace the grant and use budget, invalidate pending tickets by revision, and require fresh encryption for the current target key. Changing a machine or rotating a key requires the owner to re-encrypt locally. The server cannot decrypt for the owner; retain the plaintext securely or use a trusted source machine. A missing target envelope yields secret_unavailable_on_target.
POST /api/cards/list with {} returns {cards:[{card_id,machine_id,revision,secret_name,expires_at,uses_left}]}. POST /api/cards/get with {card_id} returns the owner's full card, including its encrypted envelope. POST /api/cards/delete with {card_id} revokes it and marks its pending tickets invalid in the same transaction. Re-creating the same card_id requires a new incarnation; old tickets cannot spend the replacement’s uses. Only the creating owner may read or change a card. The dashboard must render all strings as text.
Delivery tickets
POST /api/tools/request_credential with an agent/operator bearer token and {request_id,card_id,machine_id,session_id,exec_root,env_name,delivery}. Returns {request_id,expires_at,consumed}, never ciphertext or plaintext. The operator must be explicitly in the card grant and have current prompt permission on the session. Signed-in MCP OAuth connections are refused; use a CLI operator credential. exec_root must exactly match an approved root, not merely a path prefix.
The target machine POSTs /auth/device/cards/consume with {request_id}. It returns {format_version:2,account_id,card_id,incarnation,revision,grant_id,machine_id,key_version,secret_name,secret_version,operators,binding,expires_at,max_uses,envelope,aad}. Use only the authenticated binding for delivery. Consumption rechecks the credential, delegation, machine permission, card incarnation and revision, expiration and key confirmation. Consumption is serialized; the last use deletes the stored envelope. Each ticket expires after five minutes and can be consumed only once. A lost response is not replayed: request a new owner-approved budget if necessary. Expired tickets are cleaned up on subsequent requests. Requests and deliveries, including semantic refusals after authentication, create durable tenant-scoped sealed events with the operator, card id/incarnation/revision, machine, session, time and outcome. Events contain no secret or envelope and survive ticket cleanup. A paused, expired, removed or rotated requesting operator yields 403 secret_denied; 401 on the device channel is reserved for the machine’s own authentication.
The daemon consumer is not implemented in this backend track. It must recheck canonical local exec policy and session identity, decrypt through its OS keychain, register the plaintext with the shared Redactor before use, and deliver only to the selected process environment or a 0600 file. A locked/missing keychain must fail closed. Neither this API nor a ticket grants execution permission.
Attachments and link previews
The HTTP tools below also appear in MCP (arguments are wrapped in {request:...}). Agent reads and deletes are private to the uploading agent and account; signed-in workspace owners can list and delete account attachments; IDs are not bearer capabilities.
upload_attachment: {request_id,name,media_type,content_base64}. Types: text/plain (UTF-8), image/png, image/jpeg. Maximum decoded input and canonical image output: 512 KiB. Images are decoded with 4096×4096 dimension limits and a 32 MiB image-crate allocation budget (not a total process-memory bound), then re-encoded to PNG with metadata removed. JPEG decoder internals allocate outside that budget: progressive JPEG coefficient planes can take roughly another 64 MiB near the output limit, plus decoder and encoder overhead. The 4096-pixel dimensions, 512 KiB input and decoder’s 100-scan cap still apply; no 32 MiB peak-memory guarantee is made. Returns {id,name,media_type,size_bytes,preview,creator,created_at}.prepare_attachment: {request_id,source_kind,source_id}. source_kind note reads an authorized shared file or markdown note and applies upload validation. artifact fails closed with artifact_unavailable until P5b is integrated.get_attachment: {attachment_id}. Returns the private attachment including content_base64. Text previews contain at most 2000 characters; image previews contain width and height. No executable HTML preview is generated.discard_attachment: {request_id,attachment_id}. Deletes the private attachment. Repeating after deletion returns not_found.discard_preview: {request_id,attachment_id}. Delete a preview using its id as attachment_id.create_preview: {request_id,url,title}. Returns a link event {id,kind:"link",url,title,creator,created_at}. Only HTTP(S), no embedded username/password. Query and fragment are removed. The server performs no request, tunnel or HTML rendering. UI consumers must show an explicit link, not an iframe or automatic navigation.
Signed-in owner cleanup: POST /api/cards/attachments with {} or {after} returns {attachments:[metadata with record_kind],next}. Pages contain at most 100 entries; pass next as after until null. No preview text, URL, content_base64, input digest or fingerprint is returned. POST /api/cards/delete-attachment with {kind:"attachment"|"preview",attachment_id} deletes the selected account record. Agent and machine tokens cannot call these owner operations. Upload idempotency compares only canonical redacted content using a tenant-keyed HMAC; changed secret strings that redact identically are the same request, and the fingerprint is never returned.
The shared Redactor removes token patterns from text and metadata; matching binaries are rejected instead of rewritten. This is a defense layer, not a guarantee. Opaque card plaintext is unavailable to the server, so known-value registration and scanning before upload remain the daemon's responsibility. No OCR or steganography detection is claimed.
Attachments and previews share a separate quota of 32 records per agent, including both kinds. They cannot consume owner card or machine-key slots, or any operator’s ticket budget. Existing larger attachment collections remain readable/deletable but cannot grow until below quota. Revoking an agent also purges its attachments and previews. The existing byte-storage quota still applies: encrypted payloads count toward the existing 3 GB storage quota. Full-schema encrypted backups include cards, keys, tickets, attachments and previews, with the existing account envelopes. Restore quota recount includes sealed payloads and audit events; full-schema dumps also preserve the attachment-owner index and permanent incarnation tombstones. A backup can restore earlier grant/use state; operational restore must revoke old device/operator credentials and require owner review before resuming delivery. Machine private keys are not backed up here.
Errors include code and detail for feature-specific rejection: secret_denied, secret_unavailable, secret_unavailable_on_target, key_changed, revision_conflict, request_conflict, invalid_expiry, invalid_key, invalid_encoding, invalid_size, record_limit, ticket_limit, attachment_limit, incarnation_reused, invalid_binding, delivery_upgrade_required, attachment_type, attachment_size, attachment_decode, secret_detected, preview_url, artifact_unavailable and not_found. Existing authentication, validation and quota errors retain their existing shapes.
Capacity and private audit
Cards and machine keys each have 512 owner-controlled slots per account. Tickets use a separate budget of 32 receipts per requesting operator, including consumed and invalidated receipts until their five-minute expiry. A full operator budget returns 409 ticket_limit and cannot block another operator, owner card saves or machine enrollment. Expired tickets and expired-machine keys are reclaimed at every capacity check. The server also reclaims expired ticket receipts and keys for expired or revoked machines in bounded batches of up to 1,000 of each kind per maintenance tick (normally once per minute), releasing their charged storage without another request. Card deletion first reclaims expired receipts, then invalidates remaining live receipts in the same transaction. Operator revocation releases its tickets; machine logout or revocation releases its key and tickets.
POST /api/cards/audit requires an owner browser session. Send {} or {"after":123}; the response is {"events":[{"seq":124,"kind":"credential_delivery","data":{}}],"cursor":124}, with up to 100 events in sequence order. Each data object records operator, card id/incarnation/revision, machine, session, time, outcome, exec root, env name and delivery mode, never a secret or envelope. The reserved audit namespace cannot be a project. Existing audit events remain owner-readable and are excluded from agent updates.
The owner-only POST /api/cards/key response includes account_id alongside the machine, version, public key, fingerprint and confirmation status. Handoff enrollment checks that account and machine, and requires owner confirmation. A public key inside a handoff packet cannot enroll a machine. Machine private keys stay in owner-controlled custody.