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

Add function to get system cert pool #21

Merged
merged 1 commit into from
Oct 31, 2016

Conversation

dmcgowan
Copy link
Contributor

Defaults to getting empty cert pool when less than go 1.7 or fails to load the system cert pool.

Needed for moby/moby#12756

@aaronlehmann
Copy link

Code LGTM (not a maintainer). Not sure I like the different behavior depending on compiler version. Would there be any issues with requiring Go 1.7 to build go-connections?

@dmcgowan
Copy link
Contributor Author

I just realized this package was being used here. Originally added here (https://github.com/docker/docker/tree/master/pkg/tlsconfig) but realized that package is not used. Without the alternative Docker builds will fail on less than 1.7. The "_other" is intended to be more of a catch all rather than an alternate implementation and using it will be no better and no worse than what you get today.

@aaronlehmann
Copy link

Yes but I think it's a bad idea to have different behavior depending which compiler version you used.

@stevvooe
Copy link
Contributor

Ech. This go-connections should really be merged back into docker.

@dmcgowan
Copy link
Contributor Author

@aaronlehmann I tried to design it such that the behavior for pre-1.7 is the same as the behavior if the system certs fail to load. The go version build flags were added for exactly this reason, not sure why it is a bad idea to use them, I agree they should be avoided when possible.

@stevvooe I didn't agree with it getting separated and wouldn't mind it going back into docker. I believe it was split out to avoid a repository cyclical dependency for docker-api. Considering these packages don't differ in scope from any of the other docker/pkg packages, it would make sense to keep them together. Should create a separate issue for that so at least this can move forward since it is to unlock a user facing improvement.

@stevvooe
Copy link
Contributor

@dmcgowan So, I've moved some other items over to pkg/tlsconfig in moby/moby#26436. My biggest problem with this package is that the interface split is arbitrary. Ironically, engine-api doesn't even use these to resolve the tlsconfig.

@dnephin
Copy link
Contributor

dnephin commented Sep 16, 2016

The go version build flags were added for exactly this reason, not sure why it is a bad idea to use them

I agree. Since the behaviour in pre-go1.7 is a fallback, how about printing a warning when it's called?

func SystemCertPool() *x509.CertPool {
certpool, err := x509.SystemCertPool()
if err != nil {
return x509.NewCertPool()

Choose a reason for hiding this comment

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

Wondering if this should error, otherwise it's essentially a silent failure, which could result in unexpected behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can check for the windows ourselves here to avoid calling this when using windows, see https://golang.org/src/crypto/x509/cert_pool.go?s=730:770#L22. In that case we would still end up calling NewCertPool for windows.

// SystemCertPool returns an new empty cert pool,
// accessing system cert pool is supported in go 1.7
func SystemCertPool() *x509.CertPool {
return x509.NewCertPool()

Choose a reason for hiding this comment

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

Should we instead be trying to manually read from the default system pool locations to mimic the 1.7 behaviour manually?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying to avoid forking code from the standard library here. This implementation is just to keep it compilable on other systems, official builds should use 1.7.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's possible if we change the interface to return an error, we can just return an error here when not on windows let the caller decide whether to use x509.NewCertPool() instead. At least in that case we can have output in the debug logs that the pool was not merged with the system pool.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dmcgowan We can log a warning here.

Defaults to getting empty cert pool when less than go 1.7
or on fails to load on Windows. Logs a warning when an empty
cert pool is returned.

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
@dmcgowan
Copy link
Contributor Author

dmcgowan commented Oct 27, 2016

@stevvooe @dnephin added a warning whenever an empty cert pool is returned.

@endophage if the system certificate pool fails to load on a non-windows system then it will return the error. Windows will always return an error for x509.SystemCertPool(), I still call it get the error messaging for the warn statement but return an empty pool.

@endophage
Copy link

Sounds good

Copy link

@endophage endophage left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM

@icecrime icecrime merged commit f512407 into docker:master Oct 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants