Skip to content

Commit 21c0aaa

Browse files
authored
fix(cli-repl): do not require password for GSSAPI authentication MONGOSH-899 (#1022)
1 parent 93c22ee commit 21c0aaa

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

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

+17-2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class CliRepl {
127127
if (this.isPasswordMissing(driverOptions)) {
128128
await this.requirePassword(driverUri, driverOptions);
129129
}
130+
this.ensurePasswordFieldIsPresentInAuth(driverOptions);
130131

131132
if (!this.cliOptions.quiet) {
132133
this.output.write(`Current Mongosh Log ID:\t${this.logId}\n`);
@@ -393,9 +394,23 @@ class CliRepl {
393394
* @returns {boolean} If the password is missing.
394395
*/
395396
isPasswordMissing(driverOptions: MongoClientOptions): boolean {
396-
return !!(driverOptions.auth &&
397+
return !!(
398+
driverOptions.auth &&
397399
driverOptions.auth.username &&
398-
!driverOptions.auth.password);
400+
!driverOptions.auth.password &&
401+
driverOptions.authMechanism !== 'GSSAPI' // no need for a password for Kerberos
402+
);
403+
}
404+
405+
/**
406+
* Sets the auth.password field to undefined in the driverOptions if the auth
407+
* object is present with a truthy username. This is required by the driver, e.g.
408+
* in the case of password-less Kerberos authentication.
409+
*/
410+
ensurePasswordFieldIsPresentInAuth(driverOptions: MongoClientOptions): void {
411+
if (driverOptions.auth && driverOptions.auth.username && !('password' in driverOptions.auth)) {
412+
driverOptions.auth.password = undefined;
413+
}
399414
}
400415

401416
/**

0 commit comments

Comments
 (0)