Skip to content

Commit

Permalink
Pass a nop verifier to dupe detection (#81)
Browse files Browse the repository at this point in the history
I believe the dupe detector takes a verifier so that it only replaces
attestations that match a verifier. The verifier we pass into Attest is
ephemeral and probably not what the dupe detector really wants. For
attestations that fail to verify, the dupe detector just ignores the
error and continues.

For our use case, we always want to replace by predicate type and don't
care about keeping around multiple identities/verifiers. We _want_ to
clobber whatever was there before and update it with the most recent
identity.

Signed-off-by: Jon Johnson <jon.johnson@chainguard.dev>
  • Loading branch information
jonjohnsonjr authored Oct 9, 2023
1 parent 89876bd commit 826412b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion internal/secant/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package secant
import (
"bytes"
"context"
"crypto"
"encoding/base64"
"encoding/json"
"fmt"
Expand All @@ -25,6 +26,7 @@ import (
ctypes "github.com/sigstore/cosign/v2/pkg/types"
"github.com/sigstore/rekor/pkg/generated/client"
"github.com/sigstore/sigstore/pkg/cryptoutils"
"github.com/sigstore/sigstore/pkg/signature"
"github.com/sigstore/sigstore/pkg/signature/options"
)

Expand Down Expand Up @@ -66,6 +68,10 @@ func Attest(ctx context.Context, statements []*types.Statement, sv types.Cosigne
// so we use a placeholder here.
se := ociremote.SignedUnknown(digest)

// We use a dupe detector that always verifies because we always want to replace
// things with a matching predicate type.
dd := cremote.NewDupeDetector(&alwaysVerifier{})

for _, statement := range statements {
// Make sure these statements are all for the same subject.
if digest != statement.Digest {
Expand Down Expand Up @@ -151,7 +157,7 @@ func Attest(ctx context.Context, statements []*types.Statement, sv types.Cosigne
}

signOpts := []mutate.SignOption{
mutate.WithDupeDetector(cremote.NewDupeDetector(sv)),
mutate.WithDupeDetector(dd),
mutate.WithReplaceOp(cremote.NewReplaceOp(predicateType)),
}

Expand Down Expand Up @@ -187,3 +193,15 @@ func parsePredicateType(t string) (string, error) {
}
return uri, nil
}

type alwaysVerifier struct{}

// This only exists to satisfy cosign interface jungle.
func (av *alwaysVerifier) PublicKey(opts ...signature.PublicKeyOption) (crypto.PublicKey, error) {
panic("this should not get called ever")
}

// This always verifies.
func (av *alwaysVerifier) VerifySignature(signature, message io.Reader, opts ...signature.VerifyOption) error {
return nil
}

0 comments on commit 826412b

Please sign in to comment.