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 <xorokhotnikov@gmail.com>
(cherry picked from commit 09b0688abd)
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
IvanHunters authored and Myasnikov Daniil committed 2026-11-10 12:52:38 +00:00
1 parent 606f056b65
commit 9cff86f851
2 files changed
+50 -1

No files matched your search

+7 -1
View File
@@ -376,7 +376,13 @@ runs its charts in your management cluster: tap only sources you trust.`,
if verr != nil {
return verr
}
if ref.Digest == "" && verifiedDigest != "" {
// Fail closed: a verified signature with no parseable digest must not
// fall back to an unpinned tag pull, which would reopen the tag-mutation
// window between verify and pull.
if verifiedDigest == "" {
return fmt.Errorf("cosign verified %q but returned no manifest digest; refusing to pull by an unpinned tag", ref.pullRef())
}
if ref.Digest == "" {
ref.Digest = verifiedDigest
}
}
@@ -710,3 +710,46 @@ func TestReconcilePinsPreUpgradeTapBeforeEarlyReturn(t *testing.T) {
t.Errorf("expected pinned-digest annotation %q, got %v", manifest, got.Annotations)
}
}
// artifactReady must also wait when status.observedGeneration lags
// metadata.generation: the artifact may still describe the spec from before the
// current re-connect, so pinning from it would pin stale content even when the
// revision happens to match the tag. This isolates the generation conjunct of the
// gate (the revision here matches the tag, so only the generation check can block).
func TestReconcileWaitsWhenObservedGenerationLags(t *testing.T) {
scheme := tapScheme(t)
data, digest := tarGz(t, map[string]string{"packages/core/platform/sources/hello.yaml": samplePS})
manifest := "sha256:" + strings.Repeat("d", 64)
repo := tapRepo(true)
repo.Generation = 2 // spec advanced by a re-connect
repo.Spec.Reference = &sourcev1.OCIRepositoryRef{Tag: "v1"}
cl := fake.NewClientBuilder().WithScheme(scheme).
WithObjects(repo).
WithStatusSubresource(&sourcev1.OCIRepository{}).
Build()
var live sourcev1.OCIRepository
if err := cl.Get(context.Background(), req().NamespacedName, &live); err != nil {
t.Fatal(err)
}
live.Status.Artifact = &fluxmeta.Artifact{URL: "http://example.com/a.tar.gz", Digest: digest, Revision: "v1@" + manifest}
live.Status.ObservedGeneration = 1 // source-controller has not caught up to generation 2
if err := cl.Status().Update(context.Background(), &live); err != nil {
t.Fatal(err)
}
r := materializerFor(scheme, cl, record.NewFakeRecorder(10), &data)
if _, err := r.Reconcile(context.Background(), req()); err != nil {
t.Fatalf("reconcile: %v", err)
}
var got sourcev1.OCIRepository
if err := cl.Get(context.Background(), req().NamespacedName, &got); err != nil {
t.Fatal(err)
}
if got.Spec.Reference.Digest != "" {
t.Errorf("must not pin while observedGeneration lags generation, got %q", got.Spec.Reference.Digest)
}
if got.Annotations[tapconst.PinnedDigestAnnotation] != "" {
t.Errorf("must not record a pin while observedGeneration lags, got %v", got.Annotations)
}
}