Skip to content

Commit 0e58ec7

Browse files
bauderh-atomic-bot
authored andcommitted
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 <[email protected]> Closes: #738 Approved by: mheon
1 parent a74107b commit 0e58ec7

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

cmd/podman/push.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func pushCmd(c *cli.Context) error {
8080
var (
8181
registryCreds *types.DockerAuthConfig
8282
destName string
83+
forceSecure bool
8384
)
8485

8586
args := c.Args()
@@ -143,6 +144,10 @@ func pushCmd(c *cli.Context) error {
143144
}
144145
}
145146

147+
if c.IsSet("tls-verify") {
148+
forceSecure = c.Bool("tls-verify")
149+
}
150+
146151
dockerRegistryOptions := image.DockerRegistryOptions{
147152
DockerRegistryCreds: registryCreds,
148153
DockerCertPath: certPath,
@@ -160,5 +165,5 @@ func pushCmd(c *cli.Context) error {
160165
}
161166

162167
//return runtime.PushImage(srcName, destName, options)
163-
return newImage.PushImage(getContext(), destName, manifestType, c.String("authfile"), c.String("signature-policy"), writer, c.Bool("compress"), so, &dockerRegistryOptions)
168+
return newImage.PushImage(getContext(), destName, manifestType, c.String("authfile"), c.String("signature-policy"), writer, c.Bool("compress"), so, &dockerRegistryOptions, forceSecure)
164169
}

cmd/podman/save.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func saveCmd(c *cli.Context) error {
121121
if err != nil {
122122
return err
123123
}
124-
if err := newImage.PushImage(getContext(), dest, manifestType, "", "", writer, c.Bool("compress"), libpodImage.SigningOptions{}, &libpodImage.DockerRegistryOptions{}); err != nil {
124+
if err := newImage.PushImage(getContext(), dest, manifestType, "", "", writer, c.Bool("compress"), libpodImage.SigningOptions{}, &libpodImage.DockerRegistryOptions{}, false); err != nil {
125125
if err2 := os.Remove(output); err2 != nil {
126126
logrus.Errorf("error deleting %q: %v", output, err)
127127
}

libpod/image/image.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import (
2626
"github.com/projectatomic/libpod/libpod/common"
2727
"github.com/projectatomic/libpod/libpod/driver"
2828
"github.com/projectatomic/libpod/pkg/inspect"
29+
"github.com/projectatomic/libpod/pkg/registries"
2930
"github.com/projectatomic/libpod/pkg/util"
31+
"github.com/sirupsen/logrus"
3032
)
3133

3234
// imageConversions is used to cache image "cast" types
@@ -426,7 +428,7 @@ func (i *Image) UntagImage(tag string) error {
426428
}
427429

428430
// PushImage pushes the given image to a location described by the given path
429-
func (i *Image) PushImage(ctx context.Context, destination, manifestMIMEType, authFile, signaturePolicyPath string, writer io.Writer, forceCompress bool, signingOptions SigningOptions, dockerRegistryOptions *DockerRegistryOptions) error {
431+
func (i *Image) PushImage(ctx context.Context, destination, manifestMIMEType, authFile, signaturePolicyPath string, writer io.Writer, forceCompress bool, signingOptions SigningOptions, dockerRegistryOptions *DockerRegistryOptions, forceSecure bool) error {
430432
if destination == "" {
431433
return errors.Wrapf(syscall.EINVAL, "destination image name must be specified")
432434
}
@@ -458,9 +460,23 @@ func (i *Image) PushImage(ctx context.Context, destination, manifestMIMEType, au
458460
if err != nil {
459461
return errors.Wrapf(err, "error getting source imageReference for %q", i.InputName)
460462
}
461-
463+
insecureRegistries, err := registries.GetInsecureRegistries()
464+
if err != nil {
465+
return err
466+
}
462467
copyOptions := getCopyOptions(writer, signaturePolicyPath, nil, dockerRegistryOptions, signingOptions, authFile, manifestMIMEType, forceCompress)
468+
if strings.HasPrefix(DockerTransport, dest.Transport().Name()) {
469+
imgRef, err := reference.Parse(dest.DockerReference().String())
470+
if err != nil {
471+
return err
472+
}
473+
registry := reference.Domain(imgRef.(reference.Named))
463474

475+
if util.StringInSlice(registry, insecureRegistries) && !forceSecure {
476+
copyOptions.DestinationCtx.DockerInsecureSkipTLSVerify = true
477+
logrus.Info(fmt.Sprintf("%s is an insecure registry; pushing with tls-verify=false", registry))
478+
}
479+
}
464480
// Copy the image to the remote destination
465481
err = cp.Image(ctx, policyContext, dest, src, copyOptions)
466482
if err != nil {

pkg/varlinkapi/images.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (i *LibpodAPI) PushImage(call ioprojectatomicpodman.VarlinkCall, name, tag
137137

138138
so := image.SigningOptions{}
139139

140-
if err := newImage.PushImage(getContext(), destname, "", "", "", nil, false, so, &dockerRegistryOptions); err != nil {
140+
if err := newImage.PushImage(getContext(), destname, "", "", "", nil, false, so, &dockerRegistryOptions, false); err != nil {
141141
return call.ReplyErrorOccurred(err.Error())
142142
}
143143
return call.ReplyPushImage(newImage.ID())
@@ -272,7 +272,7 @@ func (i *LibpodAPI) ExportImage(call ioprojectatomicpodman.VarlinkCall, name, de
272272
if err != nil {
273273
return call.ReplyImageNotFound(name)
274274
}
275-
if err := newImage.PushImage(getContext(), destination, "", "", "", nil, compress, image.SigningOptions{}, &image.DockerRegistryOptions{}); err != nil {
275+
if err := newImage.PushImage(getContext(), destination, "", "", "", nil, compress, image.SigningOptions{}, &image.DockerRegistryOptions{}, false); err != nil {
276276
return call.ReplyErrorOccurred(err.Error())
277277
}
278278
return call.ReplyExportImage(newImage.ID())

0 commit comments

Comments
 (0)