Skip to content

Commit 09b0688

Browse files
committed
fix(marketplace): fail closed on an unparseable verified digest, and cover the generation gate
A verified cosign signature whose manifest digest could not be parsed fell back to an unpinned tag pull, which reopens the tag-mutation window the verification was meant to close. Return an error instead. Add a test that isolates the status.observedGeneration == metadata.generation conjunct of artifactReady; the existing tests exercised only the tag-prefix conjunct, so a mutation of the generation check went uncaught. Assisted-by: LLM Signed-off-by: IvanHunters <[email protected]>
1 parent 0195e73 commit 09b0688

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

‎cmd/cozypkg/cmd/tap.go‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,13 @@ runs its charts in your management cluster: tap only sources you trust.`,
377377
if verr != nil {
378378
return verr
379379
}
380-
if ref.Digest == "" && verifiedDigest != "" {
380+
// Fail closed: a verified signature with no parseable digest must not
381+
// fall back to an unpinned tag pull, which would reopen the tag-mutation
382+
// window between verify and pull.
383+
if verifiedDigest == "" {
384+
return fmt.Errorf("cosign verified %q but returned no manifest digest; refusing to pull by an unpinned tag", ref.pullRef())
385+
}
386+
if ref.Digest == "" {
381387
ref.Digest = verifiedDigest
382388
}
383389
}

‎internal/operator/tapmaterializer_reconciler_test.go‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,3 +694,46 @@ func TestReconcilePinsPreUpgradeTapBeforeEarlyReturn(t *testing.T) {
694694
t.Errorf("expected pinned-digest annotation %q, got %v", manifest, got.Annotations)
695695
}
696696
}
697+
698+
// artifactReady must also wait when status.observedGeneration lags
699+
// metadata.generation: the artifact may still describe the spec from before the
700+
// current re-connect, so pinning from it would pin stale content even when the
701+
// revision happens to match the tag. This isolates the generation conjunct of the
702+
// gate (the revision here matches the tag, so only the generation check can block).
703+
func TestReconcileWaitsWhenObservedGenerationLags(t *testing.T) {
704+
scheme := tapScheme(t)
705+
data, digest := tarGz(t, map[string]string{"packages/core/platform/sources/hello.yaml": samplePS})
706+
manifest := "sha256:" + strings.Repeat("d", 64)
707+
repo := tapRepo(true)
708+
repo.Generation = 2 // spec advanced by a re-connect
709+
repo.Spec.Reference = &sourcev1.OCIRepositoryRef{Tag: "v1"}
710+
cl := fake.NewClientBuilder().WithScheme(scheme).
711+
WithObjects(repo).
712+
WithStatusSubresource(&sourcev1.OCIRepository{}).
713+
Build()
714+
715+
var live sourcev1.OCIRepository
716+
if err := cl.Get(context.Background(), req().NamespacedName, &live); err != nil {
717+
t.Fatal(err)
718+
}
719+
live.Status.Artifact = &fluxmeta.Artifact{URL: "http://example.com/a.tar.gz", Digest: digest, Revision: "v1@" + manifest}
720+
live.Status.ObservedGeneration = 1 // source-controller has not caught up to generation 2
721+
if err := cl.Status().Update(context.Background(), &live); err != nil {
722+
t.Fatal(err)
723+
}
724+
725+
r := materializerFor(scheme, cl, record.NewFakeRecorder(10), &data)
726+
if _, err := r.Reconcile(context.Background(), req()); err != nil {
727+
t.Fatalf("reconcile: %v", err)
728+
}
729+
var got sourcev1.OCIRepository
730+
if err := cl.Get(context.Background(), req().NamespacedName, &got); err != nil {
731+
t.Fatal(err)
732+
}
733+
if got.Spec.Reference.Digest != "" {
734+
t.Errorf("must not pin while observedGeneration lags generation, got %q", got.Spec.Reference.Digest)
735+
}
736+
if got.Annotations[tapconst.PinnedDigestAnnotation] != "" {
737+
t.Errorf("must not record a pin while observedGeneration lags, got %v", got.Annotations)
738+
}
739+
}

0 commit comments

Comments
 (0)