Skip to content

Commit 621060e

Browse files
committed
Use a more suitable method of detecting if authentication is needed
The `db.serverCmdLineOpts()` method always requires authentication when auth is enabled. It doesn't take the `enableLocalAuthBypass` parameter into account, the subsequent authentication attempt always fails if a user doesn't exists. This commit switches to the `rs.status()` method, as that method does take the `enableLocalAuthBypass` parameter into account and allows us to obtain a shell before with authentication enabled, but before the user exists.
1 parent 5e21678 commit 621060e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

templates/mongoshrc.js.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function rsReconfigSettings(settings){
1919
<% if @auth and @store_creds -%>
2020
function authRequired() {
2121
try {
22-
return db.serverCmdLineOpts().ok != 1;
22+
return rs.status().ok != 1;
2323
} catch (err) {
2424
if (err.message.match(/requires authentication/) || err.message.match(/not authorized on admin/)) {
2525
return true

0 commit comments

Comments
 (0)