Finish FLEX-WP-0019 layer-model v0.7 conformance
Close the remaining PDP obligations: mechanical layer declaration check, registry-snapshot digest in provenance, explicit allow TTL, per-input-class freshness deadlines, and the published decision-record contract. Document the canonical request digest as the §6.4.2 replay test. Assistant: grok Assistant-Session: 01a06256-fb71-7102-b3a9-27e6734257d0
This commit is contained in:
parent
9689894c15
commit
56940727bf
32 changed files with 1194 additions and 111 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/open-policy-agent/opa/ast"
|
||||
"github.com/open-policy-agent/opa/rego"
|
||||
|
|
@ -148,6 +149,17 @@ func (p *Package) Evaluate(ctx context.Context, request api.CheckRequest) (api.D
|
|||
return p.evaluateDecision(ctx, request)
|
||||
}
|
||||
|
||||
// Digest is the SHA-256 of canonical metadata plus the compiled Rego module.
|
||||
func (p *Package) Digest() string {
|
||||
return api.CanonicalDigest(struct {
|
||||
Metadata api.PolicyPackageMetadata `json:"metadata"`
|
||||
RegoModule string `json:"rego_module"`
|
||||
}{
|
||||
Metadata: p.Metadata,
|
||||
RegoModule: p.RegoModule,
|
||||
})
|
||||
}
|
||||
|
||||
// Validate runs metadata, CARING, OPA parse/test, and fixture validation.
|
||||
func (p *Package) Validate(ctx context.Context) ValidationResult {
|
||||
result := ValidationResult{}
|
||||
|
|
@ -235,6 +247,24 @@ func (p *Package) metadataDiagnostics() []Diagnostic {
|
|||
if p.Metadata.Package == "" {
|
||||
diagnostics = append(diagnostics, requiredDiagnostic("POLICY-METADATA-PACKAGE", "package", "OPA package path is required"))
|
||||
}
|
||||
if strings.TrimSpace(p.Metadata.AllowTTL) != "" && !strings.EqualFold(strings.TrimSpace(p.Metadata.AllowTTL), "none") {
|
||||
ttl, err := time.ParseDuration(strings.TrimSpace(p.Metadata.AllowTTL))
|
||||
if err != nil {
|
||||
diagnostics = append(diagnostics, Diagnostic{
|
||||
Code: "POLICY-ALLOW-TTL-INVALID",
|
||||
Severity: "error",
|
||||
Message: fmt.Sprintf("allow_ttl %q is not a Go duration", p.Metadata.AllowTTL),
|
||||
Fields: []string{"allow_ttl"},
|
||||
})
|
||||
} else if ttl < 0 {
|
||||
diagnostics = append(diagnostics, Diagnostic{
|
||||
Code: "POLICY-ALLOW-TTL-INVALID",
|
||||
Severity: "error",
|
||||
Message: "allow_ttl must be none, 0s, or a positive duration",
|
||||
Fields: []string{"allow_ttl"},
|
||||
})
|
||||
}
|
||||
}
|
||||
return diagnostics
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue