|
@@ -7,14 +7,11 @@ import (
|
|
|
"net/http"
|
|
|
"net/http/httptest"
|
|
|
"os"
|
|
|
- "path/filepath"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
|
|
|
"github.com/docker/distribution/reference"
|
|
|
- "github.com/docker/docker/cli/config"
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
|
|
- "github.com/docker/docker/integration-cli/cli"
|
|
|
"github.com/docker/docker/integration-cli/cli/build"
|
|
|
"github.com/go-check/check"
|
|
|
"github.com/gotestyourself/gotestyourself/icmd"
|
|
@@ -281,225 +278,6 @@ func (s *DockerSchema1RegistrySuite) TestCrossRepositoryLayerPushNotSupported(c
|
|
|
c.Assert(out3, check.Equals, "hello world")
|
|
|
}
|
|
|
|
|
|
-func (s *DockerTrustSuite) TestTrustedPush(c *check.C) {
|
|
|
- repoName := fmt.Sprintf("%v/dockerclitrusted/pushtest:latest", privateRegistryURL)
|
|
|
- // tag the image and upload it to the private registry
|
|
|
- cli.DockerCmd(c, "tag", "busybox", repoName)
|
|
|
-
|
|
|
- cli.Docker(cli.Args("push", repoName), trustedCmd).Assert(c, SuccessSigningAndPushing)
|
|
|
-
|
|
|
- // Try pull after push
|
|
|
- cli.Docker(cli.Args("pull", repoName), trustedCmd).Assert(c, icmd.Expected{
|
|
|
- Out: "Status: Image is up to date",
|
|
|
- })
|
|
|
-
|
|
|
- // Assert that we rotated the snapshot key to the server by checking our local keystore
|
|
|
- contents, err := ioutil.ReadDir(filepath.Join(config.Dir(), "trust/private/tuf_keys", privateRegistryURL, "dockerclitrusted/pushtest"))
|
|
|
- c.Assert(err, check.IsNil, check.Commentf("Unable to read local tuf key files"))
|
|
|
- // Check that we only have 1 key (targets key)
|
|
|
- c.Assert(contents, checker.HasLen, 1)
|
|
|
-}
|
|
|
-
|
|
|
-func (s *DockerTrustSuite) TestTrustedPushWithEnvPasswords(c *check.C) {
|
|
|
- repoName := fmt.Sprintf("%v/dockerclienv/trusted:latest", privateRegistryURL)
|
|
|
- // tag the image and upload it to the private registry
|
|
|
- cli.DockerCmd(c, "tag", "busybox", repoName)
|
|
|
-
|
|
|
- cli.Docker(cli.Args("push", repoName), trustedCmdWithPassphrases("12345678", "12345678")).Assert(c, SuccessSigningAndPushing)
|
|
|
-
|
|
|
- // Try pull after push
|
|
|
- cli.Docker(cli.Args("pull", repoName), trustedCmd).Assert(c, icmd.Expected{
|
|
|
- Out: "Status: Image is up to date",
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-func (s *DockerTrustSuite) TestTrustedPushWithFailingServer(c *check.C) {
|
|
|
- repoName := fmt.Sprintf("%v/dockerclitrusted/failingserver:latest", privateRegistryURL)
|
|
|
- // tag the image and upload it to the private registry
|
|
|
- cli.DockerCmd(c, "tag", "busybox", repoName)
|
|
|
-
|
|
|
- // Using a name that doesn't resolve to an address makes this test faster
|
|
|
- cli.Docker(cli.Args("push", repoName), trustedCmdWithServer("https://server.invalid:81/")).Assert(c, icmd.Expected{
|
|
|
- ExitCode: 1,
|
|
|
- Err: "error contacting notary server",
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-func (s *DockerTrustSuite) TestTrustedPushWithoutServerAndUntrusted(c *check.C) {
|
|
|
- repoName := fmt.Sprintf("%v/dockerclitrusted/trustedandnot:latest", privateRegistryURL)
|
|
|
- // tag the image and upload it to the private registry
|
|
|
- cli.DockerCmd(c, "tag", "busybox", repoName)
|
|
|
-
|
|
|
- result := cli.Docker(cli.Args("push", "--disable-content-trust", repoName), trustedCmdWithServer("https://server.invalid:81/"))
|
|
|
- result.Assert(c, icmd.Success)
|
|
|
- c.Assert(result.Combined(), check.Not(checker.Contains), "Error establishing connection to notary repository", check.Commentf("Missing expected output on trusted push with --disable-content-trust:"))
|
|
|
-}
|
|
|
-
|
|
|
-func (s *DockerTrustSuite) TestTrustedPushWithExistingTag(c *check.C) {
|
|
|
- repoName := fmt.Sprintf("%v/dockerclitag/trusted:latest", privateRegistryURL)
|
|
|
- // tag the image and upload it to the private registry
|
|
|
- cli.DockerCmd(c, "tag", "busybox", repoName)
|
|
|
- cli.DockerCmd(c, "push", repoName)
|
|
|
-
|
|
|
- cli.Docker(cli.Args("push", repoName), trustedCmd).Assert(c, SuccessSigningAndPushing)
|
|
|
-
|
|
|
- // Try pull after push
|
|
|
- cli.Docker(cli.Args("pull", repoName), trustedCmd).Assert(c, icmd.Expected{
|
|
|
- Out: "Status: Image is up to date",
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-func (s *DockerTrustSuite) TestTrustedPushWithExistingSignedTag(c *check.C) {
|
|
|
- repoName := fmt.Sprintf("%v/dockerclipushpush/trusted:latest", privateRegistryURL)
|
|
|
- // tag the image and upload it to the private registry
|
|
|
- cli.DockerCmd(c, "tag", "busybox", repoName)
|
|
|
-
|
|
|
- // Do a trusted push
|
|
|
- cli.Docker(cli.Args("push", repoName), trustedCmd).Assert(c, SuccessSigningAndPushing)
|
|
|
-
|
|
|
- // Do another trusted push
|
|
|
- cli.Docker(cli.Args("push", repoName), trustedCmd).Assert(c, SuccessSigningAndPushing)
|
|
|
- cli.DockerCmd(c, "rmi", repoName)
|
|
|
-
|
|
|
- // Try pull to ensure the double push did not break our ability to pull
|
|
|
- cli.Docker(cli.Args("pull", repoName), trustedCmd).Assert(c, SuccessDownloaded)
|
|
|
-}
|
|
|
-
|
|
|
-func (s *DockerTrustSuite) TestTrustedPushWithIncorrectPassphraseForNonRoot(c *check.C) {
|
|
|
- repoName := fmt.Sprintf("%v/dockercliincorretpwd/trusted:latest", privateRegistryURL)
|
|
|
- // tag the image and upload it to the private registry
|
|
|
- cli.DockerCmd(c, "tag", "busybox", repoName)
|
|
|
-
|
|
|
- // Push with default passphrases
|
|
|
- cli.Docker(cli.Args("push", repoName), trustedCmd).Assert(c, SuccessSigningAndPushing)
|
|
|
-
|
|
|
- // Push with wrong passphrases
|
|
|
- cli.Docker(cli.Args("push", repoName), trustedCmdWithPassphrases("12345678", "87654321")).Assert(c, icmd.Expected{
|
|
|
- ExitCode: 1,
|
|
|
- Err: "could not find necessary signing keys",
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-func (s *DockerTrustSuite) TestTrustedPushWithReleasesDelegationOnly(c *check.C) {
|
|
|
- testRequires(c, NotaryHosting)
|
|
|
- repoName := fmt.Sprintf("%v/dockerclireleasedelegationinitfirst/trusted", privateRegistryURL)
|
|
|
- targetName := fmt.Sprintf("%s:latest", repoName)
|
|
|
- s.notaryInitRepo(c, repoName)
|
|
|
- s.notaryCreateDelegation(c, repoName, "targets/releases", s.not.keys[0].Public)
|
|
|
- s.notaryPublish(c, repoName)
|
|
|
-
|
|
|
- s.notaryImportKey(c, repoName, "targets/releases", s.not.keys[0].Private)
|
|
|
-
|
|
|
- // tag the image and upload it to the private registry
|
|
|
- cli.DockerCmd(c, "tag", "busybox", targetName)
|
|
|
-
|
|
|
- cli.Docker(cli.Args("push", targetName), trustedCmd).Assert(c, SuccessSigningAndPushing)
|
|
|
- // check to make sure that the target has been added to targets/releases and not targets
|
|
|
- s.assertTargetInRoles(c, repoName, "latest", "targets/releases")
|
|
|
- s.assertTargetNotInRoles(c, repoName, "latest", "targets")
|
|
|
-
|
|
|
- // Try pull after push
|
|
|
- os.RemoveAll(filepath.Join(config.Dir(), "trust"))
|
|
|
-
|
|
|
- cli.Docker(cli.Args("pull", targetName), trustedCmd).Assert(c, icmd.Expected{
|
|
|
- Out: "Status: Image is up to date",
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-func (s *DockerTrustSuite) TestTrustedPushSignsAllFirstLevelRolesWeHaveKeysFor(c *check.C) {
|
|
|
- testRequires(c, NotaryHosting)
|
|
|
- repoName := fmt.Sprintf("%v/dockerclimanyroles/trusted", privateRegistryURL)
|
|
|
- targetName := fmt.Sprintf("%s:latest", repoName)
|
|
|
- s.notaryInitRepo(c, repoName)
|
|
|
- s.notaryCreateDelegation(c, repoName, "targets/role1", s.not.keys[0].Public)
|
|
|
- s.notaryCreateDelegation(c, repoName, "targets/role2", s.not.keys[1].Public)
|
|
|
- s.notaryCreateDelegation(c, repoName, "targets/role3", s.not.keys[2].Public)
|
|
|
-
|
|
|
- // import everything except the third key
|
|
|
- s.notaryImportKey(c, repoName, "targets/role1", s.not.keys[0].Private)
|
|
|
- s.notaryImportKey(c, repoName, "targets/role2", s.not.keys[1].Private)
|
|
|
-
|
|
|
- s.notaryCreateDelegation(c, repoName, "targets/role1/subrole", s.not.keys[3].Public)
|
|
|
- s.notaryImportKey(c, repoName, "targets/role1/subrole", s.not.keys[3].Private)
|
|
|
-
|
|
|
- s.notaryPublish(c, repoName)
|
|
|
-
|
|
|
- // tag the image and upload it to the private registry
|
|
|
- cli.DockerCmd(c, "tag", "busybox", targetName)
|
|
|
-
|
|
|
- cli.Docker(cli.Args("push", targetName), trustedCmd).Assert(c, SuccessSigningAndPushing)
|
|
|
-
|
|
|
- // check to make sure that the target has been added to targets/role1 and targets/role2, and
|
|
|
- // not targets (because there are delegations) or targets/role3 (due to missing key) or
|
|
|
- // targets/role1/subrole (due to it being a second level delegation)
|
|
|
- s.assertTargetInRoles(c, repoName, "latest", "targets/role1", "targets/role2")
|
|
|
- s.assertTargetNotInRoles(c, repoName, "latest", "targets")
|
|
|
-
|
|
|
- // Try pull after push
|
|
|
- os.RemoveAll(filepath.Join(config.Dir(), "trust"))
|
|
|
-
|
|
|
- // pull should fail because none of these are the releases role
|
|
|
- cli.Docker(cli.Args("pull", targetName), trustedCmd).Assert(c, icmd.Expected{
|
|
|
- ExitCode: 1,
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-func (s *DockerTrustSuite) TestTrustedPushSignsForRolesWithKeysAndValidPaths(c *check.C) {
|
|
|
- repoName := fmt.Sprintf("%v/dockerclirolesbykeysandpaths/trusted", privateRegistryURL)
|
|
|
- targetName := fmt.Sprintf("%s:latest", repoName)
|
|
|
- s.notaryInitRepo(c, repoName)
|
|
|
- s.notaryCreateDelegation(c, repoName, "targets/role1", s.not.keys[0].Public, "l", "z")
|
|
|
- s.notaryCreateDelegation(c, repoName, "targets/role2", s.not.keys[1].Public, "x", "y")
|
|
|
- s.notaryCreateDelegation(c, repoName, "targets/role3", s.not.keys[2].Public, "latest")
|
|
|
- s.notaryCreateDelegation(c, repoName, "targets/role4", s.not.keys[3].Public, "latest")
|
|
|
-
|
|
|
- // import everything except the third key
|
|
|
- s.notaryImportKey(c, repoName, "targets/role1", s.not.keys[0].Private)
|
|
|
- s.notaryImportKey(c, repoName, "targets/role2", s.not.keys[1].Private)
|
|
|
- s.notaryImportKey(c, repoName, "targets/role4", s.not.keys[3].Private)
|
|
|
-
|
|
|
- s.notaryPublish(c, repoName)
|
|
|
-
|
|
|
- // tag the image and upload it to the private registry
|
|
|
- cli.DockerCmd(c, "tag", "busybox", targetName)
|
|
|
-
|
|
|
- cli.Docker(cli.Args("push", targetName), trustedCmd).Assert(c, SuccessSigningAndPushing)
|
|
|
-
|
|
|
- // check to make sure that the target has been added to targets/role1 and targets/role4, and
|
|
|
- // not targets (because there are delegations) or targets/role2 (due to path restrictions) or
|
|
|
- // targets/role3 (due to missing key)
|
|
|
- s.assertTargetInRoles(c, repoName, "latest", "targets/role1", "targets/role4")
|
|
|
- s.assertTargetNotInRoles(c, repoName, "latest", "targets")
|
|
|
-
|
|
|
- // Try pull after push
|
|
|
- os.RemoveAll(filepath.Join(config.Dir(), "trust"))
|
|
|
-
|
|
|
- // pull should fail because none of these are the releases role
|
|
|
- cli.Docker(cli.Args("pull", targetName), trustedCmd).Assert(c, icmd.Expected{
|
|
|
- ExitCode: 1,
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-func (s *DockerTrustSuite) TestTrustedPushDoesntSignTargetsIfDelegationsExist(c *check.C) {
|
|
|
- testRequires(c, NotaryHosting)
|
|
|
- repoName := fmt.Sprintf("%v/dockerclireleasedelegationnotsignable/trusted", privateRegistryURL)
|
|
|
- targetName := fmt.Sprintf("%s:latest", repoName)
|
|
|
- s.notaryInitRepo(c, repoName)
|
|
|
- s.notaryCreateDelegation(c, repoName, "targets/role1", s.not.keys[0].Public)
|
|
|
- s.notaryPublish(c, repoName)
|
|
|
-
|
|
|
- // do not import any delegations key
|
|
|
-
|
|
|
- // tag the image and upload it to the private registry
|
|
|
- cli.DockerCmd(c, "tag", "busybox", targetName)
|
|
|
-
|
|
|
- cli.Docker(cli.Args("push", targetName), trustedCmd).Assert(c, icmd.Expected{
|
|
|
- ExitCode: 1,
|
|
|
- Err: "no valid signing keys",
|
|
|
- })
|
|
|
- s.assertTargetNotInRoles(c, repoName, "latest", "targets", "targets/role1")
|
|
|
-}
|
|
|
-
|
|
|
func (s *DockerRegistryAuthHtpasswdSuite) TestPushNoCredentialsNoRetry(c *check.C) {
|
|
|
repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
|
|
|
dockerCmd(c, "tag", "busybox", repoName)
|