From a8060b77748142e5a0089cd20c59938d406e217b Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Thu, 24 Oct 2024 12:15:08 +0200 Subject: [PATCH] Decoupling the admin_password from proxysql --- manifests/app_type.pp | 2 -- templates/application/complete_reinstall.erb.sh | 9 ++++++++- templates/application/docker-compose_nextcloud.yml.erb | 2 -- templates/multinode/complete_reinstall.erb.sh | 9 ++++++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/manifests/app_type.pp b/manifests/app_type.pp index 698a311..b377c8a 100644 --- a/manifests/app_type.pp +++ b/manifests/app_type.pp @@ -15,7 +15,6 @@ define sunetdrive::app_type ( # The config used $config = $override_config # Other settings - $admin_password = $config[ 'admin_password' ] $dbhost = $config[ 'dbhost' ] $dbname = $config[ 'dbname' ] $dbuser = $config[ 'dbuser' ] @@ -31,7 +30,6 @@ define sunetdrive::app_type ( $config = hiera_hash($environment) $skeletondirectory = $config['skeletondirectory'] # Other settings - $admin_password = safe_hiera('admin_password') $dbhost = 'proxysql_proxysql_1' $dbname = 'nextcloud' $dbuser = 'nextcloud' diff --git a/templates/application/complete_reinstall.erb.sh b/templates/application/complete_reinstall.erb.sh index ec43c88..18914b1 100644 --- a/templates/application/complete_reinstall.erb.sh +++ b/templates/application/complete_reinstall.erb.sh @@ -3,7 +3,6 @@ config_php='/var/www/html/config/config.php' dbhost="<%= @dbhost %>" mysql_user_password="<%= @mysql_user_password %>" -admin_password="<%= @admin_password %>" location="<%= @location %>" bucket="<%= @s3_bucket %>" @@ -14,6 +13,9 @@ if [[ "${user_input}" == "IKnowWhatIAmDoing" ]]; then echo "WARNING: This will delete everything in the database and reinstall Nextcloud." echo "You have 10 seconds to abort by hitting CTRL/C" sleep 10s + echo "Setting temp admin password" + apt update && apt install -y apg + admin_password="$(apg -m 40 | head -1)" echo "Ok, proceeding." echo "Dropping database in 3 seconds" sleep 3s @@ -48,6 +50,11 @@ EOF instanceid=$(grep -E "^ 'instanceid'" ${config_php} | awk -F "'" '{print $4}') secret=$(grep -E "^ 'secret'" ${config_php} | awk -F "'" '{print $4}') passwordsalt=$(grep -E "^ 'passwordsalt'" ${config_php} | awk -F "'" '{print $4}') + echo "Now delete the admin user:" + echo " occ user:delete admin" + echo "and then create a new admin user:" + echo " /usr/local/bin/add_admin_user " + echo "" echo "Please use edit-secrets to add these variables to all Nextcloud servers:" echo "instanceid: DEC::PKCS7[${instanceid}]!" echo "secret: DEC::PKCS7[${secret}]!" diff --git a/templates/application/docker-compose_nextcloud.yml.erb b/templates/application/docker-compose_nextcloud.yml.erb index 0936df0..6ca5473 100644 --- a/templates/application/docker-compose_nextcloud.yml.erb +++ b/templates/application/docker-compose_nextcloud.yml.erb @@ -9,8 +9,6 @@ services: <%- if @hostnet -%> network_mode: host <%- end -%> - environment: - - NC_PASS=<%= @admin_password%> volumes: - /opt/nextcloud/000-default.conf:/etc/apache2/sites-enabled/000-default.conf - /opt/nextcloud/mpm_prefork.conf:/etc/apache2/mods-available/mpm_prefork.conf diff --git a/templates/multinode/complete_reinstall.erb.sh b/templates/multinode/complete_reinstall.erb.sh index e448a0f..3e35175 100644 --- a/templates/multinode/complete_reinstall.erb.sh +++ b/templates/multinode/complete_reinstall.erb.sh @@ -3,10 +3,12 @@ config_php='/var/www/html/config/config.php' dbhost="<%= @dbhost %>" mysql_user_password="<%= @mysql_user_password %>" -admin_password="<%= @admin_password %>" location="<%= @location %>" bucket="<%= @s3_bucket %>" customer="<%= @customer %>" +echo "Setting temp admin password" +apt update && apt install -y apg +admin_password="$(apg -m 40 | head -1)" /usr/bin/mysql -e "drop database nextcloud" -u nextcloud -p"${mysql_user_password}" -h "${dbhost}" >/dev/null 2>&1 /usr/bin/mysql -e "create database nextcloud" -u nextcloud -p"${mysql_user_password}" -h "${dbhost}" >/dev/null 2>&1 @@ -35,6 +37,11 @@ EOF instanceid=$(grep -E "^ 'instanceid'" ${config_php} | awk -F "'" '{print $4}') secret=$(grep -E "^ 'secret'" ${config_php} | awk -F "'" '{print $4}') passwordsalt=$(grep -E "^ 'passwordsalt'" ${config_php} | awk -F "'" '{print $4}') +echo "Now delete the admin user:" +echo " occ user:delete admin" +echo "and then create a new admin user:" +echo " /usr/local/bin/add_admin_user " +echo "" echo "${customer}_instanceid: DEC::PKCS7[${instanceid}]!" echo "${customer}_secret: DEC::PKCS7[${secret}]!" echo "${customer}_passwordsalt: DEC::PKCS7[${passwordsalt}]!"