Skip to content

feat(core): fetch Bedrock principal v2 verifier keys from the metadata document - #186

Merged
robinbraemer merged 3 commits into
mainfrom
feat/bedrock-principal-runtime-keys
Nov 30, 2026
Merged

robinbraemer merged 3 commits into
mainfrom
feat/bedrock-principal-runtime-keys

Conversation

@minekube-ai-engineer

Copy link
Copy Markdown

What

A generation-2 Connect consumer with an empty bedrock-principal.public-keys map can now verify
Bedrock signed principals zero-config: it fetches the frozen verifier-key document at
metadata-origin + metadata-path (/.well-known/minekube-connect/bedrock-principal-v2.json)
instead of failing every Bedrock session with METADATA_UNAVAILABLE.

Static pins remain authoritative: a connector with pins never fetches, and its behaviour is
byte-for-byte what it was before this change.

Why

BedrockPrincipalConsumer.verifier() read ONLY public-keys; metadata-origin/metadata-path were
validated for capability but never fetched. So even with the moxy producer in place (see
connect/bedrockauth/v2_metadata.go), a config-generation: 2 / mode: require backend could not
work without hand-pasting keys. This is independent of the moxy A/B claims decision.

How

  • BedrockPrincipalKeySource (new, @Singleton, constructed from ConfigHolder + the named
    defaultHttpClient like the existing BedrockIdentityKeyProvider):
    • HTTPS only, no redirects, 5s call bound, 64 KiB body cap, 16-key cap.
    • Validates issuer / trust_domain / audience against local config; accepts only
      kty=OKP, crv=Ed25519, alg=EdDSA, use=sig, canonical unpadded base64url 32-byte x.
    • Installs only current / next / previous key states — revoked and disabled are parsed
      for rotation context but never installed; an unknown state fails the fetch closed.
    • Honours cache_max_age_seconds (capped at 300 s, which is the producer's own bound) and
      revalidates with If-None-Match / ETag, so a 304 keeps the cached keys.
    • Rotation: an envelope whose kid is not in the cached set triggers one rate-limited (5 s)
      refresh. The verifier instance — and therefore its replay cache — is never rebuilt.
    • Stale-while-error: after cache expiry the last good document keeps verifying for a further
      bounded 600 s window. With no usable pins and no reachable document, admission fails closed
      with METADATA_UNAVAILABLE and v2 capability is not advertised.
  • PrincipalKeyResolver (new public API seam) + VerifierConfiguration.Builder#keyResolver:
    static pins are consulted first; the resolver is only a fallback for a kid the static set does
    not contain. Verification semantics (schema, signature, bindings, time, replay) are unchanged.
  • BedrockPrincipalReadiness now accounts for fetched keys (isReady / attest /
    capabilities), exposes the privacy-safe fetch state (source STATIC_PINS|METADATA|NONE, last
    successful refresh, freshness, trusted kid set), and includes the fetched kid set in the
    readiness revision.
  • docs/bedrock-identity.md documents the zero-config mode, the document contract, rotation and
    fail-closed behaviour.

Producer alignment: the document shape is exactly connect/bedrockauth/v2_metadata.go in
minekube/moxy — same path, field names, key encoding, state vocabulary, ETag and
Cache-Control: max-age semantics.

Note: the card body referred to a bedrock-identity-key path. The repo's frozen generation-2 path
(BedrockPrincipalConfiguration.METADATA_PATH, mirrored by the producer's V2MetadataPath) is
bedrock-principal-v2.json; that is what this change fetches.

Evidence

RED before the fix (independent worktree at unfixed 01970af, test compiles against the pre-fix
API): BedrockPrincipalAdmissionException: METADATA_UNAVAILABLE, and the stubbed metadata endpoint
was never contacted.

GREEN — new BedrockPrincipalMetadataKeysTest (10 tests):

  1. empty public-keys + reachable metadata verifies a real signed vector from
    bedrock-principal-v2/core-vectors.json, then a second envelope inside cache_max_age reuses the
    cached document (1 request);
  2. unreachable metadata fails closed with METADATA_UNAVAILABLE;
  3. an envelope with an uncached kid forces exactly one rotation refresh;
  4. after cache_max_age the refresh is conditional (If-None-Match) and a 304 keeps the keys;
  5. populated public-keys stays authoritative and never fetches;
  6. metadata whose trust scope disagrees with config is rejected;
  7. a revoked metadata key is never installed;
  8. a slow document cannot hold the join path beyond the 5 s bound;
  9. readiness becomes ready from metadata and reports source/freshness/kid set (and is not ready,
    NONE, when metadata is unreachable);
  10. capability still requires generation 2 + mode: require.

Full local gate on JDK 17: ./gradlew build → BUILD SUCCESSFUL, core 416 tests / velocity 34 /
spigot 49 / bungee 4, 0 failures (includes the platform DI/startup regression guards). The eight
release-harness tests that shell out to jq fail on a pristine HEAD worktree in this environment
too (daemon PATH without jq) and pass once run with jq on the worker PATH.

No release, no merge, no deploy — PR only.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 62ff0823-7fc8-460d-888f-fbfbc8b4d5c7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Rationale: the metadata key source fetched synchronously under a shared
lock reached from BedrockAdmissionCoordinator.stage(), so a slow origin
stalled every session and readiness attestation for up to ten seconds.
Keys are now refreshed by one lazily created daemon thread
(connect-bedrock-principal-keys) with at most one request in flight,
scheduled at cache expiry and kept warm without joins. The join path and
readiness only read an immutable snapshot: a missing or expired snapshot
fails METADATA_UNAVAILABLE, an unknown kid fails TRUST, and both schedule
a rate-limited background refresh. A bounded warm-up (at most 5s) runs
only while building the Watch connection and the libp2p registration so
the capability is advertised when keys are obtainable; a withheld
capability logs one warning when keys arrive later. ConnectPlatform
disable() closes the source and it restarts lazily after reload.

The readiness revision now hashes a fixed metadata source marker with the
configured scope instead of the fetched keys, so connectors of one
endpoint keep equal revisions during a rotation. Documents with duplicate
kids across all entries are rejected; entries of unknown state or key
type are skipped; a document without an installable key is not a trust
source and drops the previous keys. A kid-triggered refresh is skipped
when the document was fetched within the rate-limit interval. Fetch
failures and rejections log a rate-limited warning and a new kid set
logs once at info, without key material.

Tested: docker eclipse-temurin:17-jdk linux/arm64 ./gradlew build
--no-daemon --continue (with jq installed): BUILD SUCCESSFUL, core 425,
spigot 49, velocity 34, bungee 4 tests, 0 failures;
BedrockPrincipalMetadataKeysTest 19/19 including join-path-no-I/O,
3xx, 5s timeout via the production client, stale window, forced-refresh
rate limit, duplicate kids, revoked-kid TRUST and revision stability.
Rationale: a Watch connection opened while the metadata warm-up failed
withheld bedrock-verified-principal-v2, so a require-mode connector kept
refusing every Bedrock join until some unrelated reconnect, even after
the keys arrived. BedrockPrincipalReadiness now records what each
transport last advertised and refresh(Transport) reports, without
blocking, when that no longer matches readiness. The existing 5s
WatcherRegister.refreshWatchReadiness check re-watches on that flip in
both directions (keys arrived, or the stale window closed), next to the
v1 identity check. The withheld-capability warning is tracked per
transport so a libp2p registration no longer clears the Watch warning.

Tested: docker eclipse-temurin:17-jdk linux/arm64 ./gradlew build
--no-daemon --continue (jq installed): BUILD SUCCESSFUL, core 428,
spigot 49, velocity 34, bungee 4 tests, 0 failures. New
WatcherRegisterTest re-watch test fails with the hook disabled and passes
with it; new BedrockPrincipalMetadataKeysTest cases cover up/down flips
and per-transport withheld state.
@robinbraemer

Copy link
Copy Markdown
Member

Independent review: REQUEST_CHANGES at c629de0 (network fetch on the join path under the coordinator lock; readiness revision hashed fetched keys), fixed in 61dbd7b (background refresh with immutable snapshot reads on the join path, bounded warm-up only at Watch/libp2p advertisement, scope-only revision, per-entry skip, duplicate kids rejected, forced-refresh dedupe, diagnostics, 19 tests) and b087b1b (Watch re-connects when v2 readiness flips; per-transport withheld state). Re-review: APPROVE at b087b1b. CI build (17)/(21) green; full Docker build: core 428, spigot 49, velocity 34, bungee 4 tests, 0 failures. Merging to release the zero-config v2 consumer for the Bedrock verified-identity rollout (moxy#765, moxy#767).

@robinbraemer
robinbraemer merged commit 20ef015 into main Nov 30, 2026
3 checks passed
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