-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These commands allow users to store an image with associated signatures to disk (cosign save) and then take them from disk and load them into a remote registry (cosign load). Currently this only works with signatures, support for attestations and attachments still needs to be added. Right now, the image index is only used as an implementation details. Future work should allow saving and loading the entire image index, including the `index.json`. Signed-off-by: Priya Wadhwa <priyawadhwa@google.com>
- Loading branch information
priyawadhwa
authored
Nov 22, 2021
1 parent
e1141af
commit 7ec91a4
Showing
10 changed files
with
321 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// Copyright 2021 The Sigstore Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cli | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/google/go-containerregistry/pkg/name" | ||
"github.com/pkg/errors" | ||
"github.com/sigstore/cosign/cmd/cosign/cli/options" | ||
"github.com/sigstore/cosign/pkg/oci/layout" | ||
"github.com/sigstore/cosign/pkg/oci/remote" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func Load() *cobra.Command { | ||
o := &options.LoadOptions{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "load", | ||
Short: "Load a signed image on disk to a remote registry", | ||
Long: "Load a signed image on disk to a remote registry", | ||
Example: ` cosign load --dir <path to directory> <IMAGE>`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return LoadCmd(cmd.Context(), *o, args[0]) | ||
}, | ||
} | ||
|
||
o.AddFlags(cmd) | ||
return cmd | ||
} | ||
|
||
func LoadCmd(ctx context.Context, opts options.LoadOptions, imageRef string) error { | ||
ref, err := name.ParseReference(imageRef) | ||
if err != nil { | ||
return errors.Wrapf(err, "parsing image name %s", imageRef) | ||
} | ||
|
||
// get the signed image from disk | ||
sii, err := layout.SignedImageIndex(opts.Directory) | ||
if err != nil { | ||
return errors.Wrap(err, "signed image index") | ||
} | ||
return remote.WriteSignedImageIndexImages(ref, sii) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Copyright 2021 The Sigstore Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package options | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// LoadOptions is the top level wrapper for the load command. | ||
type LoadOptions struct { | ||
Directory string | ||
} | ||
|
||
var _ Interface = (*LoadOptions)(nil) | ||
|
||
// AddFlags implements Interface | ||
func (o *LoadOptions) AddFlags(cmd *cobra.Command) { | ||
cmd.Flags().StringVar(&o.Directory, "dir", "", | ||
"path to directory where the signed image is stored on disk") | ||
_ = cmd.MarkFlagRequired("dir") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Copyright 2021 The Sigstore Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package options | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// SaveOptions is the top level wrapper for the load command. | ||
type SaveOptions struct { | ||
Directory string | ||
} | ||
|
||
var _ Interface = (*SaveOptions)(nil) | ||
|
||
// AddFlags implements Interface | ||
func (o *SaveOptions) AddFlags(cmd *cobra.Command) { | ||
cmd.Flags().StringVar(&o.Directory, "dir", "", | ||
"path to dir where the signed image should be stored on disk") | ||
_ = cmd.MarkFlagRequired("dir") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// Copyright 2021 The Sigstore Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cli | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/google/go-containerregistry/pkg/name" | ||
"github.com/pkg/errors" | ||
"github.com/sigstore/cosign/cmd/cosign/cli/options" | ||
"github.com/sigstore/cosign/pkg/oci/layout" | ||
ociremote "github.com/sigstore/cosign/pkg/oci/remote" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func Save() *cobra.Command { | ||
o := &options.SaveOptions{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "save", | ||
Short: "Save the container image and associated signatures to disk at the specified directory.", | ||
Long: "Save the container image and associated signatures to disk at the specified directory.", | ||
Example: ` cosign save --dir <path to directory> <IMAGE>`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return SaveCmd(cmd.Context(), *o, args[0]) | ||
}, | ||
} | ||
|
||
o.AddFlags(cmd) | ||
return cmd | ||
} | ||
|
||
func SaveCmd(ctx context.Context, opts options.SaveOptions, imageRef string) error { | ||
ref, err := name.ParseReference(imageRef) | ||
if err != nil { | ||
return errors.Wrapf(err, "parsing image name %s", imageRef) | ||
} | ||
si, err := ociremote.SignedImage(ref) | ||
if err != nil { | ||
return errors.Wrap(err, "getting signed image") | ||
} | ||
return layout.WriteSignedImage(opts.Directory, si) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters