fix(marketplace): reject a non-cosign verify provider at connect

TapVerify advertised provider notation, but buildVerifySpec always emits a
matchOIDCIdentity block, which is meaningful only for keyless cosign. Setting
provider: notation produced a nonsensical verify block. The connect now rejects
any provider other than cosign and the type doc no longer advertises notation,
since only keyless cosign identity matching is settable here.

Assisted-by: LLM
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
(cherry picked from commit 10be3d2770)
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
IvanHunters authored and Myasnikov Daniil committed 2026-11-10 12:52:20 +00:00
1 parent f49979a01e
commit 56be1644b7
4 files changed
+25 -7

No files matched your search

+3 -1
View File
@@ -63,7 +63,9 @@ type TapSpec struct {
// (issuer + subject) is the supported form, so a moved tag cannot be followed
// unless it is also signed by the recorded identity.
type TapVerify struct {
// Provider is the signature technology: "cosign" (default) or "notation".
// Provider is the signature technology. Only keyless cosign (the default) is
// settable at connect, since the identity match below is a cosign construct;
// a non-cosign value is rejected.
Provider string `json:"provider,omitempty"`
// Issuer is the OIDC issuer URL for keyless cosign verification, e.g.
// https://token.actions.githubusercontent.com.
@@ -739,7 +739,7 @@ func schema_pkg_apis_core_v1alpha1_TapVerify(ref common.ReferenceCallback) commo
Properties: map[string]spec.Schema{
"provider": {
SchemaProps: spec.SchemaProps{
Description: "Provider is the signature technology: \"cosign\" (default) or \"notation\".",
Description: "Provider is the signature technology. Only keyless cosign (the default) is settable at connect, since the identity match below is a cosign construct; a non-cosign value is rejected.",
Type: []string{"string"},
Format: "",
},
+6 -5
View File
@@ -93,15 +93,16 @@ func parseConnectURL(url, tagOverride string) (connectTarget, error) {
// signer would be worse than none. A key-based policy an admin sets by hand on
// the source is preserved across connects (see Create) but is not settable here.
func buildVerifySpec(v *corev1alpha1.TapVerify) (map[string]any, error) {
// Only keyless cosign is settable here; matchOIDCIdentity is a cosign-only
// construct, so a non-cosign provider would produce a nonsensical policy.
if v.Provider != "" && v.Provider != "cosign" {
return nil, fmt.Errorf("verify.provider %q is not supported; only keyless cosign identity matching is settable at connect", v.Provider)
}
if v.Issuer == "" || v.Subject == "" {
return nil, fmt.Errorf("verify requires both issuer and subject (keyless cosign identity)")
}
provider := v.Provider
if provider == "" {
provider = "cosign"
}
return map[string]any{
"provider": provider,
"provider": "cosign",
"matchOIDCIdentity": []any{map[string]any{"issuer": v.Issuer, "subject": v.Subject}},
}, nil
}
+15
View File
@@ -416,6 +416,21 @@ func TestCreateVerifyRequiresBothIdentityFields(t *testing.T) {
}
}
func TestCreateVerifyRejectsNonCosignProvider(t *testing.T) {
r := fakeREST()
in := &corev1alpha1.Tap{Spec: corev1alpha1.TapSpec{
URL: "oci://ghcr.io/foo/bar:v1",
Verify: &corev1alpha1.TapVerify{
Provider: "notation",
Issuer: "https://token.actions.githubusercontent.com",
Subject: "https://github.com/org/repo/.github/workflows/release.yml@refs/tags/v1",
},
}}
if _, err := r.Create(context.Background(), in, nil, nil); !apierrors.IsBadRequest(err) {
t.Errorf("a non-cosign provider must be BadRequest (matchOIDCIdentity is cosign-only), got %v", err)
}
}
func TestCreateRefusesConflictingURL(t *testing.T) {
// A source with the same derived name but a different registry host must not
// be silently retargeted.