Skip to content

Commit d628447

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 a3fc533 commit d628447

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

templates/mongoshrc.js.erb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ 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
26-
} else {
27-
throw("Unknown error :" + err)
26+
if (err.message.match(/not running with --replSet/)) {
27+
return false
2828
}
29+
throw("Unknown error :" + err)
30+
}
2931
}
3032
}
3133

0 commit comments

Comments
 (0)