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

feat(NODE-5566): add ability to provide CRL file via tlsCRLFile #3834

Merged
merged 9 commits into from Aug 22, 2023

Conversation

durran
Copy link
Member

@durran durran commented Aug 22, 2023

Description

Adds the ability to provide a CRL file as an option in the connection string or client options.

What is changing?

  • Adds a new option, tlsCRLFile, that takes a string as a path to the crl.pem.
  • Refactors a bit of TLS testing variable names.
Is there new documentation needed for these changes?

Yes, TLS options should be updated.

What is the motivation for this change?

NODE-5549/NODE-5566

Release Highlight

Users may now provide a CRL file name as a client option.

For users wanting to provide a TLS client revokation list as a filename and not a Buffer, a new option tlsCRLFile has been added and can be provided in either the connection string or as a MongoClient option.

new MongoClient('mongodb://localhost:27017/db?tls=true&tlsCRLFile=path/to/crl.pem'); // option in connection string.
new MongoClient('mongodb://localhost:27017/db', { tls: true, tlsCRLFile: 'path/to/crl.pem' }) // option in client options.

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@@ -636,8 +636,6 @@ functions:
export PROJECT_DIRECTORY="$(pwd)"
export NODE_LTS_VERSION=${NODE_LTS_VERSION}
export DRIVERS_TOOLS="${DRIVERS_TOOLS}"
export SSL_CA_FILE="${SSL_CA_FILE}"
Copy link
Member Author

Choose a reason for hiding this comment

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

These are actually not defined but set up in run-tls-tests.sh so I removed them from here.

@@ -4,7 +4,8 @@ set -o errexit # Exit the script with error if any of the commands fail

source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"

export SSL_KEY_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/client.pem"
export SSL_CA_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem"
export TLS_KEY_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/client.pem"
Copy link
Member Author

Choose a reason for hiding this comment

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

Just renamed while here to align with us preferring "tls" over "ssl".

@@ -790,7 +795,7 @@ export interface MongoOptions
* | nodejs native option | driver spec equivalent option name | driver option type |
* |:----------------------|:----------------------------------------------|:-------------------|
* | `ca` | `tlsCAFile` | `string` |
* | `crl` | N/A | `string` |
* | `crl` | `tlsCRLFile` | `string` |
Copy link
Member Author

Choose a reason for hiding this comment

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

It's not really a spec option but didn't want to create another column in the table just for the one option.

@@ -114,6 +115,29 @@ describe('TLS Support', function () {
});
});

context('when providing tlsCRLFile', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't have a CRL in drivers-tools that wouldn't reject the CA we have, so just have an integration test for the failure. Looked at the Python driver and they do the same.

@durran durran marked this pull request as ready for review August 22, 2023 13:47
@durran durran changed the title feat(NODE-5549): add ability to provide crl file feat(NODE-5566): add ability to provide crl file Aug 22, 2023
@nbbeeken nbbeeken self-requested a review August 22, 2023 17:06
@nbbeeken nbbeeken self-assigned this Aug 22, 2023
@nbbeeken nbbeeken added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Aug 22, 2023
nbbeeken
nbbeeken previously approved these changes Aug 22, 2023
@nbbeeken nbbeeken changed the title feat(NODE-5566): add ability to provide crl file feat(NODE-5566): add ability to provide CRL file via tlsCRLFile Aug 22, 2023
@nbbeeken nbbeeken added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Aug 22, 2023
@W-A-James W-A-James self-requested a review August 22, 2023 17:18
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add an assertion to the

when client has been opened and closed more than once
	should only read files once

test that checks that the the crl file is read exactly once?

Relevant block should be at line 61

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated but needed to split them out for when the connection would succeed and fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good on the test restructuring but I more so meant that we want to guarantee that no matter how many times we call connect, we only read in each of these files once. I added another comment directly on the assertions I'm making reference to.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I just caught that and added the other test as well.

Copy link
Contributor

@W-A-James W-A-James Aug 22, 2023

Choose a reason for hiding this comment

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

Can you update the Note on tlsCAFile and tlsCertificateKeyFile to also mention that tlsCRLFile also has the same behaviour.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

Comment on lines +80 to +81
expect((await fs.stat(TLS_CA_FILE)).atime).to.deep.equal(caFileAccessTime);
expect((await fs.stat(TLS_CERT_KEY_FILE)).atime).to.deep.equal(certKeyFileAccessTime);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add assertions similar to these for the CRL file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

Good on the test restructuring but I more so meant that we want to guarantee that no matter how many times we call connect, we only read in each of these files once. I added another comment directly on the assertions I'm making reference to.

@durran durran requested a review from W-A-James August 22, 2023 18:06
Copy link
Contributor

@W-A-James W-A-James left a comment

Choose a reason for hiding this comment

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

Parse error in test/manual/tls_support.test.ts but otherwise LGTM

@durran
Copy link
Member Author

durran commented Aug 22, 2023

Parse error in test/manual/tls_support.test.ts but otherwise LGTM

Fixed.

@durran durran requested a review from W-A-James August 22, 2023 18:40
nbbeeken
nbbeeken previously approved these changes Aug 22, 2023
W-A-James
W-A-James previously approved these changes Aug 22, 2023
@durran durran dismissed stale reviews from W-A-James and nbbeeken via 9448075 August 22, 2023 19:25
it('should only read files once', async () => {
await client.connect();
await client.close();
context('when the connection will fail', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do these tests mean? I interpret them as "when the TLS settings are misconfigured" (resulting in the call to connect to fail. And the first test does demonstrate this.

But what about the second? I'd expect the call to connect on line 109 to throw, if the client were misconfigured, and that the test would fail. How is it passing?

Copy link
Member Author

Choose a reason for hiding this comment

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

The connection will fail here because the CRL will cause a revokation. The second was failing - I just fixed that test.

@durran durran requested a review from nbbeeken August 22, 2023 20:39
@nbbeeken nbbeeken merged commit 33c86c9 into main Aug 22, 2023
22 of 26 checks passed
@nbbeeken nbbeeken deleted the NODE-5549 branch August 22, 2023 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
4 participants