From 89e5528f124b7356fcca962a674c0844a1ca15a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Gr=C3=A1sl?= Date: Wed, 5 Apr 2023 13:41:46 +0200 Subject: [PATCH] [bitnami/solr] Check if basic auth is already enabled before trying to create the user (#28689) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [bitnami/solr] Check if basic auth is already enabled before trying to create the user. We have encountered the same issue as the following issue: https://github.com/bitnami/charts/issues/15356 In our case we run a multinode solr cloud with zookeper. If the cluster was already initialized and basic auth is configured in zk for solr cloud, auth enable cannot run again. In our case a disaster recovery happened and tried to rejoin the node with a new volume into the cluster, the lib tries to create the admin user, but get exit code 1 executing auth enable because solr responds auth is already enabled please disable it first. Because of this the script exits with error and the node never recovers. At the init phase we can get the security.json from zk and check if solr.BasicAuthPlugin already included or not and only create the user if basicAuth is not included yet altough it's the startup of the cluster. Signed-off-by: János Grásl --- .../rootfs/opt/bitnami/scripts/libsolr.sh | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/bitnami/solr/9/debian-11/rootfs/opt/bitnami/scripts/libsolr.sh b/bitnami/solr/9/debian-11/rootfs/opt/bitnami/scripts/libsolr.sh index 90a598d0937f..473b5b2b0a47 100644 --- a/bitnami/solr/9/debian-11/rootfs/opt/bitnami/scripts/libsolr.sh +++ b/bitnami/solr/9/debian-11/rootfs/opt/bitnami/scripts/libsolr.sh @@ -285,6 +285,31 @@ solr_wait_for_api() { fi } +######################### +# Check if SOLR Cloud auth is already enabled +# Globals: +# SOLR_* +# Arguments: +# None +# Returns: +# Boolean +######################### +solr_auth_already_enabled() { + local temp_file_name="/tmp/zk-security.json" + local -r exec="${SOLR_BIN_DIR}/solr" + local command_args=("zk" "cp" "zk:/solr/security.json" "$temp_file_name" "-z" "$SOLR_ZK_HOSTS") + debug "Checking if auth already enabled in ZK" + + "$exec" "${command_args[@]}" + + local result=1 + if grep -q solr.BasicAuthPlugin "$temp_file_name"; then + result=0 + fi + rm "$temp_file_name" + return $result +} + ######################### # Create SOLR cloud user # Globals: @@ -303,11 +328,15 @@ solr_create_cloud_user() { info "Creating user: ${username}" - if ! debug_execute "$exec" "${command_args[@]}"; then - error "There was an error when creating the user" - exit 1 + if ! solr_auth_already_enabled; then + if ! debug_execute "$exec" "${command_args[@]}"; then + error "There was an error when creating the user" + exit 1 + else + info "User created" + fi else - info "User created" + info "Skipping. Security is already enabled." fi }