From 5d5e949f92dda5fd9d8678255a7aaa0e9c93d720 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 6 Nov 2024 16:23:12 +0000 Subject: [PATCH] More sso fixes and clean up --- bin/installapp-sso | 2 +- lib/authelia.sh | 27 ++++++++--------- lib/bookstack.sh | 29 ++++++++---------- lib/espocrm.sh | 26 ++++++++-------- lib/gitea.sh | 25 ++++++++-------- lib/jitsi.sh | 75 +++++++++++++--------------------------------- lib/mail.sh | 14 ++++----- lib/matrix.sh | 32 ++++++++++---------- lib/roundcube.sh | 29 ++++++++---------- lib/wordpress.sh | 40 +++++++++++-------------- 10 files changed, 125 insertions(+), 174 deletions(-) diff --git a/bin/installapp-sso b/bin/installapp-sso index eded594..b69a23c 100755 --- a/bin/installapp-sso +++ b/bin/installapp-sso @@ -1,4 +1,4 @@ -#!/bin/bash -x +#!/bin/bash # # Installs SSO on app . /etc/federated diff --git a/lib/authelia.sh b/lib/authelia.sh index 7a1ef6b..e0c31f2 100644 --- a/lib/authelia.sh +++ b/lib/authelia.sh @@ -6,7 +6,7 @@ PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sb get_appvars config_authelia() { - echo -ne "\n* Configuring /federated/apps/authelia container.." + echo -ne "* Configuring authelia container.." if [ ! -d "/federated/apps/authelia" ]; then mkdir -p /federated/apps/authelia/data/config @@ -49,13 +49,13 @@ tr -cd '[:alnum:]' < /dev/urandom | fold -w "64" | head -n 1 > /federated/apps/a tr -cd '[:alnum:]' < /dev/urandom | fold -w "64" | head -n 1 > /federated/apps/authelia/data/secrets/STORAGE_ENCRYPTION_KEY echo "$LDAP_SECRET" > /federated/apps/authelia/data/secrets/AUTHENTICATION_BACKEND_LDAP_PASSWORD echo "$ADMINPASS" > /federated/apps/authelia/data/secrets/NOTIFIER_SMTP_PASSWORD -openssl genrsa -out /federated/apps/authelia/data/secrets/private.pem 4096 -openssl rsa -in /federated/apps/authelia/data/secrets/private.pem -outform PEM -pubout -out /federated/apps/authelia/data/secrets/public.pem +openssl genrsa -out /federated/apps/authelia/data/secrets/private.pem 4096 2>/dev/null +openssl rsa -in /federated/apps/authelia/data/secrets/private.pem -outform PEM -pubout -out /federated/apps/authelia/data/secrets/public.pem 2>/dev/null POWERDNS_CLIENT_SECRET=$(create_password); -POWERDNS_CLIENT_SECRET_HASH=$(docker run -it --rm authelia/authelia:latest authelia crypto hash generate pbkdf2 --password $POWERDNS_CLIENT_SECRET | awk '{ print $2 }') +POWERDNS_CLIENT_SECRET_HASH=$(docker run -it --rm authelia/authelia:latest authelia crypto hash generate pbkdf2 --password $POWERDNS_CLIENT_SECRET 2>/dev/null | awk '{ print $2 }') [[ -d "/federated/apps/pdnsmysql/data/var/lib/mysql/pdnsadmin" ]] && POWERDNS_DB="pdnsadmin" || POWERDNS_DB="pdns" -NEXTCLOUD_CLIENT_SECRET=$(create_password); -NEXTCLOUD_CLIENT_SECRET_HASH=$(docker run -it --rm authelia/authelia:latest authelia crypto hash generate pbkdf2 --password $NEXTCLOUD_CLIENT_SECRET | awk '{ print $2 }') +#NEXTCLOUD_CLIENT_SECRET=$(create_password); +#NEXTCLOUD_CLIENT_SECRET_HASH=$(docker run -it --rm authelia/authelia:latest authelia crypto hash generate pbkdf2 --password $NEXTCLOUD_CLIENT_SECRET | awk '{ print $2 }') cat > /federated/apps/authelia/.env < /dev/null [ $? -ne 0 ] && fail "Couldn't add dns record for authelia" - # If extra_hosts doesn't exist then insert extra_host configuration in pdnsadmin - [[ ! $(grep extra_hosts /federated/apps/pdnsadmin/docker-compose.yml 2>/dev/null) ]] && sed -i "/192.168.0.12/a \ extra_hosts:\n\ - \"authelia.$DOMAIN:$EXTERNALIP\"" /federated/apps/pdnsadmin/docker-compose.yml + # If extra_hosts doesn't exist then insert extra_host configuration in pdnsadmin docker compose + add_authelia_config_to_dockercompose "pdnsadmin" # Stop and start pdnsadmin for internal dns externalhosts to work - /federated/bin/stop pdnsadmin - /federated/bin/start pdnsadmin + run_command "/federated/bin/stop pdnsadmin" + run_command "/federated/bin/start pdnsadmin" - echo -ne "done." + echo -ne "done.\n" } uninstall_authelia() { echo -ne "* Uninstalling authelia container.." - spin & - SPINPID=$! # First stop the service cd /federated/apps/authelia && docker-compose -f docker-compose.yml -p authelia down &> /dev/null @@ -234,6 +232,5 @@ uninstall_authelia() { # Delete the DNS record docker exec pdns pdnsutil delete-rrset $DOMAIN authelia A - kill -9 $SPINPID &> /dev/null echo -ne "done.\n" } diff --git a/lib/bookstack.sh b/lib/bookstack.sh index bb708bf..ff3a0ba 100644 --- a/lib/bookstack.sh +++ b/lib/bookstack.sh @@ -6,7 +6,7 @@ PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sb get_appvars config_bookstack() { - echo -ne "\n* Configuring bookstack container.." + echo -ne "* Configuring bookstack container.." if [ ! -d "/federated/apps/bookstack" ]; then mkdir -p /federated/apps/bookstack/data/config @@ -81,8 +81,8 @@ start_bookstack() { docker exec pdns pdnsutil add-record $DOMAIN documentation A 86400 $EXTERNALIP &> /dev/null [ $? -ne 0 ] && fail "Couldn't add dns record for bookstack" - docker exec pdnsmysql mysql -ubookstack -p$BOOKSTACK_SECRET bookstack -e "delete from users where email = 'admin@admin.com';" - docker exec bookstack php /app/www/artisan bookstack:create-admin --email="admin@$DOMAIN" --name="Admin" --password="$ADMINPASS" + docker exec pdnsmysql mysql -ubookstack -p$BOOKSTACK_SECRET bookstack -e "delete from users where email = 'admin@admin.com';" &> /dev/null + docker exec bookstack php /app/www/artisan bookstack:create-admin --email="admin@$DOMAIN" --name="Admin" --password="$ADMINPASS" &> /dev/null # Set mail configuration sed -i "s#MAIL_FROM=.*#MAIL_FROM=admin@$DOMAIN#g" /federated/apps/bookstack/data/config/www/.env @@ -93,13 +93,10 @@ start_bookstack() { sed -i "s#MAIL_PASSWORD=.*#MAIL_PASSWORD=$ADMINPASS#g" /federated/apps/bookstack/data/config/www/.env sed -i "s#MAIL_ENCRYPTION=.*#MAIL_ENCRYPTION=TLS#g" /federated/apps/bookstack/data/config/www/.env - kill -9 $SPINPID &> /dev/null echo -ne "done.\n" } email_bookstack() { echo -ne "* Sending email to customer.." - spin & - SPINPID=$! cat > /federated/apps/mail/data/root/certs/mailfile < @@ -171,13 +168,10 @@ EOF docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Application installed on $DOMAIN\" $EMAIL < /root/certs/mailfile" rm /federated/apps/mail/data/root/certs/mailfile - kill -9 $SPINPID &> /dev/null echo -ne "done.\n" } uninstall_bookstack() { echo -ne "* Uninstalling bookstack container.." - spin & - SPINPID=$! # First stop the service cd /federated/apps/bookstack && docker-compose -f docker-compose.yml -p bookstack down &> /dev/null @@ -199,14 +193,15 @@ uninstall_bookstack() { if [[ $(grep "### Bookstack" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null) ]]; then sed -i '/### Bookstack/,/### /{/### PowerDNS/!{/### /!d}}' /federated/apps/authelia/data/config/idproviders.yml sed -i '/### Bookstack/d' /federated/apps/authelia/data/config/idproviders.yml - /federated/bin/stop authelia - /federated/bin/start authelia + run_command "/federated/bin/stop authelia" + run_command "/federated/bin/start authelia" fi - kill -9 $SPINPID &> /dev/null echo -ne "done.\n" } configsso_bookstack() { + echo -ne "* Configuring bookstack container with SSO.." + [ ! -d "/federated/apps/authelia" ] && failcheck "Authelia is not installed. You need this first before continuing." [ ! -f "/federated/apps/authelia/data/config/idproviders.yml" ] && failcheck "Authelia idproviders.yml is missing." [[ $(grep "### Bookstack" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null) ]] && failcheck "Authelia already has a Bookstack configuration." @@ -232,8 +227,8 @@ cat >> /federated/apps/authelia/data/config/idproviders.yml <> /federated/apps/bookstack/.env < /federated/apps/espocrm/.env < /federated/apps/mail/data/root/certs/mailfile < @@ -174,13 +172,10 @@ EOF docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Application installed on $DOMAIN\" $EMAIL < /root/certs/mailfile" rm /federated/apps/mail/data/root/certs/mailfile - kill -9 $SPINPID &> /dev/null echo -ne "done.\n" } uninstall_espocrm() { echo -ne "* Uninstalling espocrm container.." - spin & - SPINPID=$! # First stop the service cd /federated/apps/espocrm && docker-compose -f docker-compose.yml -p espocrm down &> /dev/null @@ -205,14 +200,15 @@ uninstall_espocrm() { if [[ $(grep "### Espocrm" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null) ]]; then sed -i '/### Espocrm/,/### /{/### PowerDNS/!{/### /!d}}' /federated/apps/authelia/data/config/idproviders.yml sed -i '/### Espocrm/d' /federated/apps/authelia/data/config/idproviders.yml - /federated/bin/stop authelia - /federated/bin/start authelia + run_command "/federated/bin/stop authelia" + run_command "/federated/bin/start authelia" fi - kill -9 $SPINPID &> /dev/null echo -ne "done.\n" } configsso_espocrm() { + echo -ne "* Configuring espocrm container with SSO.." + [ ! -d "/federated/apps/authelia" ] && failcheck "Authelia is not installed. You need this first before continuing." [ ! -f "/federated/apps/authelia/data/config/idproviders.yml" ] && failcheck "Authelia idproviders.yml is missing." [[ $(grep "### Espocrm" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null) ]] && failcheck "Authelia already has a Espocrm configuration." @@ -240,8 +236,8 @@ cat >> /federated/apps/authelia/data/config/idproviders.yml <> /federated/apps/espocrm/.env < /dev/null docker exec postgresql psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE gitea TO gitea" &> /dev/null -echo -ne "done." +echo -ne "done.\n" } email_gitea() { echo -ne "* Sending email to customer.." @@ -241,8 +241,6 @@ EOF } uninstall_gitea() { echo -ne "* Uninstalling gitea container.." - spin & - SPINPID=$! # First stop the service cd /federated/apps/gitea && docker-compose -f docker-compose.yml -p gitea down &> /dev/null @@ -264,11 +262,10 @@ uninstall_gitea() { if [[ $(grep "### Gitea" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null) ]]; then sed -i '/### Gitea/,/### /{/### PowerDNS/!{/### /!d}}' /federated/apps/authelia/data/config/idproviders.yml sed -i '/### Gitea/d' /federated/apps/authelia/data/config/idproviders.yml - /federated/bin/stop authelia - /federated/bin/start authelia + run_command "/federated/bin/stop authelia" + run_command "/federated/bin/start authelia" fi - kill -9 $SPINPID &> /dev/null echo -ne "done.\n" } start_gitea() { @@ -295,9 +292,11 @@ start_gitea() { # Remove creategitea.sh rm /federated/apps/gitea/data/data/creategitea.sh - echo -ne "done." + echo -ne "done.\n" } configsso_gitea() { + echo -ne "* Configuring gitea container with SSO.." + [ ! -d "/federated/apps/authelia" ] && failcheck "Authelia is not installed. You need this first before continuing." [ ! -f "/federated/apps/authelia/data/config/idproviders.yml" ] && failcheck "Authelia idproviders.yml is missing." [[ $(grep "### Gitea" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null) ]] && failcheck "Authelia already has a Gitea configuration." @@ -325,8 +324,8 @@ cat >> /federated/apps/authelia/data/config/idproviders.yml < /federated/apps/jitsi/.env <> /federated/apps/jitsi/.env <> /federated/apps/jitsi/.env <> /federated/apps/jitsi/.env <> /federated/apps/jitsi/.env <> /federated/apps/jitsi/.env <> /federated/apps/jitsi/.env <> /federated/apps/jitsi/.env <> /federated/apps/jitsi/.env < /federated/apps/mail/data/root/certs/mailfile < @@ -773,13 +740,10 @@ EOF docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Application installed on $DOMAIN\" $EMAIL < /root/certs/mailfile" rm /federated/apps/mail/data/root/certs/mailfile - kill -9 $SPINPID &> /dev/null echo -ne "done.\n" } uninstall_jitsi() { echo -ne "* Uninstalling jitsi container.." - spin & - SPINPID=$! # First stop the service cd /federated/apps/jitsi && docker-compose -f docker-compose.yml -p jitsi down &> /dev/null @@ -800,8 +764,8 @@ uninstall_jitsi() { if [[ $(grep "### Jitsi" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null) ]]; then sed -i '/### Jitsi/,/### /{/### PowerDNS/!{/### /!d}}' /federated/apps/authelia/data/config/idproviders.yml sed -i '/### Jitsi/d' /federated/apps/authelia/data/config/idproviders.yml - /federated/bin/stop authelia - /federated/bin/start authelia + run_command "/federated/bin/stop authelia" + run_command "/federated/bin/start authelia" fi if [[ -d "/federated/apps/jitsiopenid" ]]; then @@ -810,16 +774,17 @@ uninstall_jitsi() { docker image rm mod242/jitsi-go-openid:latest &> /dev/null fi - kill -9 $SPINPID &> /dev/null echo -ne "done.\n" } start_jitsi() { # Start service with command to make sure it's up before proceeding start_service "jitsi" "nc -z 192.168.0.25 443 &> /dev/null" "8" - echo -ne "done." + echo -ne "done.\n" } configsso_jitsi() { + echo -ne "* Configuring jitsi container with SSO.." + [ ! -d "/federated/apps/authelia" ] && failcheck "Authelia is not installed. You need this first before continuing." [ ! -f "/federated/apps/authelia/data/config/idproviders.yml" ] && failcheck "Authelia idproviders.yml is missing." [[ $(grep "### Jitsi" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null) ]] && failcheck "Authelia already has a Jitsi configuration." @@ -849,8 +814,8 @@ cat >> /federated/apps/authelia/data/config/idproviders.yml < /dev/null @@ -64,8 +64,8 @@ sed -i 's!args:!!g' /federated/apps/matrix/data/matrix/homeserver.yaml # Insert our Postgres and LDAP config cat >> /federated/apps/matrix/data/matrix/homeserver.yaml < /dev/null docker exec postgresql psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE matrix TO matrix" &> /dev/null -echo -ne "done." +echo -ne "done.\n" } start_matrix() { # Start service with command to make sure it's up before proceeding @@ -139,12 +139,10 @@ start_matrix() { docker exec pdns pdnsutil add-record $DOMAIN matrix A 86400 $EXTERNALIP &> /dev/null [ $? -ne 0 ] && fail "Couldn't add dns record for matrix" - echo -ne "done." + echo -ne "done.\n" } email_matrix() { echo -ne "* Sending email to customer.." - spin & - SPINPID=$! cat > /federated/apps/mail/data/root/certs/mailfile < @@ -216,13 +214,10 @@ EOF docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Application installed on $DOMAIN\" $EMAIL < /root/certs/mailfile" rm /federated/apps/mail/data/root/certs/mailfile - kill -9 $SPINPID &> /dev/null echo -ne "done.\n" } uninstall_matrix() { echo -ne "* Uninstalling matrix container.." - spin & - SPINPID=$! # First stop the service cd /federated/apps/matrix && docker-compose -f docker-compose.yml -p matrix down &> /dev/null @@ -244,14 +239,15 @@ uninstall_matrix() { if [[ $(grep "### Matrix" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null) ]]; then sed -i '/### Matrix/,/### /{/### PowerDNS/!{/### /!d}}' /federated/apps/authelia/data/config/idproviders.yml sed -i '/### Matrix/d' /federated/apps/authelia/data/config/idproviders.yml - /federated/bin/stop authelia - /federated/bin/start authelia + run_command "/federated/bin/stop authelia" + run_command "/federated/bin/start authelia" fi - kill -9 $SPINPID &> /dev/null echo -ne "done.\n" } configsso_matrix() { + echo -ne "* Configuring matrix container with SSO.." + [ ! -d "/federated/apps/authelia" ] && failcheck "Authelia is not installed. You need this first before continuing." [ ! -f "/federated/apps/authelia/data/config/idproviders.yml" ] && failcheck "Authelia idproviders.yml is missing." [[ $(grep "### Matrix" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null) ]] && failcheck "Authelia already has a Matrix configuration." @@ -277,8 +273,8 @@ cat >> /federated/apps/authelia/data/config/idproviders.yml < /dev/null [ $? -ne 0 ] && fail "Couldn't add dns record for roundcube" - kill -9 $SPINPID &> /dev/null echo -ne "done.\n" } email_roundcube() { echo -ne "* Sending email to customer.." - spin & - SPINPID=$! cat > /federated/apps/mail/data/root/certs/mailfile < @@ -108,13 +105,10 @@ EOF docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Application installed on $DOMAIN\" $EMAIL < /root/certs/mailfile" rm /federated/apps/mail/data/root/certs/mailfile - kill -9 $SPINPID &> /dev/null echo -ne "done.\n" } uninstall_roundcube() { echo -ne "* Uninstalling roundcube container.." - spin & - SPINPID=$! # First stop the service cd /federated/apps/roundcube && docker-compose -f docker-compose.yml -p roundcube down &> /dev/null @@ -137,14 +131,15 @@ uninstall_roundcube() { if [[ $(grep "### Roundcube" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null) ]]; then sed -i '/### Roundcube/,/### /{/### PowerDNS/!{/### /!d}}' /federated/apps/authelia/data/config/idproviders.yml sed -i '/### Roundcube/d' /federated/apps/authelia/data/config/idproviders.yml - /federated/bin/stop authelia - /federated/bin/start authelia + run_command "/federated/bin/stop authelia" + run_command "/federated/bin/start authelia" fi - kill -9 $SPINPID &> /dev/null echo -ne "done.\n" } configsso_roundcube() { + echo -ne "* Configuring roundcube container with SSO.." + [ ! -d "/federated/apps/authelia" ] && failcheck "Authelia is not installed. You need this first before continuing." [ ! -f "/federated/apps/authelia/data/config/idproviders.yml" ] && failcheck "Authelia idproviders.yml is missing." [[ $(grep "### Roundcube" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null) ]] && failcheck "Authelia already has a Roundcube configuration." @@ -171,8 +166,8 @@ cat >> /federated/apps/authelia/data/config/idproviders.yml < /dev/null - [ $? -ne 0 ] && fail "Couldn't add dns record" - docker exec pdns pdnsutil add-record $DOMAIN wordpress A 86400 $EXTERNALIP &> /dev/null - [ $? -ne 0 ] && fail "Couldn't add dns record" + run_command "/federated/bin/stop wordpress" + run_command "/federated/bin/start wordpress" + run_command "docker exec pdns pdnsutil add-record $DOMAIN www A 86400 $EXTERNALIP" + run_command "docker exec pdns pdnsutil add-record $DOMAIN wordpress A 86400 $EXTERNALIP" echo -ne "done.\n" } email_wordpress() { echo -ne "* Sending email to customer.." - spin & - SPINPID=$! cat > /federated/apps/mail/data/root/certs/mailfile < @@ -171,13 +167,10 @@ EOF docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Application installed on $DOMAIN\" $EMAIL < /root/certs/mailfile" rm /federated/apps/mail/data/root/certs/mailfile - kill -9 $SPINPID &> /dev/null echo -ne "done.\n" } uninstall_wordpress() { echo -ne "* Uninstalling wordpress container.." - spin & - SPINPID=$! # First stop the service cd /federated/apps/wordpress && docker-compose -f docker-compose.yml -p wordpress down &> /dev/null @@ -200,14 +193,15 @@ uninstall_wordpress() { if [[ $(grep "### Wordpress" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null) ]]; then sed -i '/### Wordpress/,/### /{/### PowerDNS/!{/### /!d}}' /federated/apps/authelia/data/config/idproviders.yml sed -i '/### Wordpress/d' /federated/apps/authelia/data/config/idproviders.yml - /federated/bin/stop authelia - /federated/bin/start authelia + run_command "/federated/bin/stop authelia" + run_command "/federated/bin/start authelia" fi - kill -9 $SPINPID &> /dev/null echo -ne "done.\n" } configsso_wordpress() { + echo -ne "* Configuring wordpress container with SSO.." + [ ! -d "/federated/apps/authelia" ] && failcheck "Authelia is not installed. You need this first before continuing." [ ! -f "/federated/apps/authelia/data/config/idproviders.yml" ] && failcheck "Authelia idproviders.yml is missing." [[ $(grep "### Wordpress" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null) ]] && failcheck "Authelia already has a Wordpress configuration." @@ -235,8 +229,8 @@ cat >> /federated/apps/authelia/data/config/idproviders.yml < /dev/null - docker exec wordpress wp plugin activate daggerhart-openid-connect-generic &> /dev/null + run_command "docker exec wordpress wp plugin install daggerhart-openid-connect-generic" + run_command "docker exec wordpress wp plugin activate daggerhart-openid-connect-generic" - /federated/bin/stop wordpress - /federated/bin/start wordpress + run_command "/federated/bin/stop wordpress" + run_command "/federated/bin/start wordpress" + + echo -ne "done.\n" }