-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 support for config file option 'cafile' #736
Conversation
@chlunde Thanks! Do you mind adding an integration test for this feature? |
Wouldn't it be better to make Yarn use the OS TLS trust store instead of adding an option? |
I'm not sure if this the same error, but... on our custom registry we need to set I also get |
@sindresorhus Having nodejs, not Yarn, use the OS trust store by default would be a good thing in the long run. There's some information related to that issue here: https://www.happyassassin.net/2015/01/12/a-note-about-ssltls-trusted-certificate-stores-and-platforms/ But I think a change like this would be required anyway if someone uses a self-signed certificate or cannot add the registry CA to the default trust store for some other reason. |
There might not be any way around this, true. Just want to recommend being careful about adding options. It's usually better if it just works. Now users must know to set the |
@@ -118,6 +123,12 @@ export default class RequestManager { | |||
if (opts.httpsProxy != null) { | |||
this.httpsProxy = opts.httpsProxy; | |||
} | |||
|
|||
if (opts.cafile != null && opts.cafile != '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! Would you mind adding a short comment here explaining what this does and how it works?
@kittens @cpojer Thanks for the comments, I've updated the PR with integration tests. I added support for comments between the certificates (like used by https://curl.haxx.se/docs/caextract.html), and no longer throw an exception if the file is missing, because yarn config set cafile "correctpath" was not working when the current cafile was missing. Issues:
fails with
|
I've updated the PR to address my own comments, except for the "nocache" query parameter in the mock which I've kept. The branch |
Summary
With a private registry using a company CA issued certificate, yarn fails because nodejs does not use the OS SSL/TLS trust store (at least on Linux). The same issue affects registries using self signed certificates and might also apply for the public registries in companies using SSL/TLS intercepting proxies.
This is change adds support for the
cafile
-option, which should point to a file path containing one or more PEM files concatenated together, like innpm
.I've chosen
cafile
and not theca
option, because it is simpler to point to the operating system TLS trust store, which often will already have the correct CA certificates for corporate computers.This does not add support for disabling strict-ssl, because that will open for MITM attacks.
References #606, #631
Test plan
_Integration test_
I've added a test which sets up a web server with a self signed certificate and a trust store containing a normal CA and the self signed certificate, and verifies that a connection set up using RequestManager can perform a GET-request from that server.
_Manual test_
With default config an no cafile set, I get following stack trace:
With
cafile=/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
in.npmrc
orcafile /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
in.yarnrc
installation succeeds