Skip to content

Commit 4cd132e

Browse files
committed
fix: Enable registries with self-signed certificates
This change enables Skaffold to push to container image registries that use self-signed or other untrusted certificates, when Skaffold runs on macOS or Windows. It also removes the need for the `SSL_CERT_FILE` environment variable workaround on Linux. Prior to this fix, Skaffold would fail to retrieve the digest from the registry after the image was built, even if the registry was configured as an insecure registry in Skaffold configuration: ``` getting image: Get "https://localhost:8443/v2/": tls: failed to verify certificate: x509: certificate signed by unknown authority; GET http://localhost:8443/v2/: unexpected status code 400 Bad Request: Client sent an HTTP request to an HTTPS server. ``` On Linux environments only, a possible workaround was to set the `SSL_CERT_FILE` environment variable. However, this workaround cannot be used on macOS or Windows. This change updates `getRemoteIndex()` and `getRemoteImage()` in `pkg/skaffold/docker/remote.go`, adding the `InsecureSkipVerify` TLS config field to the transport if the registry from the image name matches one of the insecure registries configured in Skaffold. Fixes: GoogleContainerTools#3039 GoogleContainerTools#3116 Related: google/go-containerregistry#1559
1 parent c280097 commit 4cd132e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

pkg/skaffold/docker/remote.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ package docker
1818

1919
import (
2020
"context"
21+
"crypto/tls"
2122
"fmt"
23+
"net/http"
2224

2325
"github.com/google/go-containerregistry/pkg/name"
2426
v1 "github.com/google/go-containerregistry/pkg/v1"
@@ -123,6 +125,9 @@ func getRemoteImage(identifier string, cfg Config, platform v1.Platform) (v1.Ima
123125
options := []remote.Option{
124126
remote.WithAuthFromKeychain(primaryKeychain),
125127
}
128+
if IsInsecure(ref, cfg.GetInsecureRegistries()) {
129+
options = append(options, insecureTransportOption())
130+
}
126131
if platform.String() != "" {
127132
options = append(options, remote.WithPlatform(platform))
128133
}
@@ -136,14 +141,29 @@ func getRemoteIndex(identifier string, cfg Config) (v1.ImageIndex, error) {
136141
return nil, err
137142
}
138143

139-
return remoteIndex(ref, remote.WithAuthFromKeychain(primaryKeychain))
144+
options := []remote.Option{
145+
remote.WithAuthFromKeychain(primaryKeychain),
146+
}
147+
if IsInsecure(ref, cfg.GetInsecureRegistries()) {
148+
options = append(options, insecureTransportOption())
149+
}
150+
return remoteIndex(ref, options...)
140151
}
141152

142153
// IsInsecure tests if an image is pulled from an insecure registry; default is false
143154
func IsInsecure(ref name.Reference, insecureRegistries map[string]bool) bool {
144155
return insecureRegistries[ref.Context().Registry.Name()]
145156
}
146157

158+
// insecureTransportOption allows untrusted certificates.
159+
func insecureTransportOption() remote.Option {
160+
transport := remote.DefaultTransport.(*http.Transport).Clone()
161+
transport.TLSClientConfig = &tls.Config{
162+
InsecureSkipVerify: true, //nolint: gosec
163+
}
164+
return remote.WithTransport(transport)
165+
}
166+
147167
func parseReference(s string, cfg Config, opts ...name.Option) (name.Reference, error) {
148168
ref, err := name.ParseReference(s, opts...)
149169
if err != nil {

0 commit comments

Comments
 (0)