Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sigstore dependencies #6

Merged
merged 6 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
210 changes: 80 additions & 130 deletions go.mod

Large diffs are not rendered by default.

1,249 changes: 202 additions & 1,047 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions hack/tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0

COSIGN := $(TOOLS_BIN_DIR)/cosign
COSIGN_VERSION ?= v1.12.1
COSIGN_VERSION ?= v2.0.2

export TOOLS_BIN_DIR := $(TOOLS_BIN_DIR)
export PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH)
Expand All @@ -21,4 +21,4 @@ tool_version_file = $(TOOLS_BIN_DIR)/.version_$(subst $(TOOLS_BIN_DIR)/,,$(1))_$
#########################################

$(COSIGN): $(call tool_version_file,$(COSIGN),$(COSIGN_VERSION))
GOBIN=$(abspath $(TOOLS_BIN_DIR)) go install github.com/sigstore/cosign/cmd/cosign@$(COSIGN_VERSION)
GOBIN=$(abspath $(TOOLS_BIN_DIR)) go install github.com/sigstore/cosign/v2/cmd/cosign@$(COSIGN_VERSION)
31 changes: 25 additions & 6 deletions pkg/lakom/verifysignature/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package verifysignature
import (
"context"
"crypto"
"errors"
"fmt"

"github.com/gardener/gardener-extension-shoot-lakom-service/pkg/constants"
Expand All @@ -16,8 +15,8 @@ import (

"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/sigstore/cosign/pkg/cosign"
ociremote "github.com/sigstore/cosign/pkg/oci/remote"
"github.com/sigstore/cosign/v2/pkg/cosign"
ociremote "github.com/sigstore/cosign/v2/pkg/oci/remote"
"github.com/sigstore/sigstore/pkg/signature"
"golang.org/x/sync/singleflight"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand Down Expand Up @@ -77,12 +76,20 @@ func verify(ctx context.Context, imageRef name.Reference, keys []crypto.PublicKe
RegistryClientOpts: opts,
SigVerifier: verifier,
ClaimVerifier: cosign.SimpleClaimVerifier,
IgnoreSCT: true,
IgnoreTlog: true,
vpnachev marked this conversation as resolved.
Show resolved Hide resolved
})
if err != nil {
if IsNoSignaturesFound(err) {
log.Info("no signatures found for the image", "error", err.Error())
vpnachev marked this conversation as resolved.
Show resolved Hide resolved
return false, nil
}

if IsNoMatchingSignature(err) {
log.Info("no matching signatures found for current public key", "error", err.Error())
continue
}

return false, err
}

Expand Down Expand Up @@ -145,8 +152,20 @@ func (r *cacheVerifier) Verify(ctx context.Context, image string, kcr utils.KeyC
return verified, nil
}

// IsNoMatchingSignature checks if error is of time github.com/sigstore/cosign/pkg/cosign.ErrNoMatchingSignatures.
// IsNoMatchingSignature checks if error is of time github.com/sigstore/cosign/pkg/cosign.ErrNoMatchingSignaturesType.
vpnachev marked this conversation as resolved.
Show resolved Hide resolved
func IsNoMatchingSignature(err error) bool {
target := cosign.ErrNoMatchingSignatures
return errors.As(err, &target)
noMatchingSignatureErr, ok := err.(*cosign.VerificationError)
if !ok {
return false
}
return noMatchingSignatureErr.ErrorType() == cosign.ErrNoMatchingSignaturesType
}

// IsNoSignaturesFound checks if error is of time github.com/sigstore/cosign/pkg/cosign.ErrNoSignaturesFoundType.
vpnachev marked this conversation as resolved.
Show resolved Hide resolved
func IsNoSignaturesFound(err error) bool {
noMatchingSignatureErr, ok := err.(*cosign.VerificationError)
if !ok {
return false
}
return noMatchingSignatureErr.ErrorType() == cosign.ErrNoSignaturesFoundType
}
23 changes: 19 additions & 4 deletions pkg/lakom/verifysignature/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package verifysignature_test
import (
"context"
"fmt"
"strings"
"time"

"github.com/gardener/gardener-extension-shoot-lakom-service/pkg/lakom/utils"
Expand All @@ -16,7 +15,9 @@ import (
"github.com/google/go-containerregistry/pkg/authn"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/sigstore/cosign/pkg/cosign"
"github.com/sigstore/cosign/v2/pkg/cosign"
logf "sigs.k8s.io/controller-runtime/pkg/log"
logzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
)

type anonymousKeyChain struct{}
Expand All @@ -37,7 +38,8 @@ var _ = Describe("Verifier", func() {
refresh = time.Millisecond * 100
ttl = time.Second
kcr = &anonymousKeyChainReader{}
ctx = context.TODO()
ctx context.Context
logger = logzap.New(logzap.WriteTo(GinkgoWriter), logzap.UseDevMode(true))

// source: https://github.com/sigstore/cosign/releases/download/v1.11.1/release-cosign.pub
cosignPublicKey = `-----BEGIN PUBLIC KEY-----
Expand All @@ -47,6 +49,10 @@ IqozONbbdbqz11hlRJy9c7SG+hdcFl9jE9uE/dwtuwU2MqU9T/cN0YkWww==
`
)

BeforeEach(func() {
ctx = logf.IntoContext(context.TODO(), logger)
})

Describe("Direct Verifier", func() {
var (
directVerifier verifysignature.Verifier
Expand Down Expand Up @@ -168,10 +174,19 @@ IqozONbbdbqz11hlRJy9c7SG+hdcFl9jE9uE/dwtuwU2MqU9T/cN0YkWww==
})

It("Should detect NoMatchingSignature error", func() {
noMathcingSignatureErr := fmt.Errorf("%w:\n%s", cosign.ErrNoMatchingSignatures, strings.Join([]string{"some error message"}, "\n "))
noMathcingSignatureErr := &cosign.VerificationError{}
noMathcingSignatureErr.SetErrorType(cosign.ErrNoMatchingSignaturesType)

Expect(verifysignature.IsNoMatchingSignature(noMathcingSignatureErr)).To(BeTrue())
Expect(verifysignature.IsNoMatchingSignature(fmt.Errorf("some other error"))).To(BeFalse())
})

It("Should detect NoSignaturesFoundType error", func() {
noSignatureFound := &cosign.VerificationError{}
noSignatureFound.SetErrorType(cosign.ErrNoSignaturesFoundType)

Expect(verifysignature.IsNoSignaturesFound(noSignatureFound)).To(BeTrue())
Expect(verifysignature.IsNoSignaturesFound(fmt.Errorf("some other error"))).To(BeFalse())
})

})
27 changes: 0 additions & 27 deletions vendor/bitbucket.org/creachadair/shell/LICENSE

This file was deleted.

7 changes: 0 additions & 7 deletions vendor/bitbucket.org/creachadair/shell/README.md

This file was deleted.

23 changes: 0 additions & 23 deletions vendor/bitbucket.org/creachadair/shell/bitbucket-pipelines.yml

This file was deleted.

Loading