Skip to content

Commit

Permalink
resolver: allow setting both insecure tls and http
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Jul 27, 2020
1 parent e226089 commit 6704487
Showing 1 changed file with 40 additions and 16 deletions.
56 changes: 40 additions & 16 deletions util/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,51 @@ import (
"github.com/pkg/errors"
)

func fillInsecureOpts(host string, c config.RegistryConfig, h *docker.RegistryHost) error {
func fillInsecureOpts(host string, c config.RegistryConfig, h docker.RegistryHost) ([]docker.RegistryHost, error) {
var hosts []docker.RegistryHost

tc, err := loadTLSConfig(c)
if err != nil {
return err
return nil, err
}
var isHTTP bool

if c.PlainHTTP != nil && *c.PlainHTTP {
h.Scheme = "http"
} else if c.Insecure != nil && *c.Insecure {
tc.InsecureSkipVerify = true
} else if c.PlainHTTP == nil {
isHTTP = true
}
if c.PlainHTTP == nil {
if ok, _ := docker.MatchLocalhost(host); ok {
h.Scheme = "http"
isHTTP = true
}
}

if isHTTP {
h2 := h
h2.Scheme = "http"
hosts = append(hosts, h2)
}
if c.Insecure != nil && *c.Insecure {
h2 := h
transport := newDefaultTransport()
transport.TLSClientConfig = tc
h2.Client = &http.Client{
Transport: tracing.NewTransport(transport),
}
tc.InsecureSkipVerify = true
hosts = append(hosts, h2)
}

transport := newDefaultTransport()
transport.TLSClientConfig = tc
if len(hosts) == 0 {
transport := newDefaultTransport()
transport.TLSClientConfig = tc

h.Client = &http.Client{
Transport: tracing.NewTransport(transport),
h.Client = &http.Client{
Transport: tracing.NewTransport(transport),
}
hosts = append(hosts, h)
}
return nil

return hosts, nil
}

func loadTLSConfig(c config.RegistryConfig) (*tls.Config, error) {
Expand Down Expand Up @@ -116,11 +138,12 @@ func NewRegistryConfig(m map[string]config.RegistryConfig) docker.RegistryHosts
Capabilities: docker.HostCapabilityPull | docker.HostCapabilityResolve,
}

if err := fillInsecureOpts(mirror, m[mirror], &h); err != nil {
hosts, err := fillInsecureOpts(mirror, m[mirror], h)
if err != nil {
return nil, err
}

out = append(out, h)
out = append(out, hosts...)
}

if host == "docker.io" {
Expand All @@ -135,11 +158,12 @@ func NewRegistryConfig(m map[string]config.RegistryConfig) docker.RegistryHosts
Capabilities: docker.HostCapabilityPush | docker.HostCapabilityPull | docker.HostCapabilityResolve,
}

if err := fillInsecureOpts(host, c, &h); err != nil {
hosts, err := fillInsecureOpts(host, c, h)
if err != nil {
return nil, err
}

out = append(out, h)
out = append(out, hosts...)
return out, nil
},
docker.ConfigureDefaultRegistries(
Expand Down

0 comments on commit 6704487

Please sign in to comment.