From 13ee0db80fd3cd2f30e1a950d3a8b7a334c4b418 Mon Sep 17 00:00:00 2001 From: maxmureev Date: Wed, 13 Mar 2024 20:50:34 +0700 Subject: [PATCH] Implement use.su option to use in bootstrap.conf - the option is parsed by the nifi-registry.sh script and uses '/bin/su' instead of 'sudo' if true. --- .../src/main/resources/bin/nifi-registry.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/nifi-registry/nifi-registry-core/nifi-registry-resources/src/main/resources/bin/nifi-registry.sh b/nifi-registry/nifi-registry-core/nifi-registry-resources/src/main/resources/bin/nifi-registry.sh index ef7619926c7b..e7a1e5a817d7 100644 --- a/nifi-registry/nifi-registry-core/nifi-registry-resources/src/main/resources/bin/nifi-registry.sh +++ b/nifi-registry/nifi-registry-core/nifi-registry-resources/src/main/resources/bin/nifi-registry.sh @@ -310,8 +310,23 @@ run() { run_nifi_registry_cmd="'${JAVA}' -cp '${BOOTSTRAP_CLASSPATH}' -Xms12m -Xmx24m ${BOOTSTRAP_DIR_PARAMS} org.apache.nifi.registry.bootstrap.RunNiFiRegistry $@" if [ -n "${run_as_user}" ]; then + preserve_environment=$(grep '^\s*preserve.environment' "${BOOTSTRAP_CONF}" | cut -d'=' -f2 | tr '[:upper:]' '[:lower:]') + use_su=$(grep '^\s*use.su' "${BOOTSTRAP_CONF}" | cut -d'=' -f2 | tr '[:upper:]' '[:lower:]') + + if [ "$use_su" = "true" ]; then + SUDO="/bin/su" + if [ "$preserve_environment" = "true" ]; then + echo "The use.su option is not supported with preserve.environment enabled for compatibility reasons. Exiting." + exit 1 + fi + else + SUDO="sudo -u" + if [ "$preserve_environment" = "true" ]; then + SUDO="sudo -E -u" + fi + fi # Provide SCRIPT_DIR and execute nifi-env for the run.as user command - run_nifi_registry_cmd="sudo -u ${run_as_user} sh -c \"SCRIPT_DIR='${SCRIPT_DIR}' && . '${SCRIPT_DIR}/nifi-registry-env.sh' && ${run_nifi_registry_cmd}\"" + run_nifi_registry_cmd="${SUDO} ${run_as_user} -s /bin/sh -c \"SCRIPT_DIR='${SCRIPT_DIR}' && . '${SCRIPT_DIR}/nifi-registry-env.sh' && ${run_nifi_registry_cmd}\"" fi if [ "$1" = "run" ]; then