Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
add: acorn pull --verify -> do not pull image if signature verificati…
Browse files Browse the repository at this point in the history
…on failed

Signed-off-by: Thorsten Klein <[email protected]>
  • Loading branch information
iwilltry42 committed Jul 12, 2023
1 parent 4bdac8a commit 1177378
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 4 additions & 1 deletion docs/docs/100-reference/01-command-line/acorn_pull.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ acorn pull [flags] IMAGE
### Options

```
-h, --help help for pull
-a, --annotation strings Annotations to check for during verification
-h, --help help for pull
-k, --key string Key to use for verifying (default "./cosign.pub")
-v, --verify Verify the image signature BEFORE pulling and only pull on success
```

### Options inherited from parent commands
Expand Down
18 changes: 17 additions & 1 deletion pkg/cli/pull.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cli

import (
"fmt"

cli "github.com/acorn-io/runtime/pkg/cli/builder"
"github.com/acorn-io/runtime/pkg/client"
"github.com/acorn-io/runtime/pkg/config"
Expand All @@ -20,7 +22,10 @@ func NewPull(c CommandContext) *cobra.Command {
}

type Pull struct {
client ClientFactory
client ClientFactory
Verify bool `usage:"Verify the image signature BEFORE pulling and only pull on success" short:"v" local:"true" default:"false"`
Key string `usage:"Key to use for verifying" short:"k" local:"true" default:"./cosign.pub"`
Annotations map[string]string `usage:"Annotations to check for during verification" short:"a" local:"true" name:"annotation"`
}

func (s *Pull) Run(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -49,6 +54,17 @@ func (s *Pull) Run(cmd *cobra.Command, args []string) error {
return err
}

if s.Verify {
v := ImageVerify{
client: s.client,
Key: s.Key,
Annotations: s.Annotations,
}
if err := v.Run(cmd, args); err != nil {
return fmt.Errorf("NOT pulling image: %w", err)
}
}

progress, err := c.ImagePull(cmd.Context(), args[0], &client.ImagePullOptions{
Auth: auth,
})
Expand Down

0 comments on commit 1177378

Please sign in to comment.