From 34fcb7e0727dc59bc65c1250bce0da83e370f768 Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Thu, 7 Sep 2023 06:07:40 +0000 Subject: [PATCH] fix: allow HTTPS for localhost Signed-off-by: Billy Zha --- cmd/oras/internal/option/remote.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/oras/internal/option/remote.go b/cmd/oras/internal/option/remote.go index f56b90bf5..edf9edd30 100644 --- a/cmd/oras/internal/option/remote.go +++ b/cmd/oras/internal/option/remote.go @@ -43,7 +43,7 @@ import ( // Remote options struct. type Remote struct { CACertFilePath string - PlainHTTP bool + PlainHTTP *bool Insecure bool Configs []string Username string @@ -98,7 +98,7 @@ func (opts *Remote) ApplyFlagsWithPrefix(fs *pflag.FlagSet, prefix, description fs.StringVarP(&opts.Username, flagPrefix+"username", shortUser, "", notePrefix+"registry username") fs.StringVarP(&opts.Password, flagPrefix+"password", shortPassword, "", notePrefix+"registry password or identity token") fs.BoolVarP(&opts.Insecure, flagPrefix+"insecure", "", false, "allow connections to "+notePrefix+"SSL registry without certs") - fs.BoolVarP(&opts.PlainHTTP, flagPrefix+"plain-http", "", false, "allow insecure connections to "+notePrefix+"registry without SSL check") + fs.BoolVarP(opts.PlainHTTP, flagPrefix+"plain-http", "", false, "allow insecure connections to "+notePrefix+"registry without SSL check") fs.StringVarP(&opts.CACertFilePath, flagPrefix+"ca-file", "", "", "server certificate authority file for the remote "+notePrefix+"registry") fs.StringArrayVarP(&opts.resolveFlag, flagPrefix+"resolve", "", nil, "customized DNS for "+notePrefix+"registry, formatted in `host:port:address[:address_port]`") fs.StringArrayVarP(&opts.Configs, flagPrefix+"registry-config", "", nil, "`path` of the authentication file for "+notePrefix+"registry") @@ -305,9 +305,12 @@ func (opts *Remote) NewRepository(reference string, common Common, logger logrus // isPlainHttp returns the plain http flag for a given registry. func (opts *Remote) isPlainHttp(registry string) bool { + if opts.PlainHTTP != nil { + return *opts.PlainHTTP + } host, _, _ := net.SplitHostPort(registry) if host == "localhost" || registry == "localhost" { return true } - return opts.PlainHTTP + return false }