Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip tls verification if default transport is used with insecure option #1559

Merged
merged 1 commit into from
Feb 8, 2023

Conversation

komish
Copy link
Contributor

@komish komish commented Feb 7, 2023

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 makeOptions to 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.RoundTripper that 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#L88

Signed-off-by: Jose R. Gonzalez jose@flutes.dev

@komish komish force-pushed the crane-insecure-skip-verify branch 2 times, most recently from 339f268 to 6b9e7e9 Compare February 7, 2023 16:35
@komish
Copy link
Contributor Author

komish commented Feb 7, 2023

/cc @jonjohnsonjr

}
}

// 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).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// the default transport is used (i.e. when WithTransport is not defined).
// the default transport is used (i.e. when WithTransport is not used).

Copy link
Contributor Author

@komish komish Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggestion should be incorporated in the latest force-push. 223f982

Copy link
Collaborator

@jonjohnsonjr jonjohnsonjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@codecov-commenter
Copy link

codecov-commenter commented Feb 7, 2023

Codecov Report

Merging #1559 (223f982) into main (e04520b) will increase coverage by 0.20%.
The diff coverage is 86.20%.

❗ Current head 223f982 differs from pull request most recent head b8a70b6. Consider uploading reports for the commit b8a70b6 to get more accurate results

@@            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     
Impacted Files Coverage Δ
pkg/v1/remote/write.go 62.43% <62.50%> (-0.27%) ⬇️
pkg/v1/remote/descriptor.go 72.34% <67.56%> (-1.51%) ⬇️
internal/cmd/edit.go 54.12% <85.00%> (+0.64%) ⬆️
pkg/crane/options.go 86.44% <100.00%> (+7.27%) ⬆️
pkg/registry/manifest.go 94.04% <100.00%> (+1.83%) ⬆️
pkg/registry/registry.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@komish
Copy link
Contributor Author

komish commented Feb 7, 2023

@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.

func WithTransport(t http.RoundTripper) Option {
return func(o *Options) {
o.Remote = append(o.Remote, remote.WithTransport(t))
o.transportSet = true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in 5112fe3

Signed-off-by: Jose R. Gonzalez <jose@flutes.dev>
@jonjohnsonjr jonjohnsonjr merged commit 9cd098e into google:main Feb 8, 2023
@jonjohnsonjr
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants