diff --git a/tools/install_demo_configuration.bat b/tools/install_demo_configuration.bat index d9d30fea2b..2d5a83dc3c 100755 --- a/tools/install_demo_configuration.bat +++ b/tools/install_demo_configuration.bat @@ -17,6 +17,7 @@ set "assumeyes=0" set "initsecurity=0" set "cluster_mode=0" set "skip_updates=-1" +set "use_default_admin_password=0" goto :GETOPTS @@ -27,6 +28,7 @@ echo -y confirm all installation dialogues automatically echo -i initialize Security plugin with default configuration (default is to ask if -y is not given) echo -c enable cluster mode by binding to all network interfaces (default is to ask if -y is not given) echo -s skip updates if config is already applied to opensearch.yml +echo -p to set default admin password as 'admin' for non-production environment (default requires user to set it up manually) EXIT /B 0 :GETOPTS @@ -35,6 +37,7 @@ if /I "%1" == "-y" set "assumeyes=1" if /I "%1" == "-i" set "initsecurity=1" if /I "%1" == "-c" set "cluster_mode=1" if /I "%1" == "-s" set "skip_updates=0" +if /I "%1" == "-p" set "use_default_admin_password=1" shift if not "%1" == "" goto :GETOPTS @@ -331,16 +334,24 @@ dir %OPENSEARCH_CONF_DIR% echo "what is in the password file" type "%ADMIN_PASSWORD_FILE%" - -if "%initialAdminPassword%" NEQ "" ( - set "ADMIN_PASSWORD=!initialAdminPassword!" +if "%use_default_admin_password%"=="1" ( + set "ADMIN_PASSWORD=admin" ) else ( - for /f %%a in ('type "%ADMIN_PASSWORD_FILE%"') do set "ADMIN_PASSWORD=%%a" + if "%initialAdminPassword%" NEQ "" ( + set "ADMIN_PASSWORD=%initialAdminPassword%" + ) else ( + for /f "delims=" %%a in ('type "%ADMIN_PASSWORD_FILE%"') do ( + set "ADMIN_PASSWORD=%%a" + goto breakloop + ) + ) ) +:breakloop + if not defined ADMIN_PASSWORD ( - echo Unable to find the admin password for the cluster. Please set initialAdminPassword or create a file %ADMIN_PASSWORD_FILE% with a single line that contains the password. - exit /b 1 + echo Unable to find the admin password for the cluster. Please set initialAdminPassword or create a file %ADMIN_PASSWORD_FILE% with a single line that contains the password. + exit /b 1 ) echo " ***************************************************" diff --git a/tools/install_demo_configuration.sh b/tools/install_demo_configuration.sh index 01bc1bfed1..1b67e8f050 100755 --- a/tools/install_demo_configuration.sh +++ b/tools/install_demo_configuration.sh @@ -29,6 +29,7 @@ assumeyes=0 initsecurity=0 cluster_mode=0 skip_updates=-1 +USE_DEFAULT_ADMIN_PASSWORD=0 function show_help() { echo "install_demo_configuration.sh [-y] [-i] [-c]" @@ -37,9 +38,10 @@ function show_help() { echo " -i initialize Security plugin with default configuration (default is to ask if -y is not given)" echo " -c enable cluster mode by binding to all network interfaces (default is to ask if -y is not given)" echo " -s skip updates if config is already applied to opensearch.yml" + echo " -p to set default admin password as 'admin' for non-production environment (default requires user to set it up manually)" } -while getopts "h?yics" opt; do +while getopts "h?yicsp" opt; do case "$opt" in h|\?) show_help @@ -52,6 +54,9 @@ while getopts "h?yics" opt; do c) cluster_mode=1 ;; s) skip_updates=0 + ;; + p) USE_DEFAULT_PASSWORD=1 + ;; esac done @@ -392,13 +397,18 @@ echo 'plugins.security.system_indices.indices: [".plugins-ml-config", ".plugins- ADMIN_PASSWORD_FILE="$OPENSEARCH_CONF_DIR/initialAdminPassword.txt" INTERNAL_USERS_FILE="$OPENSEARCH_CONF_DIR/opensearch-security/internal_users.yml" -if [[ -n "$initialAdminPassword" ]]; then - ADMIN_PASSWORD="$initialAdminPassword" -elif [[ -f "$ADMIN_PASSWORD_FILE" && -s "$ADMIN_PASSWORD_FILE" ]]; then - ADMIN_PASSWORD=$(head -n 1 "$ADMIN_PASSWORD_FILE") +if [[ $USE_DEFAULT_ADMIN_PASSWORD -eq 1 ]]; then + echo "Skipping the admin password setup for the cluster, and setting up the default admin password as 'admin'." + ADMIN_PASSWORD="admin" else - echo "Unable to find the admin password for the cluster. Please run 'export initialAdminPassword=' or create a file $ADMIN_PASSWORD_FILE with a single line that contains the password." - exit 1 + if [[ -n "$initialAdminPassword" ]]; then + ADMIN_PASSWORD="$initialAdminPassword" + elif [[ -f "$ADMIN_PASSWORD_FILE" && -s "$ADMIN_PASSWORD_FILE" ]]; then + ADMIN_PASSWORD=$(head -n 1 "$ADMIN_PASSWORD_FILE") + else + echo "Unable to find the admin password for the cluster. Please run 'export initialAdminPassword=' or create a file $ADMIN_PASSWORD_FILE with a single line that contains the password." + exit 1 + fi fi echo " ***************************************************"