skip tls verification if default transport is used with insecure option#1559
Conversation
339f268 to
6b9e7e9
Compare
|
/cc @jonjohnsonjr |
pkg/crane/options.go
Outdated
|
|
||
| // Insecure is an Option that allows image references to be fetched without TLS. | ||
| // This will also allow for untrusted (e.g. self-signed) certificates in cases where | ||
| // the default transport is used (i.e. when WithTransport is not defined). |
There was a problem hiding this comment.
| // the default transport is used (i.e. when WithTransport is not defined). | |
| // the default transport is used (i.e. when WithTransport is not used). |
There was a problem hiding this comment.
This suggestion should be incorporated in the latest force-push. 223f982
jonjohnsonjr
left a comment
There was a problem hiding this comment.
This LGTM overall. Do you mind adding a test to cover this? I'd probably be lazy and add a private transport to Options when you call Insecure and WithTransport, then just check that InsecureSkipVerify is set for that.
6b9e7e9 to
223f982
Compare
Codecov Report
@@ Coverage Diff @@
## main #1559 +/- ##
==========================================
+ Coverage 72.75% 72.95% +0.20%
==========================================
Files 118 118
Lines 9236 9386 +150
==========================================
+ Hits 6720 6848 +128
- Misses 1831 1845 +14
- Partials 685 693 +8
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
|
@jonjohnsonjr Sure thing. I went ahead and added tests to make sure we're setting the internal boolean values (that trigger the logic we want), and then a test to make sure we're adding the transport how we expect. As you suggested, I added a private transport value to facilitate the test, and rewired the logic to set that value. Made the test much simpler. |
pkg/crane/options.go
Outdated
| func WithTransport(t http.RoundTripper) Option { | ||
| return func(o *Options) { | ||
| o.Remote = append(o.Remote, remote.WithTransport(t)) | ||
| o.transportSet = true |
There was a problem hiding this comment.
What do you think about o.transport = t instead of the bool, then have makeOptions check for opt.transport == nil rather than having both the bool and the transport?
There was a problem hiding this comment.
I'm thinking we'd still want to track the insecure bool, but otherwise that could work and removes a bit of a redundancy. I'll put it together and send it here momentarily (along with the Boilerplate check fix).
223f982 to
5112fe3
Compare
Signed-off-by: Jose R. Gonzalez <jose@flutes.dev>
5112fe3 to
b8a70b6
Compare
|
Thanks! |
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
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
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
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: #3039 #3116 Related: google/go-containerregistry#1559
Fixes #1553
This PR addresses an inconsistency between the Crane library and the Crane CLI (which works correctly) with regards to interactions with image registries behind untrusted (read: self-signed) certificates.
This implementation internally tracks the Insecure/WithTransport options being set to allow
makeOptionsto decide whether or not a slightly modified default transport needs to be added to the remote options. If the right combination is not set, this does not add any default transport, relying on whatever default was to be used (same behavior as before).This PR does not change the Crane CLI because the
http.RoundTripperthat it builds out ultimately takes into account docker config values that a library caller should invoke manually. In doing so, a caller would be defining their own transport, and the logic here would not take effect. https://github.com/google/go-containerregistry/blob/main/cmd/crane/cmd/root.go#L88Signed-off-by: Jose R. Gonzalez jose@flutes.dev