Skip to content

Commit

Permalink
Check push permissions before building images (#622)
Browse files Browse the repository at this point in the history
* Check push permissions before building images

* Fix doc comment

* improve error messages
  • Loading branch information
imjasonh authored and dlorenc committed Mar 19, 2019
1 parent 28bfb75 commit 3fa411c
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ required = [

[[constraint]]
name = "github.com/google/go-containerregistry"
revision = "8c1640add99804503b4126abc718931a4d93c31a"
revision = "8621d738a07bc74b2adeafd175a3c738423577a0"

[[override]]
name = "k8s.io/apimachinery"
Expand Down
6 changes: 4 additions & 2 deletions cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ import (
"strings"
"time"

"github.com/GoogleContainerTools/kaniko/pkg/timing"

"github.com/GoogleContainerTools/kaniko/pkg/buildcontext"
"github.com/GoogleContainerTools/kaniko/pkg/config"
"github.com/GoogleContainerTools/kaniko/pkg/constants"
"github.com/GoogleContainerTools/kaniko/pkg/executor"
"github.com/GoogleContainerTools/kaniko/pkg/timing"
"github.com/GoogleContainerTools/kaniko/pkg/util"
"github.com/genuinetools/amicontained/container"
"github.com/pkg/errors"
Expand Down Expand Up @@ -79,6 +78,9 @@ var RootCmd = &cobra.Command{
}
logrus.Warn("kaniko is being run outside of a container. This can have dangerous effects on your system")
}
if err := executor.CheckPushPermissions(opts); err != nil {
exit(errors.Wrap(err, "error checking push permissions -- make sure you entered the correct tag name, and that you are authenticated correctly, and try again"))
}
if err := os.Chdir("/"); err != nil {
exit(errors.Wrap(err, "error changing to root dir"))
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/executor/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@ func (w *withUserAgent) RoundTrip(r *http.Request) (*http.Response, error) {
return w.t.RoundTrip(r)
}

// CheckPushPermissionos checks that the configured credentials can be used to
// push to every specified destination.
func CheckPushPermissions(opts *config.KanikoOptions) error {
if opts.NoPush {
return nil
}

checked := map[string]bool{}
for _, destination := range opts.Destinations {
destRef, err := name.NewTag(destination, name.WeakValidation)
if err != nil {
return errors.Wrap(err, "getting tag for destination")
}
if checked[destRef.Context().RepositoryStr()] {
continue
}
if err := remote.CheckPushPermission(destRef, creds.GetKeychain(), http.DefaultTransport); err != nil {

This comment has been minimized.

Copy link
@cgiroudargoud

cgiroudargoud Mar 20, 2019

This does not seem to take into account the --skip-tls-verify flag

This comment has been minimized.

Copy link
@lolychee

lolychee Mar 26, 2019

--insecure too

This comment has been minimized.

Copy link
@dbolshak

dbolshak Apr 3, 2019

I hope that somebody from google will have a chance to take a look at #629

return errors.Wrapf(err, "checking push permission for %q", destRef)
}
checked[destRef.Context().RepositoryStr()] = true
}
return nil
}

// DoPush is responsible for pushing image to the destinations specified in opts
func DoPush(image v1.Image, opts *config.KanikoOptions) error {
t := timing.Start("Total Push Time")
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3fa411c

Please sign in to comment.