Skip to content

Commit 9cff86f

Browse files
IvanHuntersmyasnikovdaniil
authored andcommitted
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]> (cherry picked from commit 09b0688) Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent 606f056 commit 9cff86f

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
@@ -376,7 +376,13 @@ runs its charts in your management cluster: tap only sources you trust.`,
376376
if verr != nil {
377377
return verr
378378
}
379-
if ref.Digest == "" && verifiedDigest != "" {
379+
// Fail closed: a verified signature with no parseable digest must not
380+
// fall back to an unpinned tag pull, which would reopen the tag-mutation
381+
// window between verify and pull.
382+
if verifiedDigest == "" {
383+
return fmt.Errorf("cosign verified %q but returned no manifest digest; refusing to pull by an unpinned tag", ref.pullRef())
384+
}
385+
if ref.Digest == "" {
380386
ref.Digest = verifiedDigest
381387
}
382388
}

‎internal/operator/tapmaterializer_reconciler_test.go‎

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

0 commit comments

Comments
 (0)