Skip to content

feat(enclave): seal and provision key bundles, with enclave seal/provision/status - #1331

Merged
Gabriel-Trintinalia merged 22 commits into
masterfrom
enclave-seal-provision
Dec 3, 2026
Merged

Gabriel-Trintinalia merged 22 commits into
masterfrom
enclave-seal-provision

Conversation

@Gabriel-Trintinalia

@Gabriel-Trintinalia Gabriel-Trintinalia commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

PR Description

Supersedes #1317: the same branch, reopened so that its original author can review it. The first four commits are #1317 as it stood; the last four address the reviews it got since (see "Changes since #1317").

Part of #1301, on top of #1313. Seals BLS keys into a key bundle and provisions a bundle into a running enclave signer, with the enclave subcommands that drive both. This is the whole host side: an operator can seal, provision and check an enclave signer with what's here.

  • Sealer. Reads EIP-2335 keystores (one password file or one password file per keystore) and a raw secrets file, and seals every secret under a new data key, with the public key as additional data. It refuses a wrong password, malformed JSON, a key seen twice, zero keys and invalid secrets, without ever printing a secret. JSON that isn't a keystore, such as deposit_data-*.json, is skipped.
  • Provisioner. Checks the bundle's provider against the broker and optionally runs the broker's key policy check, before waiting for the enclave. Then it checks the enclave's platform, gets evidence, has the broker release the data key, and loads the keys. It fails unless every key ends up loaded or already held.
  • enclave seal, enclave provision, enclave status. seal takes the region from a KMS key ARN, so --aws-region is only needed for a bare key id or alias. provision builds its KMS broker from the bundle's key ARN, so there's no region flag. --verify-key-policy defaults to true for KMS bundles and false for dev ones, since the dev broker has no key policy. status --min-keys --wait-seconds lets a deployment script wait for a provisioned enclave. The tools print their results on stdout and log to stderr. The HTTP client's wire and header loggers stay at INFO, so --logging=DEBUG never prints the KMS data key.
  • Fake enclave signer in enclave-host's test fixtures. It does the real crypto for the dev platform: a fresh RSA release key per GET_EVIDENCE, a CMS unwrap, then an AES-GCM open of each sealed key, checked against its public key with Teku. So this PR's tests don't need the enclave signer module.

The sealer and provisioner come from #1304 and the subcommands from #1306. Changes from those:

Changes since #1317

These come from two code reviews and two Copilot reviews of #1317.

Waits and timeouts

  • provision --wait-seconds holds when the enclave accepts a connection but never answers: the session's first STATUS is bounded by what is left of the wait (at least 2 s), by closing the session from a watchdog. It used to run for the response timeout. The error says the enclave did not answer in time.
  • status has --response-timeout-seconds (default 10), so a busy enclave is not reported as down after 2 s. With --wait-seconds, a request in flight at the deadline is cut short.
  • EnclaveClient.Options has a separate connectTimeout. The two-argument constructor keeps one timeout for both. A connect timeout is reported as such. This touches enclave-protocol, including its README.
  • Timeout options are capped at what the client accepts, before any KMS call.

Refusals

  • seal and provision refuse options of the other platform, so a leftover --aws-kms-key-id cannot silently produce a dev bundle.
  • seal fails on an empty or whitespace-only *.json keystore and on content after the JSON value, instead of skipping the file. It checks the output directory before the data key and the decrypts, and refuses more keys than one signer holds (Protocol.MAX_KEYS).
  • status refuses a negative --min-keys.

Command line

  • --output, --address and --bundle can come from --config-file. They are checked by the tools, not with picocli's required, which failed the parse before the config file was applied.
  • Usage errors of the enclave tools go to stderr, so stdout only carries results. Failures no longer say "Failed to initialize Web3Signer". An OutOfMemoryError while sealing gets a heap hint.
  • status reports why the enclave is unreachable (refused, unknown host, the vsock hints).
  • "The data key most likely does not match this bundle" is reported whenever no key loads, also when some keys were already held.

Left open, for the reviewer to decide

  • seal accepts a multi-Region KMS key, which provision refuses by default in the key policy check.
  • provision prints nothing while it retries during --wait-seconds.
  • status --wait-seconds stops at the first refusal of STATUS instead of waiting on.
  • With a custom -Dlog4j.configurationFile, logs go where that file sends them, which can be stdout. For the deployment guide.

Fixed Issue(s)

Part of #1301.

Documentation

  • I thought about documentation and added the doc-change-required label to this PR if updates are required. The deployment guide comes at the end of the series.

Changelog

  • I thought about adding a changelog entry, and added one if I deemed necessary. One entry, with the deployment guide.

Testing

  • I thought about testing these changes in a realistic/non-local environment.

The sealer tests cover every input source and refusal. The provisioner tests run against the fake enclave and cover:

  • loading, duplicates and adding to keys already held;
  • bundles larger than one load request;
  • every entry or some entries rejected, and a wrong data key with keys already held;
  • provider, platform and key policy refusals before any release;
  • the release blob dump;
  • giving up when nothing listens, waiting for an enclave that starts late, and an enclave that accepts but never answers;
  • an enclave on another protocol version, and a connection lost after the keys load;
  • wiping the data key after use.

The commandline tests seal, provision and check status end to end against the fake, and check that seal --logging=DEBUG keeps the data key out of the logs. They also cover the config file, the refusals above and the status waits. Seal and provision against real KMS and Nitro come with the acceptance tests later in the series.

Run locally: the tests of enclave-protocol and enclave-host, and the enclave and parser tests of commandline. The full build was not run locally.

🤖 Generated with Claude Code


Note

High Risk
Introduces host-side BLS key handling, KMS data-key generation/release, and enclave provisioning paths where mishandling or logging could expose validator secrets.

Overview
Adds experimental web3signer enclave subcommands — seal, provision, and status — wired through enclave-host (KeySealer, KeyProvisioner) so operators can encrypt BLS keys into bundles (AWS Nitro KMS or dev), load them into a running enclave signer, and poll readiness with --min-keys / --wait-seconds.

CLI/parser behavior is tailored for tooling: enclave commands keep stdout for machine-readable output, route errors and usage to stderr, skip the normal Web3Signer startup banner, and cap HTTP client debug logging so KMS data keys are not logged at DEBUG.

Security and ops hardening includes optional KMS key-policy verification before provision, refusal of multi-Region KMS keys at seal time, cross-platform option validation, secret hygiene in sealing errors, and EnclaveClient changes (separate connect timeout, isPermanent() on connect failures) to support bounded retries in status and provision.

Extensive unit/integration tests use a new FakeEnclaveSigner test fixture and expanded enclave-host / commandline test coverage.

Reviewed by Cursor Bugbot for commit ee84ea3. Bugbot is set up for automated code reviews on this repo. Configure here.

jframe and others added 17 commits December 3, 2026 08:26
…ision/status

Adds KeySealer, which seals EIP-2335 keystores and raw secrets into a key
bundle, and KeyProvisioner, which loads a bundle into a running enclave
signer through the broker's key release. The enclave subcommand wraps both,
plus a status check. A fake enclave signer in enclave-host's test fixtures
does the dev platform's real crypto, so the host side is tested end to end
without the enclave signer module.

Ported from #1304 and #1306.
- Errors: keystore failures give their reason; the tools print the cause chain,
  name missing or unreadable files, and print the stack trace at debug level.
- enclave tools: no server startup log line; --version and help on every tool;
  bare `enclave` fails; key source options are checked up front by name.
- seal: takes the region from a KMS key ARN; gets the data key before decrypting
  keystores, so a wrong key fails fast; keystores are read once.
- provision: checks --address first; a 2 second connect timeout so
  --wait-seconds holds; the key policy check runs before connecting; a protocol
  version mismatch is an EnclaveHostException; a lost key count after loading no
  longer fails the run (Result.enclaveKeyCount is optional, bundleKeys removed).
- Help text for --response-timeout-seconds and --dev-master-key-file.
- Tests: connect retry, partial load, status wait, version mismatch, data key
  wiping, raw key formats and option checks; no free port races.
- At --logging=DEBUG the HTTP client's wire logger printed KMS responses,
  including GenerateDataKey's plaintext data key. The enclave tools now hold
  the client's wire and header loggers at INFO.
- The enclave tools log to stderr, so stdout carries only their output.
- One shared 2 second connect timeout for provision and status.
…1313

- KeyBundle.Provider enum in place of the provider strings
- KeySealer seals a bundle through one AesGcm instance, closed after use
- FakeEnclaveSigner opens entries through an AesGcm instance
- AwsKmsKeyReleaseBroker.arnRegion matches key and alias ARNs itself, as
  #1313 replaced regionOf with a key-ARN-only pattern
- KeySealerTest keeps the data key array, as DataKey refuses plaintext()
  once closed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ykVB9dTVuCZAgm9NVX9oZ
- provision: wait for the enclave with a pooled STATUS on the short
  request timeout before opening the session, so --wait-seconds holds
  when a proxy accepts but the enclave never answers
- status: add --response-timeout-seconds (default 10); EnclaveClient.Options
  gains a separate connectTimeout so the connect stays short
- seal/provision: refuse options of the other platform, so a leftover
  --aws-kms-key-id cannot silently produce a dev bundle (and vice versa)
- enclave tools: usage errors go to stderr, keeping stdout for results;
  execution failures no longer say "Failed to initialize Web3Signer";
  an OutOfMemoryError while sealing gets a heap hint
- timeout options are capped at what the client accepts, checked before
  any KMS call
- blame the data key whenever no key loads, also when some were already
  held

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- provision: bound the session's first STATUS by what is left of the
  wait (at least 2 s) by closing the session from a watchdog, instead
  of probing on a pooled connection first; a session that accepts but
  never answers no longer holds provisioning for the response timeout
- status: refuse a negative --min-keys, which passed for an empty enclave
- seal: an empty or whitespace-only *.json keystore fails instead of being
  skipped as "not a keystore", and content after the JSON value is a
  parse error, so a truncated keystore cannot drop a key silently

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- required options (--output, --address, --bundle) are checked by the
  tools and not by picocli, whose check failed the parse before a value
  from --config-file could be applied
- provision: when the first STATUS outlasts the wait, say that the
  enclave did not answer in time, not that the connection dropped
- client: a connect timeout is reported with the connect timeout, not
  the request timeout; README describes connectTimeout
- status: an unreachable enclave is reported with its cause (refused,
  unknown host, vsock hints), and with a stack trace at DEBUG
- seal: check the output directory before the data key and the slow
  decrypts, and refuse more keys than one signer can hold
- test: compare stderr with normalized newlines

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A request in flight at the deadline ran on for the response timeout,
which --response-timeout-seconds can make much longer than the wait.
With a wait, a watchdog now closes the client at the deadline, which
fails the request in flight; without one, the single request still gets
the whole response timeout.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Jackson's parse error quotes the text it could not read. With a raw keys
file named *.json among the keystores, that text is a secret, and the
tools print the causes of a failure. Drop the cause and report only the
line and column.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The loop slept until the deadline and then polled once more, just as
the watchdog closed the client, so an enclave that answered but held too
few keys was mostly reported as not answering STATUS. No request is sent
once the wait is over; the last answer is reported instead.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The listing kept regular files only, so a *.json symlink to a volume
that is not mounted, or a directory named *.json, was left out and seal
succeeded with a key fewer. Entries are now taken by name, and one that
is not a readable file fails.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The config file provider throws with the root command line, so a missing
file or an unknown key printed the root usage on stdout, which the
enclave tools keep for results. The writer is now also picked from the
arguments.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A mistyped --keystores-path, password file, passwords directory or raw
keys file only failed after KMS had been asked for a data key. sealToFile
now checks that each given source is there first, next to the check of
the output directory.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Cancelling the CompletableFuture left its timer task in the delayed
executor, so each attempt that connected and then failed kept its
session and connection until the rest of the wait had passed. The
watchdogs now run on a scheduler of the connect that removes cancelled
tasks and is shut down when the connect ends.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Only the copy that toArray() made was zeroed. The array behind
toBytes(), the copy made for the zero check, the parsed bytes of a raw
key and every BLSSecretKey stayed in memory for the rest of the run,
also when sealing failed.

- seal and the zero check take the array of toBytes() itself and zero it
- a raw key's parsed bytes are zeroed once the key is made
- sealToFile destroys every key once the bundle is sealed or sealing
  failed, and readKeyPairs destroys the keys read so far when it fails

The in-memory seal(List) used by tests leaves the caller's keys alone.
The hex lines of a raw keys file and the copies inside KeyStore.decrypt
are Strings and library internals and are not reached by this.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
seal accepted a multi-Region key, and provision then refused the bundle
in the key policy check, which is its default: the operator only found
out on the enclave host and had to seal again. The KMS broker now
refuses it when it creates the data key, by the key ARN that KMS returns,
so that an alias or a bare key id is covered too.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
With more keystores than one enclave signer can hold, every one of them
was decrypted first, with the data key in memory all the while, and the
limit only refused at the end. The *.json entries are now read and
parsed first, which is cheap, to leave out those that are not keystores;
their number and the number of raw keys are checked against the limit
before the first decrypt.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…t fix

provision retried every failure for the whole --wait-seconds, 60 seconds
by default, and printed nothing meanwhile: also without a vsock driver,
or with a host name in --address that does not resolve.

A provisioning connect that fails is now marked permanent unless the
address refused the connection, did not answer in time or reset it
(EnclaveAddress.mayConnectLater, EnclaveUnavailableException.isPermanent),
and provision reports a permanent failure at once. A failure after the
connect, such as an enclave that accepts but does not answer, is retried
as before.

On vsock, ENODEV and ENETUNREACH count as permanent: the driver or the
transport is missing. An enclave that is not running yet answers
ETIMEDOUT, and a port nothing listens on ECONNREFUSED.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Gabriel-Trintinalia and others added 2 commits December 3, 2026 10:29
status --wait-seconds kept asking for the whole wait with a typo in the
host name or without the vsock driver, although provision stops at once
on the same failures.

Only the connect of a provisioning session was marked permanent. The
client's connect now reports its own failure, for a pooled request as
for a provisioning session, and marks it permanent unless the address
refused the connection, did not answer in time or reset it. status
stops polling on a permanent failure. A request that fails after it
connected is not permanent.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ime left

The loop was a while (true) with its exits spread through the body. It
now tries once and again while the failure is not permanent and the wait
has time left, keeps the last failure and throws it once the loop ends.
No change in behaviour: after the last pause there is still one attempt.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 570604f. Configure here.

After sleeping the last of the wait, the connect loop made one more
attempt, which with the two second minimum for the first STATUS could
run a few seconds past --wait-seconds. status sends nothing once its
wait is over; provision now does the same. There is still always one
attempt, also with a zero wait.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Gabriel-Trintinalia
Gabriel-Trintinalia enabled auto-merge (squash) December 3, 2026 00:22
@Gabriel-Trintinalia
Gabriel-Trintinalia merged commit 13e7f3e into master Dec 3, 2026
14 checks passed

This branch was successfully deployed

1 active deployment
docker — c35e41a4 Deployed Dec 3, 2026 by Gabriel-Trintinalia via docker-build (default, arm64) #1315
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants