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

Switch attach to new library. #774

Merged
merged 1 commit into from
Sep 24, 2021
Merged
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
15 changes: 7 additions & 8 deletions cmd/cosign/cli/attach/sig.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package attach

import (
"context"
"encoding/base64"
"errors"
"flag"
"io/ioutil"
Expand All @@ -28,7 +27,7 @@ import (
"github.com/peterbourgon/ff/v3/ffcli"

"github.com/sigstore/cosign/cmd/cosign/cli/options"
cremote "github.com/sigstore/cosign/pkg/cosign/remote"
"github.com/sigstore/cosign/pkg/oci/mutate"
ociremote "github.com/sigstore/cosign/pkg/oci/remote"
"github.com/sigstore/cosign/pkg/oci/static"
sigPayload "github.com/sigstore/sigstore/pkg/signature/payload"
Expand Down Expand Up @@ -69,7 +68,6 @@ func SignatureCmd(ctx context.Context, regOpts options.RegistryOpts, sigRef, pay
if err != nil {
return err
}

digest, err := ociremote.ResolveDigest(ref, regOpts.ClientOpts(ctx)...)
if err != nil {
return err
Expand All @@ -85,23 +83,24 @@ func SignatureCmd(ctx context.Context, regOpts options.RegistryOpts, sigRef, pay
return err
}

// This expects it to not be base64 encoded, so decode first
sigBytes, err := base64.StdEncoding.DecodeString(string(b64SigBytes))
sig, err := static.NewSignature(payload, string(b64SigBytes))
if err != nil {
return err
}

dstRef, err := ociremote.SignatureTag(digest, regOpts.ClientOpts(ctx)...)
se, err := ociremote.SignedEntity(digest, regOpts.ClientOpts(ctx)...)
if err != nil {
return err
}

sig, err := static.NewSignature(payload, base64.StdEncoding.EncodeToString(sigBytes))
// Attach the signature to the entity.
newSE, err := mutate.AttachSignatureToEntity(se, sig)
if err != nil {
return err
}

return cremote.UploadSignature(sig, dstRef, cremote.UploadOpts{RegistryClientOpts: regOpts.GetRegistryClientOpts(ctx)})
// Publish the signatures associated with this entity
return ociremote.WriteSignatures(digest.Repository, newSE, regOpts.ClientOpts(ctx)...)
}

type SignatureArgType uint8
Expand Down
29 changes: 0 additions & 29 deletions pkg/cosign/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ import (
"bytes"
"encoding/base64"

"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"

"github.com/sigstore/cosign/pkg/oci"
"github.com/sigstore/cosign/pkg/oci/mutate"
ociremote "github.com/sigstore/cosign/pkg/oci/remote"
"github.com/sigstore/cosign/pkg/oci/static"
"github.com/sigstore/sigstore/pkg/signature"
)
Expand Down Expand Up @@ -101,28 +97,3 @@ LayerLoop:
}
return nil, nil
}

type UploadOpts struct {
DupeDetector mutate.DupeDetector
RegistryClientOpts []remote.Option
}

func UploadSignature(l oci.Signature, dst name.Reference, opts UploadOpts) error {
base, err := ociremote.Signatures(dst, ociremote.WithRemoteOptions(opts.RegistryClientOpts...))
if err != nil {
return err
}

if opts.DupeDetector != nil {
if existing, err := opts.DupeDetector.Find(base, l); err != nil || existing != nil {
return err
}
}

sigs, err := mutate.AppendSignatures(base, l)
if err != nil {
return err
}

return remote.Write(dst, sigs, opts.RegistryClientOpts...)
}