Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 118 additions & 110 deletions go.mod

Large diffs are not rendered by default.

596 changes: 298 additions & 298 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/controller/helmchart_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/notaryproject/notation-go/verifier/trustpolicy"
"github.com/opencontainers/go-digest"
"github.com/sigstore/cosign/v2/pkg/cosign"
"github.com/sigstore/cosign/v3/pkg/cosign"
helmgetter "helm.sh/helm/v4/pkg/getter"
helmreg "helm.sh/helm/v4/pkg/registry"
helmrepo "helm.sh/helm/v4/pkg/repo/v1"
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/helmchart_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ import (
"github.com/notaryproject/notation-go/signer"
"github.com/notaryproject/notation-go/verifier/trustpolicy"
. "github.com/onsi/gomega"
coptions "github.com/sigstore/cosign/v2/cmd/cosign/cli/options"
"github.com/sigstore/cosign/v2/cmd/cosign/cli/sign"
"github.com/sigstore/cosign/v2/pkg/cosign"
coptions "github.com/sigstore/cosign/v3/cmd/cosign/cli/options"
"github.com/sigstore/cosign/v3/cmd/cosign/cli/sign"
"github.com/sigstore/cosign/v3/pkg/cosign"
hchart "helm.sh/helm/v4/pkg/chart/v2"
"helm.sh/helm/v4/pkg/chart/v2/loader"
helmreg "helm.sh/helm/v4/pkg/registry"
Expand Down Expand Up @@ -3468,7 +3468,7 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_verifySignatureCosign(t *tes
Timeout: timeout,
}

err = sign.SignCmd(ro, ko, coptions.SignOptions{
err = sign.SignCmd(ctx, ro, ko, coptions.SignOptions{
Upload: true,
SkipConfirmation: true,
TlogUpload: false,
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/ocirepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
gcrv1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/notaryproject/notation-go/verifier/trustpolicy"
"github.com/sigstore/cosign/v2/pkg/cosign"
"github.com/sigstore/cosign/v3/pkg/cosign"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/ocirepository_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ import (
"github.com/notaryproject/notation-go/verifier/trustpolicy"
. "github.com/onsi/gomega"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
coptions "github.com/sigstore/cosign/v2/cmd/cosign/cli/options"
"github.com/sigstore/cosign/v2/cmd/cosign/cli/sign"
"github.com/sigstore/cosign/v2/pkg/cosign"
coptions "github.com/sigstore/cosign/v3/cmd/cosign/cli/options"
"github.com/sigstore/cosign/v3/cmd/cosign/cli/sign"
"github.com/sigstore/cosign/v3/pkg/cosign"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -2211,7 +2211,7 @@ func TestOCIRepository_reconcileSource_verifyOCISourceSignatureCosign(t *testing
ro := &coptions.RootOptions{
Timeout: timeout,
}
err = sign.SignCmd(ro, ko, coptions.SignOptions{
err = sign.SignCmd(ctx, ro, ko, coptions.SignOptions{
Upload: true,
SkipConfirmation: true,
TlogUpload: false,
Expand Down
30 changes: 24 additions & 6 deletions internal/oci/cosign/cosign.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import (

"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/sigstore/cosign/v2/cmd/cosign/cli/fulcio"
coptions "github.com/sigstore/cosign/v2/cmd/cosign/cli/options"
"github.com/sigstore/cosign/v2/cmd/cosign/cli/rekor"
"github.com/sigstore/cosign/v2/pkg/cosign"
ociremote "github.com/sigstore/cosign/v2/pkg/oci/remote"
"github.com/sigstore/cosign/v3/cmd/cosign/cli/fulcio"
coptions "github.com/sigstore/cosign/v3/cmd/cosign/cli/options"
"github.com/sigstore/cosign/v3/cmd/cosign/cli/rekor"
"github.com/sigstore/cosign/v3/pkg/cosign"
"github.com/sigstore/cosign/v3/pkg/oci"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change

ociremote "github.com/sigstore/cosign/v3/pkg/oci/remote"
"github.com/sigstore/sigstore/pkg/cryptoutils"
"github.com/sigstore/sigstore/pkg/signature"

Expand Down Expand Up @@ -80,6 +82,7 @@ func NewCosignVerifier(ctx context.Context, opts ...Options) (*CosignVerifier, e
}

checkOpts := &cosign.CheckOpts{}
checkOpts.NewBundleFormat = true
Copy link
Member

@matheuscscp matheuscscp Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line seems unneeded since we're assigning the value of this field for each case inside Verify()?


ro := coptions.RegistryOptions{}
co, err := ro.ClientOpts(ctx)
Expand Down Expand Up @@ -146,10 +149,25 @@ func NewCosignVerifier(ctx context.Context, opts ...Options) (*CosignVerifier, e
}

// Verify verifies the authenticity of the given ref OCI image.
// Both cosign v2 signatures and cosign v3 bundles are supported by
// attempting to discover bundles before verification.
// Bundles can be located either via the OCI 1.1 referrer API or an
// OCI 1.0 referrer tag.
// It returns a boolean indicating if the verification was successful.
// It returns an error if the verification fails, nil otherwise.
func (v *CosignVerifier) Verify(ctx context.Context, ref name.Reference) (soci.VerificationResult, error) {
signatures, _, err := cosign.VerifyImageSignatures(ctx, ref, v.opts)
var signatures []oci.Signature
// copy options since we'll need to change them based on bundle discovery on the ref
opts := *v.opts
newBundles, _, err := cosign.GetBundles(ctx, ref, opts.RegistryClientOpts)
if len(newBundles) == 0 || err != nil {
opts.NewBundleFormat = false
signatures, _, err = cosign.VerifyImageSignatures(ctx, ref, &opts)
} else {
opts.NewBundleFormat = true
signatures, _, err = cosign.VerifyImageAttestations(ctx, ref, &opts)
}
fmt.Println(opts.NewBundleFormat, v.opts.NewBundleFormat)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

if err != nil {
return soci.VerificationResultFailed, err
}
Expand Down
69 changes: 68 additions & 1 deletion internal/oci/cosign/cosign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import (
"fmt"
"net/http"
"net/url"
"os"
"reflect"
"testing"

"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
. "github.com/onsi/gomega"
"github.com/sigstore/cosign/v2/pkg/cosign"
"github.com/sigstore/cosign/v3/pkg/cosign"

testproxy "github.com/fluxcd/source-controller/tests/proxy"
testregistry "github.com/fluxcd/source-controller/tests/registry"
Expand Down Expand Up @@ -191,3 +192,69 @@ func TestPrivateKeyVerificationWithProxy(t *testing.T) {
})
}
}

func TestPKBundleAttestations(t *testing.T) {
g := NewWithT(t)

// registryAddr := testregistry.New(t)

// proxyAddr, proxyPort := testproxy.New(t)

pubKey, err := os.ReadFile("/Users/stealthybox/hack/cosign/cosign.pub")
g.Expect(err).NotTo(HaveOccurred())

tests := []struct {
name string
tagURL string
}{
{
name: "v2",
tagURL: "localhost:5558/v2-zot",
},
{
name: "v2",
tagURL: "localhost:5559/v2-reg",
},
{
name: "v3 bundle oci 1.1 referrers",
tagURL: "localhost:5558/v3-bundle-zot",
},
{
name: "v3 bundle oci 1.0 fallback",
tagURL: "localhost:5559/v3-bundle-reg",
},
{
name: "v2-v3 bundle oci 1.1 referrers",
tagURL: "localhost:5558/v2-v3-bundle-zot",
},
{
name: "v2-v3 bundle oci 1.0 fallback",
tagURL: "localhost:5559/v2-v3-bundle-reg",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)

ctx := context.Background()

// tagURL := fmt.Sprintf(tag, registryAddr)
ref, err := name.ParseReference(tt.tagURL)
g.Expect(err).NotTo(HaveOccurred())

transport := http.DefaultTransport.(*http.Transport).Clone()
// transport.Proxy = http.ProxyURL(tt.proxyURL)

var opts []Options
opts = append(opts, WithRemoteOptions(remote.WithTransport(transport)))
opts = append(opts, WithPublicKey(pubKey))

verifier, err := NewCosignVerifier(ctx, opts...)
g.Expect(err).NotTo(HaveOccurred())

_, err = verifier.Verify(ctx, ref)
g.Expect(err).NotTo(HaveOccurred())
})
}
}
Loading