Skip to content

Commit f8e3b0d

Browse files
committed
fix(marketplace): preserve the pull secret on API repeat connect
The repeat-connect merge preserved spec.verify but still dropped spec.secretRef when the connect omitted a secret, breaking a private tap on a pin move. It now preserves an existing secretRef the same way, so the API and CLI connect paths are symmetric: a repeat connect overrides verify and the secret only when it carries its own, and never silently drops either. Assisted-by: LLM Signed-off-by: IvanHunters <[email protected]>
1 parent 10be3d2 commit f8e3b0d

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎pkg/registry/core/tap/rest.go‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,21 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation
272272
fmt.Errorf("a different repository (%s) is already connected as %q; disconnect it before connecting %s", curURL, target.FluxSourceName, target.URL))
273273
}
274274
// Update the fields this API owns on the FETCHED object, so the operator's
275-
// finalizer survives. Replace url, interval, ref and secretRef from this
276-
// connect, but PRESERVE a spec.verify set earlier (by this API or by an
277-
// admin): a repeat connect must never silently drop a signature-verification
278-
// policy. Replacing the whole ref rather than merging it is deliberate: it
279-
// drops the operator's prior digest pin so the newly requested tag re-
280-
// resolves (the operator re-pins it). A connect that itself carries verify
275+
// finalizer survives. Replace url, interval and ref from this connect, but
276+
// PRESERVE a spec.verify or spec.secretRef set earlier (by this API or by
277+
// an admin) when this connect does not carry its own: a repeat connect must
278+
// never silently drop a signature-verification policy or a pull credential.
279+
// Replacing the whole ref rather than merging it is deliberate: it drops the
280+
// operator's prior digest pin so the newly requested tag re-resolves (the
281+
// operator re-pins it). A connect that itself carries verify or a secret
281282
// overrides the preserved one.
282283
newSpec := map[string]any{}
283284
if existingVerify, ok, _ := unstructured.NestedMap(cur.Object, "spec", "verify"); ok {
284285
newSpec["verify"] = existingVerify
285286
}
287+
if existingSecret, ok, _ := unstructured.NestedMap(cur.Object, "spec", "secretRef"); ok {
288+
newSpec["secretRef"] = existingSecret
289+
}
286290
for k, v := range repo.Object["spec"].(map[string]any) {
287291
newSpec[k] = v
288292
}

‎pkg/registry/core/tap/rest_test.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ func TestCreateRepeatPreservesVerifyAndResetsPin(t *testing.T) {
344344
"provider": "cosign",
345345
"matchOIDCIdentity": []any{map[string]any{"issuer": "https://token.actions.githubusercontent.com", "subject": "https://github.com/org/repo/.github/workflows/release.yml@refs/tags/v1"}},
346346
}, "spec", "verify")
347+
_ = unstructured.SetNestedMap(existing.Object, map[string]any{"name": "pull-creds"}, "spec", "secretRef")
347348
existing.SetFinalizers([]string{"apps.cozystack.io/tap-materializer"})
348349
existing.SetAnnotations(map[string]string{
349350
"apps.cozystack.io/materialized-revision": "v1@" + oldDigest,
@@ -362,6 +363,9 @@ func TestCreateRepeatPreservesVerifyAndResetsPin(t *testing.T) {
362363
if prov, _, _ := unstructured.NestedString(u.Object, "spec", "verify", "provider"); prov != "cosign" {
363364
t.Errorf("spec.verify was dropped on repeat connect: %+v", u.Object["spec"])
364365
}
366+
if name, _, _ := unstructured.NestedString(u.Object, "spec", "secretRef", "name"); name != "pull-creds" {
367+
t.Errorf("spec.secretRef must be preserved on a repeat connect that omits a secret, got %q", name)
368+
}
365369
if tag, _, _ := unstructured.NestedString(u.Object, "spec", "ref", "tag"); tag != "v2" {
366370
t.Errorf("tag not updated to v2, got %q", tag)
367371
}

0 commit comments

Comments
 (0)