[bitnami/solr] Check if basic auth is already enabled before trying to create the user (#28689)

[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 <janos.grasl@gmail.com>
This commit is contained in:
János Grásl
2023-04-05 13:41:46 +02:00
committed by GitHub
parent a49d0a217b
commit 89e5528f12
@@ -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
}