From b35a6dcf8385a1d144d3464a72228640af66d92e Mon Sep 17 00:00:00 2001 From: Sasidharan Ekambavanan Date: Tue, 20 Feb 2024 14:13:57 +0530 Subject: [PATCH] [bitnami/mongodb-sharded] Update libmongodb.sh : mongodb_is_primary_node_up() function : grep check to find if mongod instance changed from secondary to primary (#55910) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update libmongodb.sh : mongodb_is_primary_node_up() function : grep check to find if mongod instance changed from secondary to primary In the Bitnami script file libmongodb.sh, in mongodb_is_primary_node_up(), the grep chec to see if the MongoDB instance has turned from secondary to primary has bug. Reason : The problem is in the line grep -q "true" <<<"$result". As part of the $result output, MongoDB gives a connection string which also has the string "true". Hence even when it is secondary, i.e. output of db.isMaster().ismaster is false, the grep -q "true" <<<"$result" check passes and it proceeds to create the root user. When it tries to create a root user during the secondary state, the root user creation fails. In faster systems, it turns into primary quickly and this bug in the code doesn't matter. Changing the grep check into a more specific one like the following helps to check if the mongodb instance turns into primary and then the root user gets created successfully and Authentication passes. grep -q "\[direct: primary\] admin> true" <<<"$result" Signed-off-by: Sasidharan Ekambavanan * Update libmongodb.sh Changing grep check to a more generic one to support any string within [direct: ] Signed-off-by: Sasidharan Ekambavanan * Update libmongodb.sh Fixing typo. Signed-off-by: Sasidharan Ekambavanan * Update bitnami/mongodb-sharded/7.0/debian-11/rootfs/opt/bitnami/scripts/libmongodb.sh Signed-off-by: Gonzalo Gómez Gracia --------- Signed-off-by: Sasidharan Ekambavanan Signed-off-by: Gonzalo Gómez Gracia Co-authored-by: Gonzalo Gómez Gracia --- .../7.0/debian-11/rootfs/opt/bitnami/scripts/libmongodb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitnami/mongodb-sharded/7.0/debian-11/rootfs/opt/bitnami/scripts/libmongodb.sh b/bitnami/mongodb-sharded/7.0/debian-11/rootfs/opt/bitnami/scripts/libmongodb.sh index 7a6b5c08647b..ad0a0b15edb6 100644 --- a/bitnami/mongodb-sharded/7.0/debian-11/rootfs/opt/bitnami/scripts/libmongodb.sh +++ b/bitnami/mongodb-sharded/7.0/debian-11/rootfs/opt/bitnami/scripts/libmongodb.sh @@ -1052,7 +1052,7 @@ mongodb_is_primary_node_up() { db.isMaster().ismaster EOF ) - grep -q "true" <<<"$result" + grep -qE ".*\[direct:\s?\S+\]\s+admin>\s+true" <<<"$result" } ########################