fixes and logging for cosign verify <iamge>

Signed-off-by: Adam Martin <adam.martin@rancherfederal.com>
This commit is contained in:
Adam Martin
2023-10-11 13:44:21 -04:00
parent 96d92e3248
commit bb9a088a84
3 changed files with 9 additions and 8 deletions
+3 -1
View File
@@ -71,6 +71,7 @@ func (o *AddImageOpts) AddFlags(cmd *cobra.Command) {
}
func AddImageCmd(ctx context.Context, o *AddImageOpts, s *store.Layout, reference string) error {
l := log.FromContext(ctx)
cfg := v1alpha1.Image{
Name: reference,
}
@@ -78,10 +79,11 @@ func AddImageCmd(ctx context.Context, o *AddImageOpts, s *store.Layout, referenc
// Check if the user provided a key.
if o.Key != "" {
// verify signature using the provided key.
err := cosign.VerifySignature(ctx, s, o.Key)
err := cosign.VerifySignature(ctx, s, o.Key, cfg.Name)
if err != nil {
return err
}
l.Infof("Signature verified for image [%s]", cfg.Name)
}
return storeImage(ctx, s, cfg)
+2 -1
View File
@@ -101,10 +101,11 @@ func SyncCmd(ctx context.Context, o *SyncOpts, s *store.Layout) error {
// Check if the user provided a key.
if o.Key != "" {
// verify signature using the provided key.
err := cosign.VerifySignature(ctx, s, o.Key)
err := cosign.VerifySignature(ctx, s, o.Key, i.Name)
if err != nil {
return err
}
l.Infof("Signature verified for image [%s]", cfg.Name)
}
err = storeImage(ctx, s, i)
+4 -6
View File
@@ -25,7 +25,7 @@ import (
)
// VerifyFileSignature verifies the digital signature of a file using Sigstore/Cosign.
func VerifySignature(ctx context.Context, s *store.Layout, keyPath string) error {
func VerifySignature(ctx context.Context, s *store.Layout, keyPath string, ref string) error {
// Ensure that the cosign binary is installed or download it if needed
cosignBinaryPath, err := ensureCosignBinary(ctx, s)
@@ -34,7 +34,7 @@ func VerifySignature(ctx context.Context, s *store.Layout, keyPath string) error
}
// Command to verify the signature using Cosign.
cmd := exec.Command(cosignBinaryPath, "verify", "--insecure-ignore-tlog", "--key", keyPath, s.Root)
cmd := exec.Command(cosignBinaryPath, "verify", "--insecure-ignore-tlog", "--key", keyPath, ref)
// Run the command and capture its output.
output, err := cmd.CombinedOutput()
@@ -53,10 +53,9 @@ func SaveImage(ctx context.Context, s *store.Layout, ref string) error {
if err != nil {
return err
}
println(cosignBinaryPath)
// Command to verify the signature using Cosign.
cmd := exec.Command("/Users/amartin/go/bin/cosign", "save", ref, "--dir", s.Root)
cmd := exec.Command(cosignBinaryPath, "save", ref, "--dir", s.Root)
// Run the command and capture its output.
output, err := cmd.CombinedOutput()
@@ -75,10 +74,9 @@ func LoadImage(ctx context.Context, s *store.Layout, registry string, ropts cont
if err != nil {
return err
}
println(cosignBinaryPath)
// Command to verify the signature using Cosign.
cmd := exec.Command("/Users/amartin/go/bin/cosign", "load", "--registry", registry, "--dir", s.Root)
cmd := exec.Command(cosignBinaryPath, "load", "--registry", registry, "--dir", s.Root)
// Conditionally add extra registry flags.
if ropts.Insecure {