Repository navigation
feat(core): fetch Bedrock principal v2 verifier keys from the metadata document - #186
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
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.
|
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). |
What
A generation-2 Connect consumer with an empty
bedrock-principal.public-keysmap can now verifyBedrock 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 ONLYpublic-keys;metadata-origin/metadata-pathwerevalidated for capability but never fetched. So even with the moxy producer in place (see
connect/bedrockauth/v2_metadata.go), aconfig-generation: 2/mode: requirebackend could notwork without hand-pasting keys. This is independent of the moxy A/B claims decision.
How
BedrockPrincipalKeySource(new,@Singleton, constructed fromConfigHolder+ the nameddefaultHttpClientlike the existingBedrockIdentityKeyProvider):issuer/trust_domain/audienceagainst local config; accepts onlykty=OKP,crv=Ed25519,alg=EdDSA,use=sig, canonical unpadded base64url 32-bytex.current/next/previouskey states —revokedanddisabledare parsedfor rotation context but never installed; an unknown state fails the fetch closed.
cache_max_age_seconds(capped at 300 s, which is the producer's own bound) andrevalidates with
If-None-Match/ETag, so a304keeps the cached keys.kidis not in the cached set triggers one rate-limited (5 s)refresh. The verifier instance — and therefore its replay cache — is never rebuilt.
bounded 600 s window. With no usable pins and no reachable document, admission fails closed
with
METADATA_UNAVAILABLEand 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
kidthe static set doesnot contain. Verification semantics (schema, signature, bindings, time, replay) are unchanged.
BedrockPrincipalReadinessnow accounts for fetched keys (isReady/attest/capabilities), exposes the privacy-safe fetch state (sourceSTATIC_PINS|METADATA|NONE, lastsuccessful refresh, freshness, trusted
kidset), and includes the fetched kid set in thereadiness revision.
docs/bedrock-identity.mddocuments the zero-config mode, the document contract, rotation andfail-closed behaviour.
Producer alignment: the document shape is exactly
connect/bedrockauth/v2_metadata.goinminekube/moxy — same path, field names, key encoding,
statevocabulary,ETagandCache-Control: max-agesemantics.Note: the card body referred to a
bedrock-identity-keypath. The repo's frozen generation-2 path(
BedrockPrincipalConfiguration.METADATA_PATH, mirrored by the producer'sV2MetadataPath) isbedrock-principal-v2.json; that is what this change fetches.Evidence
RED before the fix (independent worktree at unfixed
01970af, test compiles against the pre-fixAPI):
BedrockPrincipalAdmissionException: METADATA_UNAVAILABLE, and the stubbed metadata endpointwas never contacted.
GREEN — new
BedrockPrincipalMetadataKeysTest(10 tests):public-keys+ reachable metadata verifies a real signed vector frombedrock-principal-v2/core-vectors.json, then a second envelope insidecache_max_agereuses thecached document (1 request);
METADATA_UNAVAILABLE;kidforces exactly one rotation refresh;cache_max_agethe refresh is conditional (If-None-Match) and a304keeps the keys;public-keysstays authoritative and never fetches;revokedmetadata key is never installed;NONE, when metadata is unreachable);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
jqfail on a pristine HEAD worktree in this environmenttoo (daemon PATH without
jq) and pass once run withjqon the worker PATH.No release, no merge, no deploy — PR only.