[#4253 7/8] feat(policy,discovery): fatal load-time PD validation (Policy 7)#4290
Draft
stevenvegt wants to merge 1 commit into
Draft
[#4253 7/8] feat(policy,discovery): fatal load-time PD validation (Policy 7)#4290stevenvegt wants to merge 1 commit into
stevenvegt wants to merge 1 commit into
Conversation
Assisted-by: AI
Contributor
|
Coverage Impact This PR will not change total coverage. 🚦 See full report on Qlty Cloud »🛟 Help
|
This was referenced May 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Parent PRD
#4253
Item 7 of 8. Depends on item #2 (#4281,
pe.Validate) — branched off4253-2-validators. Independent of the #3/#4/#5 chain.Summary
Wire
pe.Validate(Policy 7) into the two places that load operator-owned PresentationDefinitions at startup — the local policy backend and discovery service definitions — and make an inconsistent PD fatal at boot. This matches the existing precedent (a PD that fails JSON-schema validation already prevents startup) and the PRD's "fail to load" intent.Why fatal at boot
Configure(startup) into memory; request-time serving (FindCredentialProfile) reads memory, never disk. So load time is the natural and only place to validate them.v2.ValidateinvalidatingPresentationDefinition.UnmarshalJSON). Making the semantic same-idcheck fatal too keeps both classes of invalid policy consistent: the node refuses to run with a broken policy file.idPD comes from Policy 3 (always-on), which yieldsErrNoCredentialswith aMatchReportexplanation — but with fatal boot, such a node never starts serving in the first place.Backward-compatibility caveat: a same-
idPD with conflicting filters currently works (same-idis decorative today — independent per-descriptor matching). After this change it fails to boot. Operators must audit deployed PDs before upgrading; the release notes (#8) carry the audit checklist. This is the breaking edge the PRD's impact assessment already calls out.Implementation Spec
policy/local.goIn
loadFromFile's per-scope loop (lines 177-191), after the existing profile checks, validate each non-nil PD withpe.Validate:Organization,ServiceProvider,User(the three*validatingPresentationDefinitionslots).*pe.PDValidationError, return an error naming the scope, the wallet-owner, and the file, wrapping the typed error (whose message aggregates every conflicting field id), e.g.:presentation definition for scope %q (%s) is invalid (file=%s): %w.loadFromFile -> loadFromDirectory -> Configure, so the node refuses to start.(Hooked here rather than in
UnmarshalJSONso the message carries scope/owner/file context;UnmarshalJSONonly knows the bare PD.)discovery/definition.goIn
ParseServiceDefinition, after the unmarshal (line 72), callpe.Validate(definition.PresentationDefinition):invalid presentation definition in service definition %q: %wwithdefinition.ID.loadDefinitions -> Configure, fatal at startup (same as the existing schema validation at line 66).Testing
idtype/const conflict failsloadFromFile; the error names the field id, the scope, and the wallet-owner. A consistent same-idPD loads fine.ParseServiceDefinitionnaming the service id; a consistent one parses.Acceptance Criteria
policy/local.govalidates each non-nil profile PD at load viape.Validate; failure is fatal and names scope + owner + file.discovery/definition.govalidates the service-definition PD inParseServiceDefinition; failure is fatal and names the service id.*pe.PDValidationErrordetail; consistent PDs (incl. path-only same-iddifferences) load fine.go build ./...andgo test ./policy/... ./discovery/...pass.