Skip to content

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

Closed
jframe wants to merge 9 commits into
masterfrom
enclave-host-provisioning
Closed

jframe wants to merge 9 commits into
masterfrom
enclave-host-provisioning

Conversation

@jframe

@jframe jframe commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

PR Description

Part of #1301. Stacked on #1313; the base switches to master once that merges. 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:

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;
  • provider, platform and key policy refusals before any release;
  • the release blob dump;
  • giving up when nothing listens, and waiting for an enclave that starts late;
  • 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. Seal and provision against real KMS and Nitro come with the acceptance tests later in the series.


Note

High Risk
Introduces operator-facing handling of BLS secrets, KMS data keys, and enclave provisioning; mistakes or logging misconfiguration could expose key material despite deliberate safeguards.

Overview
Adds an experimental web3signer enclave command tree with seal, provision, and status, wiring the CLI to new enclave-host KeySealer and KeyProvisioner implementations so operators can encrypt BLS keys into bundles and load them into a running enclave signer.

seal supports AWS Nitro (KMS) and dev platforms, reading EIP-2335 keystores or raw hex secrets; provision releases the data key via KMS or dev master key and loads the bundle; status can poll with --wait-seconds and --min-keys for deployment checks. CLI integration keeps tool output on stdout, logs and errors on stderr, skips the normal signer startup banner, and caps HTTP wire logging at INFO so KMS data keys are not logged at DEBUG.

EnclaveClient gains a separate connectTimeout (short connects while --wait-seconds bounds overall polling). enclave-host adds test fixtures (FakeEnclaveSigner) and broad unit/integration tests for sealing, provisioning, and the CLI path.

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

Base automatically changed from enclave-host-bundle to master December 2, 2026 02:12
@jframe jframe added the TEE label Dec 2, 2026
jframe and others added 4 commits December 2, 2026 02:54
…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
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Gabriel-Trintinalia

Copy link
Copy Markdown
Contributor

I have read the CLA Document and I hereby sign the CLA

@Gabriel-Trintinalia

Copy link
Copy Markdown
Contributor

recheck

github-actions Bot added a commit that referenced this pull request Dec 2, 2026

@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.

Stale Bugbot comment from a previous run.

- 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>

@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.

Reviewed by Cursor Bugbot for commit 941a3f1. Configure here.

Copilot AI 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.

🟡 Changes recommended

Active issues allow malformed keystores to be silently omitted, readiness waits to exceed their deadline, and negative --min-keys values to report false readiness.

3 open issues
What changed in this PR

Adds host-side key sealing, provisioning, and readiness commands for the experimental enclave signer, building on the existing bundle and key-release infrastructure.

Changes:

  • Seals BLS keys and provisions bundles with provider, platform, policy, and load-result checks.
  • Adds enclave seal, provision, and status, with script-friendly output and protected HTTP logging.
  • Separates connection timeouts and adds a cryptographic fake enclave for tests.
File Description
enclave-protocol/​src/​test/​java/​tech/​pegasys/​web3signer/​enclave/​client/​EnclaveClientTest.java Tests separate connection and response timeouts.
enclave-protocol/​src/​main/​java/​tech/​pegasys/​web3signer/​enclave/​client/​EnclaveClient.java Adds configurable connection timeout.
enclave-host/​src/​testFixtures/​java/​tech/​pegasys/​web3signer/​enclave/​host/​FakeEnclaveSigner.java Adds cryptographic provisioning fixture.
enclave-host/​src/​test/​java/​tech/​pegasys/​web3signer/​enclave/​host/​KeySealerTest.java Tests sealing inputs and failures.
enclave-host/​src/​test/​java/​tech/​pegasys/​web3signer/​enclave/​host/​KeyProvisionerTest.java Tests provisioning and connection failures.
enclave-host/​src/​test/​java/​tech/​pegasys/​web3signer/​enclave/​host/​aws/​AwsKmsKeyReleaseBrokerTest.java Tests ARN region extraction.
enclave-host/​src/​main/​java/​tech/​pegasys/​web3signer/​enclave/​host/​KeySealer.java Encrypts keys into bundles.
enclave-host/​src/​main/​java/​tech/​pegasys/​web3signer/​enclave/​host/​KeyProvisioner.java Coordinates checks, release, and loading.
enclave-host/​src/​main/​java/​tech/​pegasys/​web3signer/​enclave/​host/​EnclaveHostException.java Adds host-operation errors.
enclave-host/​src/​main/​java/​tech/​pegasys/​web3signer/​enclave/​host/​aws/​AwsKmsKeyReleaseBroker.java Extracts regions from KMS ARNs.
enclave-host/​build.gradle Adds sealing dependencies and test fixtures.
commandline/​src/​test/​java/​tech/​pegasys/​web3signer/​commandline/​XHelpSubCommandTest.java Includes the unstable enclave option.
commandline/​src/​test/​java/​tech/​pegasys/​web3signer/​commandline/​CommandlineParserEnclaveTest.java Tests commands, validation, and logging.
commandline/​src/​main/​java/​tech/​pegasys/​web3signer/​commandline/​Web3SignerBaseCommand.java Registers enclave commands.
commandline/​src/​main/​java/​tech/​pegasys/​web3signer/​commandline/​subcommands/​EnclaveSubCommand.java Provides shared command handling.
commandline/​src/​main/​java/​tech/​pegasys/​web3signer/​commandline/​subcommands/​EnclaveStatusSubCommand.java Reports status and polls readiness.
commandline/​src/​main/​java/​tech/​pegasys/​web3signer/​commandline/​subcommands/​EnclaveSealSubCommand.java Exposes bundle sealing.
commandline/​src/​main/​java/​tech/​pegasys/​web3signer/​commandline/​subcommands/​EnclaveProvisionSubCommand.java Exposes bundle provisioning.
commandline/​src/​main/​java/​tech/​pegasys/​web3signer/​commandline/​CommandlineParser.java Routes tool output and restricts HTTP logging.
commandline/​build.gradle Adds host module and fixture dependencies.

Review effort: Balanced

- 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>

Copilot AI 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.

🔵 Needs a closer look

An unresponsive peer can block STATUS beyond the configured readiness-wait limit because the deadline is checked only after the request returns.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity STATUS requests can exceed the readiness wait deadline

commandline/​src/​main/​java/​tech/​pegasys/​web3signer/​commandline/​subcommands/​EnclaveStatusSubCommand.java:81

With --wait-seconds=5 --response-timeout-seconds=300, a peer that accepts the connection but never answers blocks this call for roughly 300 seconds, because the deadline is checked only after client.status() returns. This defeats the documented readiness-wait bound for deployment scripts. Bound an in-flight STATUS request by the remaining positive wait, for example with a watchdog like the provisioner's, while preserving the zero-wait single-request behavior.

3 resolved since last review

Review effort: Balanced

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>
@jframe

jframe commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Replaced by #1331

@jframe jframe closed this Dec 2, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 2, 2026

This branch was previously deployed

1 inactive deployment
docker — 9e89cca0 Deployed Dec 2, 2026 by jframe via docker-build (default, amd64) #1288
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants