Skip to content

Commit

Permalink
WIP: Add sigstore tests
Browse files Browse the repository at this point in the history
This depends on https://github.com/mtrmac/image/tree/docker-push-to-tag
to support reasonable pushing to Docker registries.

Also includes a smoke test for (skopeo delete) (really verifying the
sigstore deletion).
  • Loading branch information
mtrmac committed Sep 10, 2016
1 parent ff17c24 commit 6090bdb
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 2 deletions.
90 changes: 88 additions & 2 deletions integration/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@ import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"path/filepath"

"github.com/containers/image/manifest"
"github.com/go-check/check"
)

const sigstoreV2RegistryURL = "localhost:5555" // Update also policy.json

func init() {
check.Suite(&CopySuite{})
}

type CopySuite struct {
cluster *openshiftCluster
gpgHome string
cluster *openshiftCluster
registry *testRegistryV2
gpgHome string
}

func (s *CopySuite) SetUpSuite(c *check.C) {
Expand All @@ -39,6 +44,8 @@ func (s *CopySuite) SetUpSuite(c *check.C) {
runCommandWithInput(c, isJSON, "oc", "create", "-f", "-")
}

s.registry = setupRegistryV2At(c, sigstoreV2RegistryURL, false, false)

gpgHome, err := ioutil.TempDir("", "skopeo-gpg")
c.Assert(err, check.IsNil)
s.gpgHome = gpgHome
Expand Down Expand Up @@ -245,3 +252,82 @@ func (s *CopySuite) TestCopyDirSignatures(c *check.C) {
assertSkopeoFails(c, ".*Source image rejected: .*Signature for identity localhost:8443/myns/personal:dirstaging2 is not accepted.*",
"--policy", policy, "copy", topDirDest+"/restricted/badidentity", topDirDest+"/dest")
}

func findRegularFiles(c *check.C, root string) []string {
result := []string{}
err := filepath.Walk(root, filepath.WalkFunc(func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.Mode().IsRegular() {
result = append(result, path)
}
return nil
}))
c.Assert(err, check.IsNil)
return result
}

// --sign-by and policy use for docker: with sigstore
func (s *CopySuite) TestCopyDockerSigstore(c *check.C) {
const ourRegistry = "docker://" + sigstoreV2RegistryURL + "/"

tmpDir, err := ioutil.TempDir("", "signatures-sigstore")
c.Assert(err, check.IsNil)
//defer os.RemoveAll(tmpDir)
copyDest := filepath.Join(tmpDir, "dest")
err = os.Mkdir(copyDest, 0755)
c.Assert(err, check.IsNil)
dirDest := "dir:" + copyDest
plainSigstore := filepath.Join(tmpDir, "sigstore")
splitSigstoreWrite := filepath.Join(tmpDir, "sigstore-write")

splitSigstoreReadServerHandler := http.NotFoundHandler()
splitSigstoreReadServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
splitSigstoreReadServerHandler.ServeHTTP(w, r)
}))
defer splitSigstoreReadServer.Close()

policy := fileFromFixture(c, "fixtures/policy.json", map[string]string{"@keydir@": s.gpgHome})
defer os.Remove(policy)
registriesDir := filepath.Join(tmpDir, "registries.d")
err = os.Mkdir(registriesDir, 0755)
c.Assert(err, check.IsNil)
registriesFile := fileFromFixture(c, "fixtures/registries.yaml",
map[string]string{"@sigstore@": plainSigstore, "@split-write@": splitSigstoreWrite, "@split-read@": splitSigstoreReadServer.URL})
err = os.Symlink(registriesFile, filepath.Join(registriesDir, "registries.yaml"))
c.Assert(err, check.IsNil)

// Get an image to work with. Also verifies that we can use Docker repositories with no sigstore configured.
assertSkopeoSucceeds(c, "", "--registries.d", registriesDir, "copy", "docker://busybox", ourRegistry+"original/busybox")
// Pulling an unsigned image fails.
assertSkopeoFails(c, ".*Source image rejected: A signature was required, but no signature exists.*",
"--policy", policy, "--registries.d", registriesDir, "copy", ourRegistry+"original/busybox", dirDest)

// Signing with sigstore defined succeeds,
assertSkopeoSucceeds(c, "", "--registries.d", registriesDir, "copy", "--sign-by", "personal@example.com", ourRegistry+"original/busybox", ourRegistry+"signed/busybox")
// a signature file has been created,
foundFiles := findRegularFiles(c, plainSigstore)
c.Assert(foundFiles, check.HasLen, 1)
// and pulling a signed image succeeds.
assertSkopeoSucceeds(c, "", "--policy", policy, "--registries.d", registriesDir, "copy", ourRegistry+"signed/busybox", dirDest)

// Deleting the image succeeds,
assertSkopeoSucceeds(c, "", "--registries.d", registriesDir, "delete", ourRegistry+"signed/busybox")
// and the signature file has been deleted (but we leave the directories around).
// a signature file has been created,
foundFiles = findRegularFiles(c, plainSigstore)
c.Assert(foundFiles, check.HasLen, 0)

// Signing with a read/write sigstore split succeeds,
assertSkopeoSucceeds(c, "", "--registries.d", registriesDir, "copy", "--sign-by", "personal@example.com", ourRegistry+"original/busybox", ourRegistry+"public/busybox")
// and a signature file has been created.
foundFiles = findRegularFiles(c, splitSigstoreWrite)
c.Assert(foundFiles, check.HasLen, 1)
// Pulling the image fails because the read sigstore URL has not been populated:
assertSkopeoFails(c, ".*Source image rejected: A signature was required, but no signature exists.*",
"--policy", policy, "--registries.d", registriesDir, "copy", ourRegistry+"public/busybox", dirDest)
// Pulling the image succeeds after the read sigstore URL is available:
splitSigstoreReadServerHandler = http.FileServer(http.Dir(splitSigstoreWrite))
assertSkopeoSucceeds(c, "", "--policy", policy, "--registries.d", registriesDir, "copy", ourRegistry+"public/busybox", dirDest)
}
7 changes: 7 additions & 0 deletions integration/fixtures/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
],
"transports": {
"docker": {
"localhost:5555": [
{
"type": "signedBy",
"keyType": "GPGKeys",
"keyPath": "@keydir@/personal-pubkey.gpg"
}
],
"docker.io/openshift": [
{
"type": "insecureAcceptAnything"
Expand Down
6 changes: 6 additions & 0 deletions integration/fixtures/registries.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
docker:
localhost:5555:
sigstore: file://@sigstore@
localhost:5555/public:
sigstore-write: file://@split-write@
sigstore: @split-read@
2 changes: 2 additions & 0 deletions integration/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ loglevel: debug
storage:
filesystem:
rootdirectory: %s
delete:
enabled: true
http:
addr: %s
%s`
Expand Down

0 comments on commit 6090bdb

Please sign in to comment.