feat(marketplace): accept a signature-verification policy at tap connect

A tap can now carry a keyless cosign verification policy (spec.verify), so a
reference is only pulled when signed by the recorded identity. The CLI takes
--certificate-identity and --certificate-oidc-issuer (both required together,
mirroring validate); the API takes spec.verify.{issuer,subject} on the Tap
connect object. Both map to a Flux OCIRepository verify block with provider
cosign and a matchOIDCIdentity entry. A half-configured policy (only one of
the identity pair) is refused rather than set, since a policy that matched any
signer is worse than none. A key-based policy an admin sets on the source by
hand is preserved across repeat connects.

Assisted-by: LLM
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
(cherry picked from commit c56b9876f4)
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
IvanHunters authored and Myasnikov Daniil committed 2026-11-10 12:51:40 +00:00
1 parent b326e0badd
commit 9fb9ae4000
7 files changed
+177 -6

No files matched your search

+19
View File
@@ -52,6 +52,25 @@ type TapSpec struct {
// Secret in cozy-system for a private repository. It is consumed when a Tap
// is created and, being a credential reference, is never returned on read.
SecretRef string `json:"secretRef,omitempty"`
// Verify is a connect-time input only: a signature-verification policy to
// set on the tap's Flux source (spec.verify). It is consumed when a Tap is
// created, preserved across repeat connects, and never returned on read.
Verify *TapVerify `json:"verify,omitempty"`
}
// TapVerify is a connect-time signature-verification policy for a tap. It maps
// to the Flux OCIRepository spec.verify: keyless cosign identity matching
// (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 string `json:"provider,omitempty"`
// Issuer is the OIDC issuer URL for keyless cosign verification, e.g.
// https://token.actions.githubusercontent.com.
Issuer string `json:"issuer,omitempty"`
// Subject is the certificate identity (subject) for keyless cosign
// verification; it is matched against the artifact's signing identity.
Subject string `json:"subject,omitempty"`
}
// TapSource identifies the Flux source backing a tap. It carries no credential.
@@ -231,6 +231,11 @@ func (in *TapSpec) DeepCopyInto(out *TapSpec) {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.Verify != nil {
in, out := &in.Verify, &out.Verify
*out = new(TapVerify)
**out = **in
}
return
}
@@ -244,6 +249,22 @@ func (in *TapSpec) DeepCopy() *TapSpec {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *TapVerify) DeepCopyInto(out *TapVerify) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TapVerify.
func (in *TapVerify) DeepCopy() *TapVerify {
if in == nil {
return nil
}
out := new(TapVerify)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *TenantModule) DeepCopyInto(out *TenantModule) {
*out = *in
+19
View File
@@ -87,6 +87,25 @@ func parseConnectURL(url, tagOverride string) (connectTarget, error) {
return t, nil
}
// buildVerifySpec maps a connect-time TapVerify input to a Flux OCIRepository
// spec.verify. Only keyless cosign identity matching is exposed, so both the
// issuer and the subject are required: a verification policy that matched any
// 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) {
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,
"matchOIDCIdentity": []any{map[string]any{"issuer": v.Issuer, "subject": v.Subject}},
}, nil
}
var (
gvrPackageSources = schema.GroupVersionResource{Group: "cozystack.io", Version: "v1alpha1", Resource: "packagesources"}
gvrPackages = schema.GroupVersionResource{Group: "cozystack.io", Version: "v1alpha1", Resource: "packages"}
+7
View File
@@ -244,6 +244,13 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation
if in.Spec.SecretRef != "" {
_ = unstructured.SetNestedMap(repo.Object, map[string]any{"name": in.Spec.SecretRef}, "spec", "secretRef")
}
if in.Spec.Verify != nil {
verifySpec, err := buildVerifySpec(in.Spec.Verify)
if err != nil {
return nil, apierrors.NewBadRequest(err.Error())
}
_ = unstructured.SetNestedMap(repo.Object, verifySpec, "spec", "verify")
}
// Create the Flux source, idempotently: a repeat connect updates the
// existing source (new tag/secret) rather than erroring.
+40
View File
@@ -376,6 +376,46 @@ func TestCreateRepeatPreservesVerifyAndResetsPin(t *testing.T) {
}
}
func TestCreateSetsVerify(t *testing.T) {
r := fakeREST()
in := &corev1alpha1.Tap{Spec: corev1alpha1.TapSpec{
URL: "oci://ghcr.io/foo/bar:v1",
Verify: &corev1alpha1.TapVerify{
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); err != nil {
t.Fatalf("create: %v", err)
}
u, err := r.dyn.Resource(gvrOCIRepos).Namespace("cozy-system").Get(context.Background(), "tap-foo-bar", metav1.GetOptions{})
if err != nil {
t.Fatal(err)
}
if prov, _, _ := unstructured.NestedString(u.Object, "spec", "verify", "provider"); prov != "cosign" {
t.Errorf("verify.provider = %q, want cosign", prov)
}
ids, _, _ := unstructured.NestedSlice(u.Object, "spec", "verify", "matchOIDCIdentity")
if len(ids) != 1 {
t.Fatalf("expected one matchOIDCIdentity, got %v", ids)
}
id := ids[0].(map[string]any)
if id["issuer"] != "https://token.actions.githubusercontent.com" || id["subject"] == "" {
t.Errorf("unexpected identity matcher: %v", id)
}
}
func TestCreateVerifyRequiresBothIdentityFields(t *testing.T) {
r := fakeREST()
in := &corev1alpha1.Tap{Spec: corev1alpha1.TapSpec{
URL: "oci://ghcr.io/foo/bar:v1",
Verify: &corev1alpha1.TapVerify{Issuer: "https://token.actions.githubusercontent.com"},
}}
if _, err := r.Create(context.Background(), in, nil, nil); !apierrors.IsBadRequest(err) {
t.Errorf("a keyless verify with only an issuer must be BadRequest, 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.