Skip to content

Commit 981b6d0

Browse files
author
Radu M
authored
Merge pull request #1 from radu-matei/signy
WIP Notary integration
2 parents 37554a4 + df4c2da commit 981b6d0

File tree

253 files changed

+33381
-1635
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

253 files changed

+33381
-1635
lines changed

Gopkg.lock

Lines changed: 92 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,3 @@
1-
# Gopkg.toml example
2-
#
3-
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
4-
# for detailed Gopkg.toml documentation.
5-
#
6-
# required = ["github.com/user/thing/cmd/thing"]
7-
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8-
#
9-
# [[constraint]]
10-
# name = "github.com/user/project"
11-
# version = "1.0.0"
12-
#
13-
# [[constraint]]
14-
# name = "github.com/user/project2"
15-
# branch = "dev"
16-
# source = "github.com/myfork/project2"
17-
#
18-
# [[override]]
19-
# name = "github.com/x/y"
20-
# version = "2.4.0"
21-
#
22-
# [prune]
23-
# non-go = false
24-
# go-tests = true
25-
# unused-packages = true
26-
27-
281
[[constraint]]
292
name = "github.com/deislabs/oras"
303
version = "0.6.0"
@@ -33,6 +6,14 @@
336
name = "github.com/docker/docker"
347
revision = "8a43b7bb99cd1eedc3aca61fbc3ccfba6b75c209"
358

9+
[[constraint]]
10+
name = "github.com/containerd/containerd"
11+
revision = "894b81a4b802e4eb2a91d1ce216b8817763c29fb"
12+
13+
[[override]]
14+
name = "github.com/containerd/containerd"
15+
revision = "894b81a4b802e4eb2a91d1ce216b8817763c29fb"
16+
3617
[prune]
3718
go-tests = true
3819
unused-packages = true

cmd/main.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,53 @@ package main
22

33
import (
44
"os"
5+
"path/filepath"
6+
"runtime"
57

8+
log "github.com/sirupsen/logrus"
69
"github.com/spf13/cobra"
10+
11+
"github.com/engineerd/wasm-to-oci/pkg/tuf"
12+
)
13+
14+
var (
15+
trustServer string
16+
tlscacert string
17+
trustDir string
18+
logLevel string
19+
timeout string
720
)
821

922
func main() {
1023
cmd := &cobra.Command{
1124
Use: "wasm-to-oci <subcommand> [options]",
25+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
26+
l, err := log.ParseLevel(logLevel)
27+
if err != nil {
28+
return err
29+
}
30+
log.SetLevel(l)
31+
return nil
32+
},
1233
}
1334

35+
cmd.PersistentFlags().StringVarP(&trustServer, "server", "", tuf.DockerNotaryServer, "The trust server used")
36+
cmd.PersistentFlags().StringVarP(&tlscacert, "tlscacert", "", "", "Trust certs signed only by this CA")
37+
cmd.PersistentFlags().StringVarP(&trustDir, "dir", "d", defaultTrustDir(), "Directory where the trust data is persisted to")
38+
cmd.PersistentFlags().StringVar(&logLevel, "log", "info", `Set the logging level ("debug"|"info"|"warn"|"error"|"fatal")`)
39+
cmd.PersistentFlags().StringVarP(&timeout, "timeout", "t", "5s", `Timeout for the trust server`)
40+
1441
cmd.AddCommand(newPushCmd(), newPullCmd())
1542
if err := cmd.Execute(); err != nil {
1643
os.Exit(1)
1744
}
1845
}
46+
47+
func defaultTrustDir() string {
48+
homeEnvPath := os.Getenv("HOME")
49+
if homeEnvPath == "" && runtime.GOOS == "windows" {
50+
homeEnvPath = os.Getenv("USERPROFILE")
51+
}
52+
53+
return filepath.Join(homeEnvPath, ".wasm-to-oci")
54+
}

cmd/pull.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package main
22

33
import (
4+
"os"
5+
46
"github.com/engineerd/wasm-to-oci/pkg/oci"
7+
"github.com/engineerd/wasm-to-oci/pkg/tuf"
58
"github.com/spf13/cobra"
69
)
710

811
type pullOptions struct {
912
ref string
1013
outFile string
14+
15+
sign bool
1116
}
1217

1318
func newPullCmd() *cobra.Command {
@@ -22,10 +27,24 @@ func newPullCmd() *cobra.Command {
2227
},
2328
}
2429
cmd.Flags().StringVarP(&opts.outFile, "out", "o", "module.wasm", "Name of the output module")
30+
cmd.Flags().BoolVarP(&opts.sign, "sign", "", false, "Verifies the signature of the WebAssembly module from a trust server")
2531

2632
return cmd
2733
}
2834

2935
func (p *pullOptions) run() error {
30-
return oci.Pull(p.ref, p.outFile)
36+
err := oci.Pull(p.ref, p.outFile)
37+
if err != nil {
38+
return err
39+
}
40+
41+
if p.sign {
42+
err = tuf.VerifyFileTrust(p.ref, p.outFile, trustServer, tlscacert, trustDir, timeout)
43+
if err != nil {
44+
os.Remove(p.outFile)
45+
return err
46+
}
47+
}
48+
49+
return nil
3150
}

0 commit comments

Comments
 (0)