diff --git a/pkg/apis/core/v1alpha1/tap_types.go b/pkg/apis/core/v1alpha1/tap_types.go index 076925271..42181715a 100644 --- a/pkg/apis/core/v1alpha1/tap_types.go +++ b/pkg/apis/core/v1alpha1/tap_types.go @@ -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. diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index e34c63d72..68bb1713f 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -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: "", }, diff --git a/pkg/registry/core/tap/compute.go b/pkg/registry/core/tap/compute.go index af25ab1da..25f567a0a 100644 --- a/pkg/registry/core/tap/compute.go +++ b/pkg/registry/core/tap/compute.go @@ -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 } diff --git a/pkg/registry/core/tap/rest_test.go b/pkg/registry/core/tap/rest_test.go index 9525de1d6..406a7fb68 100644 --- a/pkg/registry/core/tap/rest_test.go +++ b/pkg/registry/core/tap/rest_test.go @@ -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.