-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat(NODE-3924)!: read tls files async #3776
Conversation
src/connection_string.ts
Outdated
target: 'caFileName', | ||
type: 'string' |
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.
Can change this to not redirect to caFileName
test/unit/mongo_client.test.js
Outdated
* | `tlsCAFile` | `tlsCAFile` | `string` | | ||
* | `crl` | N/A | `string` | | ||
* | `tlsCertificateKeyFile` | `tlsCertificateKeyFile` | `string` | |
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 shouldn't be changed, right?
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.
I may have misinterpreted what this table is for. I though the leftmost column corresponded to the option as it exists in node driver and the second column was the spec compliant option name. Is it actually the case that the leftmost column corresponds to node's internal tls options?
src/mongo_client.ts
Outdated
if (!options.ca && typeof options.tlsCAFile === 'string' && options.tlsCAFile.length > 0) { | ||
options.ca = await fs.readFile(options.tlsCAFile, { encoding: 'utf8' }); | ||
} |
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.
I have two related cleanups here (these apply to tlsCertificateKeyFile
too)
first, we can use the nullish coelescing assignment operator here to avoid checking !options.ca
:
if (typeof options.tlsCAFile === 'string' && options.tlsCAFile.length > 0) {
options.ca ??= await fs.readFile(options.tlsCAFile, { encoding: 'utf8' });
}
second, I'm not sure we should be checking options.tlsCAFile.length
(even though the AC says to). the user must manually provide the filepath, and if we receive an empty string, the user's configuration is likely messed up. We should probably alert the user that we received an empty file path instead of silently ignoring it. Attempting to read from a file named "" will throw an error, so that was the old behavior.
If we do decide to ignore empty strings, I suggest we move the logic into the options parser. The requirement for these options would actually be "a non-empty string", instead of just "a string", so that should be codified in the options parsing and tested there.
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.
Your suggestion to handle empty file names in option parsing is more user friendly as far as catching bad config is concerned, so that's the solution I'd prefer as well.
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.
Daria wrote the ticket and included "ignore empty filenames" as an AC. Can you ask her why that was included?
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.
IIRC we wanted to have a nicer experience for environment variables being the source of the file name which can be set to an empty string as a way of clearing the value. I do not feel strongly, if we do ignore the empty string wouldn't TLS be misconfigured and fail? Is there a scenario where a server with TLS configured allows a client without TLS to connect? Also happy with keeping the behavior as it was (validate string and not length)
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.
Well, in both cases it fails to connect, but if we throw ourselves it's a much more actionable error than a generic connection error.
Did we have a specific environment / usecase / testing variant we wanted this for?
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.
Is there a scenario where a server with TLS configured allows a client without TLS to connect?
Not sure what impact that has here, but sure, the server’s TLS mode can be disabled
, allowTLS
, preferTLS
, requireTLS
, and two of these are modes where the server accepts connections with or without TLS.
Co-authored-by: Bailey Pearson <[email protected]>
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.
One comment about how we should error. And there's slack thread about aligning on "empty" vs "unset".
Description
What is changing?
connection string options
tlsCAFile
andtlsCertificateKeyFile
options to store the file names and defer reading to first invocation ofMongoClient.connect
tlsCAFile
ortlsCertificateKeyFile
MongoClient
MongoClient.constructor
andMongoClient.connect
to storeoptions.tlsCAFile
andoptions.tlsCertificateKeyFile
on construction and read them intooptions.ca
andoptions.key
respectively on connect.TLS support test
TLS support test evergreen task and mocha config
Updatedrun tls tests
evergreen task to timeout in 10sAPI docs
tlsCertificateKeyFile
andtlsCAFile
are readIs there new documentation needed for these changes?
Yes, docs ticket has been generated.
What is the motivation for this change?
NODE-3924
Release Highlight
TLS certificate authority and certificate-key files are now read asynchronously
In this release, we have updated the
MongoClient
to store the file names provided to the existingtlsCAFile
andtlsCertificateKeyFile
options and only read these files the first time it connects. Prior to this change, the files were read synchronously onMongoClient
construction.Note: This has no effect on driver functionality when TLS configuration files are properly specified. However, if there are any issues with the TLS configuration files (invalid file name), the error is now thrown when the
MongoClient
is connected instead of at construction time.Take a look at our TLS documentation for more information on the
tlsCAFile
andtlsCertificateKeyFile
options.Double check the following
npm run check:lint
scripttype(NODE-xxxx)[!]: description
feat(NODE-1234)!: rewriting everything in coffeescript