Skip to content

Commit

Permalink
fix: Always use custom transport to ensure TLS config is correct (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidyson committed Jan 17, 2023
1 parent 9180f52 commit 962c092
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
16 changes: 9 additions & 7 deletions cmd/mindthegap/create/imagebundle/image_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,17 @@ func NewCommand(out output.Output) *cobra.Command {
registryConfig := cfg[registryName]

var remoteOpts []remote.Option
if registryConfig.TLSVerify != nil && !*registryConfig.TLSVerify {
transport := httputils.NewConfigurableTLSRoundTripper(
httputils.TLSHostsConfig{
registryName: httputils.TLSHostConfig{Insecure: true},
},
)

remoteOpts = append(remoteOpts, remote.WithTransport(transport))
var tlsHostsConfig httputils.TLSHostsConfig
if registryConfig.TLSVerify != nil && !*registryConfig.TLSVerify {
tlsHostsConfig = httputils.TLSHostsConfig{
registryName: httputils.TLSHostConfig{Insecure: true},
}
}
transport := httputils.NewConfigurableTLSRoundTripper(
tlsHostsConfig,
)
remoteOpts = append(remoteOpts, remote.WithTransport(transport))

keychain := authn.NewMultiKeychain(
authn.NewKeychainFromHelper(
Expand Down
23 changes: 12 additions & 11 deletions cmd/mindthegap/push/helmbundle/helm_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,21 @@ func NewCommand(out output.Output) *cobra.Command {
logs.Warn.SetOutput(out.InfoWriter())

var remoteOpts []remote.Option

insecure := flags.SkipTLSVerify(destRegistrySkipTLSVerify, destRegistryURI)
tlsHostsConfig := httputils.TLSHostsConfig{
reg.Address(): httputils.TLSHostConfig{Insecure: true},
}
if insecure || destRegistryCACertificateFile != "" {
transport := httputils.NewConfigurableTLSRoundTripper(
httputils.TLSHostsConfig{
destRegistryURI.Host(): httputils.TLSHostConfig{
Insecure: insecure,
CAFile: destRegistryCACertificateFile,
},
reg.Address(): httputils.TLSHostConfig{Insecure: true},
},
)

remoteOpts = append(remoteOpts, remote.WithTransport(transport))
tlsHostsConfig[destRegistryURI.Host()] = httputils.TLSHostConfig{
Insecure: insecure,
CAFile: destRegistryCACertificateFile,
}
}
transport := httputils.NewConfigurableTLSRoundTripper(
tlsHostsConfig,
)
remoteOpts = append(remoteOpts, remote.WithTransport(transport))

keychain := authn.DefaultKeychain
if destRegistryUsername != "" && destRegistryPassword != "" {
Expand Down
23 changes: 12 additions & 11 deletions cmd/mindthegap/push/imagebundle/image_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,21 @@ func NewCommand(out output.Output) *cobra.Command {
logs.Warn.SetOutput(out.InfoWriter())

var remoteOpts []remote.Option

insecure := flags.SkipTLSVerify(destRegistrySkipTLSVerify, destRegistryURI)
tlsHostsConfig := httputils.TLSHostsConfig{
reg.Address(): httputils.TLSHostConfig{Insecure: true},
}
if insecure || destRegistryCACertificateFile != "" {
transport := httputils.NewConfigurableTLSRoundTripper(
httputils.TLSHostsConfig{
destRegistryURI.Host(): httputils.TLSHostConfig{
Insecure: insecure,
CAFile: destRegistryCACertificateFile,
},
reg.Address(): httputils.TLSHostConfig{Insecure: true},
},
)

remoteOpts = append(remoteOpts, remote.WithTransport(transport))
tlsHostsConfig[destRegistryURI.Host()] = httputils.TLSHostConfig{
Insecure: insecure,
CAFile: destRegistryCACertificateFile,
}
}
transport := httputils.NewConfigurableTLSRoundTripper(
tlsHostsConfig,
)
remoteOpts = append(remoteOpts, remote.WithTransport(transport))

keychain := authn.DefaultKeychain
if destRegistryUsername != "" && destRegistryPassword != "" {
Expand Down

0 comments on commit 962c092

Please sign in to comment.