podman push should honor registries.conf

Like podman pull, when you push an image, podman should check
if the registry is listed as insecure and if so, it should
--tls-verify=false unless the user overrides this.

Signed-off-by: baude <bbaude@redhat.com>

Closes: #738
Approved by: mheon
This commit is contained in:
baude
2018-05-09 12:04:28 -05:00
committed by Atomic Bot
parent a74107b506
commit 0e58ec7474
4 changed files with 27 additions and 6 deletions

View File

@ -80,6 +80,7 @@ func pushCmd(c *cli.Context) error {
var ( var (
registryCreds *types.DockerAuthConfig registryCreds *types.DockerAuthConfig
destName string destName string
forceSecure bool
) )
args := c.Args() args := c.Args()
@ -143,6 +144,10 @@ func pushCmd(c *cli.Context) error {
} }
} }
if c.IsSet("tls-verify") {
forceSecure = c.Bool("tls-verify")
}
dockerRegistryOptions := image.DockerRegistryOptions{ dockerRegistryOptions := image.DockerRegistryOptions{
DockerRegistryCreds: registryCreds, DockerRegistryCreds: registryCreds,
DockerCertPath: certPath, DockerCertPath: certPath,
@ -160,5 +165,5 @@ func pushCmd(c *cli.Context) error {
} }
//return runtime.PushImage(srcName, destName, options) //return runtime.PushImage(srcName, destName, options)
return newImage.PushImage(getContext(), destName, manifestType, c.String("authfile"), c.String("signature-policy"), writer, c.Bool("compress"), so, &dockerRegistryOptions) return newImage.PushImage(getContext(), destName, manifestType, c.String("authfile"), c.String("signature-policy"), writer, c.Bool("compress"), so, &dockerRegistryOptions, forceSecure)
} }

View File

@ -121,7 +121,7 @@ func saveCmd(c *cli.Context) error {
if err != nil { if err != nil {
return err return err
} }
if err := newImage.PushImage(getContext(), dest, manifestType, "", "", writer, c.Bool("compress"), libpodImage.SigningOptions{}, &libpodImage.DockerRegistryOptions{}); err != nil { if err := newImage.PushImage(getContext(), dest, manifestType, "", "", writer, c.Bool("compress"), libpodImage.SigningOptions{}, &libpodImage.DockerRegistryOptions{}, false); err != nil {
if err2 := os.Remove(output); err2 != nil { if err2 := os.Remove(output); err2 != nil {
logrus.Errorf("error deleting %q: %v", output, err) logrus.Errorf("error deleting %q: %v", output, err)
} }

View File

@ -26,7 +26,9 @@ import (
"github.com/projectatomic/libpod/libpod/common" "github.com/projectatomic/libpod/libpod/common"
"github.com/projectatomic/libpod/libpod/driver" "github.com/projectatomic/libpod/libpod/driver"
"github.com/projectatomic/libpod/pkg/inspect" "github.com/projectatomic/libpod/pkg/inspect"
"github.com/projectatomic/libpod/pkg/registries"
"github.com/projectatomic/libpod/pkg/util" "github.com/projectatomic/libpod/pkg/util"
"github.com/sirupsen/logrus"
) )
// imageConversions is used to cache image "cast" types // imageConversions is used to cache image "cast" types
@ -426,7 +428,7 @@ func (i *Image) UntagImage(tag string) error {
} }
// PushImage pushes the given image to a location described by the given path // PushImage pushes the given image to a location described by the given path
func (i *Image) PushImage(ctx context.Context, destination, manifestMIMEType, authFile, signaturePolicyPath string, writer io.Writer, forceCompress bool, signingOptions SigningOptions, dockerRegistryOptions *DockerRegistryOptions) error { func (i *Image) PushImage(ctx context.Context, destination, manifestMIMEType, authFile, signaturePolicyPath string, writer io.Writer, forceCompress bool, signingOptions SigningOptions, dockerRegistryOptions *DockerRegistryOptions, forceSecure bool) error {
if destination == "" { if destination == "" {
return errors.Wrapf(syscall.EINVAL, "destination image name must be specified") return errors.Wrapf(syscall.EINVAL, "destination image name must be specified")
} }
@ -458,9 +460,23 @@ func (i *Image) PushImage(ctx context.Context, destination, manifestMIMEType, au
if err != nil { if err != nil {
return errors.Wrapf(err, "error getting source imageReference for %q", i.InputName) return errors.Wrapf(err, "error getting source imageReference for %q", i.InputName)
} }
insecureRegistries, err := registries.GetInsecureRegistries()
if err != nil {
return err
}
copyOptions := getCopyOptions(writer, signaturePolicyPath, nil, dockerRegistryOptions, signingOptions, authFile, manifestMIMEType, forceCompress) copyOptions := getCopyOptions(writer, signaturePolicyPath, nil, dockerRegistryOptions, signingOptions, authFile, manifestMIMEType, forceCompress)
if strings.HasPrefix(DockerTransport, dest.Transport().Name()) {
imgRef, err := reference.Parse(dest.DockerReference().String())
if err != nil {
return err
}
registry := reference.Domain(imgRef.(reference.Named))
if util.StringInSlice(registry, insecureRegistries) && !forceSecure {
copyOptions.DestinationCtx.DockerInsecureSkipTLSVerify = true
logrus.Info(fmt.Sprintf("%s is an insecure registry; pushing with tls-verify=false", registry))
}
}
// Copy the image to the remote destination // Copy the image to the remote destination
err = cp.Image(ctx, policyContext, dest, src, copyOptions) err = cp.Image(ctx, policyContext, dest, src, copyOptions)
if err != nil { if err != nil {

View File

@ -137,7 +137,7 @@ func (i *LibpodAPI) PushImage(call ioprojectatomicpodman.VarlinkCall, name, tag
so := image.SigningOptions{} so := image.SigningOptions{}
if err := newImage.PushImage(getContext(), destname, "", "", "", nil, false, so, &dockerRegistryOptions); err != nil { if err := newImage.PushImage(getContext(), destname, "", "", "", nil, false, so, &dockerRegistryOptions, false); err != nil {
return call.ReplyErrorOccurred(err.Error()) return call.ReplyErrorOccurred(err.Error())
} }
return call.ReplyPushImage(newImage.ID()) return call.ReplyPushImage(newImage.ID())
@ -272,7 +272,7 @@ func (i *LibpodAPI) ExportImage(call ioprojectatomicpodman.VarlinkCall, name, de
if err != nil { if err != nil {
return call.ReplyImageNotFound(name) return call.ReplyImageNotFound(name)
} }
if err := newImage.PushImage(getContext(), destination, "", "", "", nil, compress, image.SigningOptions{}, &image.DockerRegistryOptions{}); err != nil { if err := newImage.PushImage(getContext(), destination, "", "", "", nil, compress, image.SigningOptions{}, &image.DockerRegistryOptions{}, false); err != nil {
return call.ReplyErrorOccurred(err.Error()) return call.ReplyErrorOccurred(err.Error())
} }
return call.ReplyExportImage(newImage.ID()) return call.ReplyExportImage(newImage.ID())