Skip to content

Commit 4ebdb0f

Browse files
authored
feat: add support for --tlsUseSystemCA flag COMPASS-4105 (#1205)
1 parent 7131140 commit 4ebdb0f

25 files changed

+196
-104
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ variable. For detailed instructions for each of our supported platforms, please
6060
--tlsCertificateSelector [arg] TLS Certificate in system store (Windows and macOS only)
6161
--tlsCRLFile [arg] Specifies the .pem file that contains the Certificate Revocation List
6262
--tlsDisabledProtocols [arg] Comma separated list of TLS protocols to disable [TLS1_0,TLS1_1,TLS1_2]
63+
--tlsUseSystemCA Load the operating system trusted certificate list
6364
6465
API version options:
6566

package-lock.json

Lines changed: 15 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"@typescript-eslint/parser": "^4.28.4",
100100
"aws-sdk": "^2.674.0",
101101
"axios": "^0.21.1",
102-
"boxednode": "^1.10.5",
102+
"boxednode": "^1.10.6",
103103
"browserify": "^16.5.0",
104104
"chai": "^4.2.0",
105105
"command-exists": "^1.2.9",

packages/build/src/compile/signable-compiler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ export class SignableCompiler {
7373
path: await findModulePath('service-provider-server', 'os-dns-native'),
7474
requireRegexp: /\bos_dns_native\.node$/
7575
};
76+
// Warning! Until https://jira.mongodb.org/browse/MONGOSH-990,
77+
// packages/service-provider-server *also* has a copy of these.
78+
// We use the versions included in packages/cli-repl here, so these
79+
// should be kept in sync!
7680
const winCAAddon = process.platform === 'win32' ? {
7781
path: await findModulePath('cli-repl', 'win-export-certificate-and-key'),
7882
requireRegexp: /\bwin_export_cert\.node$/

packages/cli-repl/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ CLI interface for [MongoDB Shell][mongosh], an extension to Node.js REPL with Mo
4141
--tlsAllowInvalidCertificates Allow connections to servers with invalid certificates
4242
--tlsCertificateSelector [arg] TLS Certificate in system store (Windows and macOS only)
4343
--tlsDisabledProtocols [arg] Comma separated list of TLS protocols to disable [TLS1_0,TLS1_1,TLS1_2]
44+
--tlsUseSystemCA Load the operating system trusted certificate list
4445
4546
API version options:
4647

packages/cli-repl/package-lock.json

Lines changed: 18 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli-repl/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
"moment": "^2.29.1"
8383
},
8484
"optionalDependencies": {
85-
"macos-export-certificate-and-key": "^1.0.2",
86-
"win-export-certificate-and-key": "^1.0.4",
85+
"macos-export-certificate-and-key": "^1.1.1",
86+
"win-export-certificate-and-key": "^1.1.1",
8787
"get-console-process-list": "^1.0.4"
8888
}
8989
}

packages/cli-repl/src/arg-mapper.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CommonErrors, MongoshInvalidInputError, MongoshUnimplementedError } from '@mongosh/errors';
2-
import { CliOptions, MongoClientOptions } from '@mongosh/service-provider-server';
2+
import { CliOptions, DevtoolsConnectOptions } from '@mongosh/service-provider-server';
33
import setValue from 'lodash.set';
44

55
/**
@@ -29,6 +29,7 @@ const MAPPINGS = {
2929
tlsCRLFile: 'sslCRL',
3030
tlsCertificateKeyFile: 'tlsCertificateKeyFile',
3131
tlsCertificateKeyFilePassword: 'tlsCertificateKeyFilePassword',
32+
tlsUseSystemCA: 'useSystemCA',
3233
username: 'auth.username',
3334
verbose: { opt: 'loggerLevel', val: 'debug' }
3435
};
@@ -45,8 +46,8 @@ function isExistingMappingKey(key: string, options: CliOptions): key is keyof ty
4546
*
4647
* @returns {} The driver options.
4748
*/
48-
function mapCliToDriver(options: CliOptions): MongoClientOptions {
49-
const nodeOptions: MongoClientOptions = {};
49+
function mapCliToDriver(options: CliOptions): DevtoolsConnectOptions {
50+
const nodeOptions: DevtoolsConnectOptions = {};
5051
for (const cliOption of Object.keys(MAPPINGS)) {
5152
if (isExistingMappingKey(cliOption, options)) {
5253
const mapping = MAPPINGS[cliOption as keyof typeof MAPPINGS];

packages/cli-repl/src/arg-parser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const OPTIONS = {
6969
'tlsAllowInvalidCertificates',
7070
'tlsAllowInvalidHostnames',
7171
'tlsFIPSMode',
72+
'tlsUseSystemCA',
7273
'verbose',
7374
'version'
7475
],

packages/cli-repl/src/cli-repl.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { MongoshInternalError, MongoshRuntimeError, MongoshWarning } from '@mong
22
import { redactURICredentials } from '@mongosh/history';
33
import i18n from '@mongosh/i18n';
44
import { bson, AutoEncryptionOptions } from '@mongosh/service-provider-core';
5-
import { CliOptions, CliServiceProvider, MongoClientOptions } from '@mongosh/service-provider-server';
5+
import { CliOptions, CliServiceProvider, DevtoolsConnectOptions } from '@mongosh/service-provider-server';
66
import { SnippetManager } from '@mongosh/snippet-manager';
77
import { Editor } from '@mongosh/editor';
88
import { redactSensitiveData } from '@mongosh/history';
@@ -159,10 +159,10 @@ class CliRepl implements MongoshIOProvider {
159159
* information, external editor, and finally start the repl.
160160
*
161161
* @param {string} driverUri - The driver URI.
162-
* @param {MongoClientOptions} driverOptions - The driver options.
162+
* @param {DevtoolsConnectOptions} driverOptions - The driver options.
163163
*/
164164
// eslint-disable-next-line complexity
165-
async start(driverUri: string, driverOptions: MongoClientOptions): Promise<void> {
165+
async start(driverUri: string, driverOptions: DevtoolsConnectOptions): Promise<void> {
166166
const { version } = require('../package.json');
167167
await this.verifyNodeVersion();
168168

@@ -451,9 +451,9 @@ class CliRepl implements MongoshIOProvider {
451451
* Connect to the cluster.
452452
*
453453
* @param {string} driverUri - The driver URI.
454-
* @param {MongoClientOptions} driverOptions - The driver options.
454+
* @param {DevtoolsConnectOptions} driverOptions - The driver options.
455455
*/
456-
async connect(driverUri: string, driverOptions: MongoClientOptions): Promise<CliServiceProvider> {
456+
async connect(driverUri: string, driverOptions: DevtoolsConnectOptions): Promise<CliServiceProvider> {
457457
if (!this.cliOptions.nodb && !this.cliOptions.quiet) {
458458
this.output.write(i18n.__(CONNECTING) + '\t\t' + this.clr(redactURICredentials(driverUri), 'mongosh:uri') + '\n');
459459
}
@@ -523,11 +523,11 @@ class CliRepl implements MongoshIOProvider {
523523
/**
524524
* Is the password missing from the options?
525525
*
526-
* @param {MongoClientOptions} driverOptions - The driver options.
526+
* @param {DevtoolsConnectOptions} driverOptions - The driver options.
527527
*
528528
* @returns {boolean} If the password is missing.
529529
*/
530-
isPasswordMissingOptions(driverOptions: MongoClientOptions): boolean {
530+
isPasswordMissingOptions(driverOptions: DevtoolsConnectOptions): boolean {
531531
return !!(
532532
driverOptions.auth &&
533533
driverOptions.auth.username &&
@@ -556,7 +556,7 @@ class CliRepl implements MongoshIOProvider {
556556
* object is present with a truthy username. This is required by the driver, e.g.
557557
* in the case of password-less Kerberos authentication.
558558
*/
559-
ensurePasswordFieldIsPresentInAuth(driverOptions: MongoClientOptions): void {
559+
ensurePasswordFieldIsPresentInAuth(driverOptions: DevtoolsConnectOptions): void {
560560
if (driverOptions.auth && driverOptions.auth.username && !('password' in driverOptions.auth)) {
561561
driverOptions.auth.password = undefined;
562562
}
@@ -566,7 +566,7 @@ class CliRepl implements MongoshIOProvider {
566566
* Require the user to enter a password.
567567
*
568568
* @param {string} driverUrl - The driver URI.
569-
* @param {MongoClientOptions} driverOptions - The driver options.
569+
* @param {DevtoolsConnectOptions} driverOptions - The driver options.
570570
*/
571571
async requirePassword(): Promise<string> {
572572
const passwordPromise = askpassword({

0 commit comments

Comments
 (0)