Promote native Notarius lane products
This commit is contained in:
@@ -56,47 +56,35 @@ func InspectExtractionEvidence(
|
||||
if !safeExtractionPathSegment(runID) {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceObsolete, Reason: "extract result has an invalid producing run ID"}
|
||||
}
|
||||
root := filepath.Clean(filepath.Join(paths.ArtifactsDir, "notarius", runID))
|
||||
if !filepath.IsAbs(root) || extractionMetadataString(r.Metadata, extractionMetadataRoot) != root {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceObsolete, Reason: "extract result does not identify its canonical immutable bundle"}
|
||||
root, err := filepath.Abs(paths.Root)
|
||||
if err != nil {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceUnsafe, Reason: "session root cannot be resolved"}
|
||||
}
|
||||
info, err := os.Lstat(root)
|
||||
if os.IsNotExist(err) {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceObsolete, Reason: "immutable Notarius bundle is missing"}
|
||||
}
|
||||
if err != nil || info.Mode()&os.ModeSymlink != 0 {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceUnsafe, Reason: "immutable Notarius bundle is unsafe"}
|
||||
}
|
||||
if !info.IsDir() {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceObsolete, Reason: "immutable Notarius bundle is not a directory"}
|
||||
}
|
||||
if !safeExistingExtractionDirectory(paths.Root, root) {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceUnsafe, Reason: "immutable Notarius bundle is unsafe"}
|
||||
}
|
||||
receiptRunID, receiptPipelineID := extractionReceiptIdentity(r.Metadata)
|
||||
if receiptRunID == "" || receiptPipelineID == "" {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceObsolete, Reason: "extract result has incompatible Notarius receipt identity"}
|
||||
artifactRoot := filepath.Join(root, "artifacts")
|
||||
completion, ok := r.Metadata["completion"].(map[string]any)
|
||||
if !ok || extractionMetadataString(completion, "pipeline") == "" {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceObsolete, Reason: "extract result has no native completion identity"}
|
||||
}
|
||||
pipelineID := extractionMetadataString(completion, "pipeline")
|
||||
expected := make(map[string]ExtractionArtifactDefinition, len(configured))
|
||||
for key, d := range configured {
|
||||
expected[ExtractionArtifactSourceID(key)] = d
|
||||
filenames := make(map[string]string, len(configured))
|
||||
for key, definition := range configured {
|
||||
source := ExtractionArtifactSourceID(key)
|
||||
expected[source] = definition
|
||||
filename := definition.Filename
|
||||
if filename == "" {
|
||||
filename = key + ".json"
|
||||
}
|
||||
if filename == "." || filename == ".." || filepath.Base(filename) != filename || strings.ContainsAny(filename, `/\\`) {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceUnsafe, Reason: "configured extraction filename is unsafe"}
|
||||
}
|
||||
filenames[source] = filename
|
||||
}
|
||||
seen, outputs := map[string]struct{}{}, map[string]ExtractionEvidenceOutput{}
|
||||
indexSeen := false
|
||||
for _, out := range r.Outputs {
|
||||
if strings.TrimSpace(out.ProducerRunID) != runID {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceObsolete, Reason: "extract output producer identity is inconsistent"}
|
||||
}
|
||||
if out.SourceID == "" {
|
||||
if indexSeen || out.Kind != extractionIndexKind || filepath.Clean(out.LocalPath) != filepath.Join(root, "index.json") {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceObsolete, Reason: "extract index path is not canonical"}
|
||||
}
|
||||
if state, reason, _ := inspectExtractionPayload(root, out.LocalPath, out.Checksum); state != ExtractionEvidenceValid {
|
||||
return ExtractionEvidence{State: state, Reason: reason}
|
||||
}
|
||||
indexSeen = true
|
||||
continue
|
||||
}
|
||||
d, ok := expected[out.SourceID]
|
||||
if !ok || out.Kind != extractionLaneKind {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceObsolete, Reason: "extract result source set differs from current configuration"}
|
||||
@@ -104,22 +92,27 @@ func InspectExtractionEvidence(
|
||||
if _, duplicate := seen[out.SourceID]; duplicate {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceObsolete, Reason: "extract result contains a duplicate configured source"}
|
||||
}
|
||||
if !compatibleCatalogExtractionContract(out.Contract, d) || !compatibleCatalogExtractionProvenance(out.ExternalProvenance, receiptRunID, receiptPipelineID, d) {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceObsolete, Reason: "extract output contract or provenance is incompatible"}
|
||||
if !filepath.IsAbs(out.LocalPath) || filepath.Clean(out.LocalPath) != filepath.Join(artifactRoot, filenames[out.SourceID]) {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceUnsafe, Reason: "extract output path is not its canonical destination"}
|
||||
}
|
||||
provenance := out.ExternalProvenance
|
||||
if provenance == nil || provenance.System != "notarius" || provenance.RunID != "" || provenance.PipelineID != pipelineID || pipelineID != strings.TrimSpace(d.PipelineID) || provenance.ArtifactID != d.LaneID {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceObsolete, Reason: "extract output lane or pipeline identity is incompatible"}
|
||||
}
|
||||
state, reason, size := inspectExtractionPayload(root, out.LocalPath, out.Checksum)
|
||||
if state != ExtractionEvidenceValid {
|
||||
return ExtractionEvidence{State: state, Reason: reason}
|
||||
}
|
||||
seen[out.SourceID] = struct{}{}
|
||||
outputs[out.SourceID] = ExtractionEvidenceOutput{
|
||||
Path: out.LocalPath, Checksum: out.Checksum, Size: size,
|
||||
Contract: cloneArtifactContract(out.Contract),
|
||||
if out.Size <= 0 || out.Size != size {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceObsolete, Reason: "extract output size does not match durable bytes"}
|
||||
}
|
||||
seen[out.SourceID] = struct{}{}
|
||||
outputs[out.SourceID] = ExtractionEvidenceOutput{Path: out.LocalPath, Checksum: out.Checksum, Size: size}
|
||||
}
|
||||
if !indexSeen || len(seen) != len(expected) || len(r.Outputs) != len(expected)+1 {
|
||||
if len(seen) != len(expected) || len(r.Outputs) != len(expected) {
|
||||
return ExtractionEvidence{State: ExtractionEvidenceObsolete, Reason: "extract result is incomplete"}
|
||||
}
|
||||
|
||||
return ExtractionEvidence{State: ExtractionEvidenceValid, ProducerRunID: runID, Outputs: outputs}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user