Skip to content

feat(broker): encrypt ToolHive credential storage - #2275

Merged
jhrozek merged 6 commits into
mainfrom
ext-broker-04-adapter-encrypt
Oct 13, 2026
Merged

jhrozek merged 6 commits into
mainfrom
ext-broker-04-adapter-encrypt

Conversation

@jhrozek

@jhrozek jhrozek commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Validate Mecatl session IDs at broker boundaries.
  • Add a reusable credential envelope and encrypted typed ToolHive credential storage.
  • Persist guarded credential-custody transitions.
  • Inject enrollment discovery and gate connector publication.

Verification

  • Not run as part of this PR-opening operation.

jhrozek and others added 6 commits October 12, 2026 16:17
Use the Mecatl session ID as the logical broker session key. Admit only IDs
that also pass the session-affinity header rule (printable ASCII, no boundary
spaces, 256 bytes), so a session that can be created can also be reached
through the Converse client and connector inventory. Reject other IDs before
broker-enabled host creation, fork or clear successor creation, and broker
runtime attach and connector inspection. Deleting a session whose ID the
broker cannot hold is a no-op, so deletion stays idempotent.

Co-Authored-By: mecatl <[email protected]>
Add an immutable key ring and versioned AES-GCM envelopes with row- and
field-bound associated data. Keep old keys available for reads while
the active key handles new writes. Decode strictly so each envelope has one
string form, and require caller associated data because it is the only
binding between a ciphertext and its row.

Pin compatibility with ciphertext from the reconstruction branch;
storage and custody integration follow in separate commits.

Co-Authored-By: mecatl <[email protected]>
Wrap ToolHive's native storage to seal upstream token and DCR secret
fields while leaving row identity, expiry, indexes, and persistence
semantics with ToolHive. Preserve refresh CAS by passing the exact
stored ciphertext to the native compare-and-swap operation, and leave a
missing row to native CAS so an empty expectation still creates it. Fail
closed on device-flow confirmations, which ToolHive stores unsealed.

The package is named sealedauthstorage to keep it apart from
internal/adapter/credentialstore, and its doc states what is and is not
protected: secret-field confidentiality, not metadata integrity against a
Redis writer.

Add protected Redis/key-file construction with a health check and
single-owner cleanup. Cover field binding, rotation, native storage
behavior, and failure paths; runtime wiring follows separately.

Co-Authored-By: mecatl <[email protected]>
Stage encrypted recovery evidence only after checking the referenced
ToolHive token rows and bounding retention by their earliest session
expiry. Bind the recovery reference to the logical session,
incarnation, owner and workload partitions, a nonzero profile digest,
and providers. Gate every transition on the caller's attempt deadline,
checked against Redis time; the deadline is not stored in the record.

Commit, resolve, and tombstone through guarded Redis compare-and-swap
transitions. Recheck custody after token refresh so expiry or a
concurrent tombstone cannot authorize a stale result. A Redis writer can
still replay an older ciphertext; the code documents that limit. Cover
restart, concurrency, deadline, and failure paths; runtime wiring follows.

Co-Authored-By: mecatl <[email protected]>
Replace Runtime's Process pointer with copied enrollment configuration,
a narrow authenticated discoverer, and a publication gate bound to its
owning Process. Keep ToolHive construction and discovery behind the
Process while allowing standalone runtimes to remain independent.

Discover protected backend capabilities outside the publication lock,
then publish only while the owning process, session, grant, transaction,
and attachment remain current. Inspect connectors through the same gate
without changing enrollment state; shutdown blocks stale publication.

This closes races the previous code left open: catalogue refresh checked
state, released the lock, then assigned; completed-enrollment installation
had no gate; the observe commit ignored process shutdown and context
cancellation; and rollback drained before marking the process closed. Every
publish path now also requires the runtime's entry for the session to be the
same session object.

Cover injection, enrollment, discovery, inspection, and shutdown races.
Protected credential storage and custody remain unwired in this slice.

Co-Authored-By: mecatl <[email protected]>
Fix gci import grouping, document exported sealedauthstorage methods,
and annotate the intentional empty critical section and the not-yet-wired
production storage constructor.

Co-Authored-By: mecatl <[email protected]>
@jhrozek
jhrozek merged commit 21b999c into main Oct 13, 2026
37 of 38 checks passed
@jhrozek
jhrozek deleted the ext-broker-04-adapter-encrypt branch October 13, 2026 11:24
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 13, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant