From 5d01cebeab368a6f528570236fee454448a24297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Mar=C3=B3y?= Date: Fri, 30 Jul 2021 12:23:35 +0000 Subject: [PATCH] Implement docker secret handling for SMTP_PASSWORD (#1471) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Implement docker secret handling for SMTP_PASSWORD Signed-off-by: András Maróy * Runs update.sh Signed-off-by: András Maróy * Runs update.sh Signed-off-by: András Maróy * Runs update.sh Signed-off-by: András Maróy * Runs update.sh Signed-off-by: András Maróy * Runs update.sh Signed-off-by: András Maróy * Runs update.sh Signed-off-by: András Maróy * Runs update.sh Signed-off-by: András Maróy * Runs update.sh Signed-off-by: András Maróy * Runs update.sh Signed-off-by: András Maróy * Runs update.sh Signed-off-by: András Maróy * Runs update.sh Signed-off-by: András Maróy * Use `trim` instead of `rtrim` for `SMTP_PASSWORD_FILE` contents Signed-off-by: András Maróy * Runs update.sh Signed-off-by: András Maróy * Runs update.sh Co-authored-by: GitHub Workflow --- .config/smtp.config.php | 9 ++++++++- 20.0/apache/config/smtp.config.php | 9 ++++++++- 20.0/fpm-alpine/config/smtp.config.php | 9 ++++++++- 20.0/fpm/config/smtp.config.php | 9 ++++++++- 21.0/apache/config/smtp.config.php | 9 ++++++++- 21.0/fpm-alpine/config/smtp.config.php | 9 ++++++++- 21.0/fpm/config/smtp.config.php | 9 ++++++++- 22.0/apache/config/smtp.config.php | 9 ++++++++- 22.0/fpm-alpine/config/smtp.config.php | 9 ++++++++- 22.0/fpm/config/smtp.config.php | 9 ++++++++- README.md | 2 +- 11 files changed, 81 insertions(+), 11 deletions(-) diff --git a/.config/smtp.config.php b/.config/smtp.config.php index 59f1eaa1..62880e4b 100644 --- a/.config/smtp.config.php +++ b/.config/smtp.config.php @@ -8,8 +8,15 @@ if (getenv('SMTP_HOST') && getenv('MAIL_FROM_ADDRESS') && getenv('MAIL_DOMAIN')) 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', 'mail_smtpname' => getenv('SMTP_NAME') ?: '', - 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), 'mail_domain' => getenv('MAIL_DOMAIN'), ); + + if (getenv('SMTP_PASSWORD_FILE') && file_exists(getenv('SMTP_PASSWORD_FILE'))) { + $CONFIG['mail_smtppassword'] = trim(file_get_contents(getenv('SMTP_PASSWORD_FILE'))); + } elseif (getenv('SMTP_PASSWORD')) { + $CONFIG['mail_smtppassword'] = getenv('SMTP_PASSWORD'); + } else { + $CONFIG['mail_smtppassword'] = ''; + } } diff --git a/20.0/apache/config/smtp.config.php b/20.0/apache/config/smtp.config.php index 59f1eaa1..62880e4b 100644 --- a/20.0/apache/config/smtp.config.php +++ b/20.0/apache/config/smtp.config.php @@ -8,8 +8,15 @@ if (getenv('SMTP_HOST') && getenv('MAIL_FROM_ADDRESS') && getenv('MAIL_DOMAIN')) 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', 'mail_smtpname' => getenv('SMTP_NAME') ?: '', - 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), 'mail_domain' => getenv('MAIL_DOMAIN'), ); + + if (getenv('SMTP_PASSWORD_FILE') && file_exists(getenv('SMTP_PASSWORD_FILE'))) { + $CONFIG['mail_smtppassword'] = trim(file_get_contents(getenv('SMTP_PASSWORD_FILE'))); + } elseif (getenv('SMTP_PASSWORD')) { + $CONFIG['mail_smtppassword'] = getenv('SMTP_PASSWORD'); + } else { + $CONFIG['mail_smtppassword'] = ''; + } } diff --git a/20.0/fpm-alpine/config/smtp.config.php b/20.0/fpm-alpine/config/smtp.config.php index 59f1eaa1..62880e4b 100644 --- a/20.0/fpm-alpine/config/smtp.config.php +++ b/20.0/fpm-alpine/config/smtp.config.php @@ -8,8 +8,15 @@ if (getenv('SMTP_HOST') && getenv('MAIL_FROM_ADDRESS') && getenv('MAIL_DOMAIN')) 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', 'mail_smtpname' => getenv('SMTP_NAME') ?: '', - 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), 'mail_domain' => getenv('MAIL_DOMAIN'), ); + + if (getenv('SMTP_PASSWORD_FILE') && file_exists(getenv('SMTP_PASSWORD_FILE'))) { + $CONFIG['mail_smtppassword'] = trim(file_get_contents(getenv('SMTP_PASSWORD_FILE'))); + } elseif (getenv('SMTP_PASSWORD')) { + $CONFIG['mail_smtppassword'] = getenv('SMTP_PASSWORD'); + } else { + $CONFIG['mail_smtppassword'] = ''; + } } diff --git a/20.0/fpm/config/smtp.config.php b/20.0/fpm/config/smtp.config.php index 59f1eaa1..62880e4b 100644 --- a/20.0/fpm/config/smtp.config.php +++ b/20.0/fpm/config/smtp.config.php @@ -8,8 +8,15 @@ if (getenv('SMTP_HOST') && getenv('MAIL_FROM_ADDRESS') && getenv('MAIL_DOMAIN')) 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', 'mail_smtpname' => getenv('SMTP_NAME') ?: '', - 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), 'mail_domain' => getenv('MAIL_DOMAIN'), ); + + if (getenv('SMTP_PASSWORD_FILE') && file_exists(getenv('SMTP_PASSWORD_FILE'))) { + $CONFIG['mail_smtppassword'] = trim(file_get_contents(getenv('SMTP_PASSWORD_FILE'))); + } elseif (getenv('SMTP_PASSWORD')) { + $CONFIG['mail_smtppassword'] = getenv('SMTP_PASSWORD'); + } else { + $CONFIG['mail_smtppassword'] = ''; + } } diff --git a/21.0/apache/config/smtp.config.php b/21.0/apache/config/smtp.config.php index 59f1eaa1..62880e4b 100644 --- a/21.0/apache/config/smtp.config.php +++ b/21.0/apache/config/smtp.config.php @@ -8,8 +8,15 @@ if (getenv('SMTP_HOST') && getenv('MAIL_FROM_ADDRESS') && getenv('MAIL_DOMAIN')) 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', 'mail_smtpname' => getenv('SMTP_NAME') ?: '', - 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), 'mail_domain' => getenv('MAIL_DOMAIN'), ); + + if (getenv('SMTP_PASSWORD_FILE') && file_exists(getenv('SMTP_PASSWORD_FILE'))) { + $CONFIG['mail_smtppassword'] = trim(file_get_contents(getenv('SMTP_PASSWORD_FILE'))); + } elseif (getenv('SMTP_PASSWORD')) { + $CONFIG['mail_smtppassword'] = getenv('SMTP_PASSWORD'); + } else { + $CONFIG['mail_smtppassword'] = ''; + } } diff --git a/21.0/fpm-alpine/config/smtp.config.php b/21.0/fpm-alpine/config/smtp.config.php index 59f1eaa1..62880e4b 100644 --- a/21.0/fpm-alpine/config/smtp.config.php +++ b/21.0/fpm-alpine/config/smtp.config.php @@ -8,8 +8,15 @@ if (getenv('SMTP_HOST') && getenv('MAIL_FROM_ADDRESS') && getenv('MAIL_DOMAIN')) 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', 'mail_smtpname' => getenv('SMTP_NAME') ?: '', - 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), 'mail_domain' => getenv('MAIL_DOMAIN'), ); + + if (getenv('SMTP_PASSWORD_FILE') && file_exists(getenv('SMTP_PASSWORD_FILE'))) { + $CONFIG['mail_smtppassword'] = trim(file_get_contents(getenv('SMTP_PASSWORD_FILE'))); + } elseif (getenv('SMTP_PASSWORD')) { + $CONFIG['mail_smtppassword'] = getenv('SMTP_PASSWORD'); + } else { + $CONFIG['mail_smtppassword'] = ''; + } } diff --git a/21.0/fpm/config/smtp.config.php b/21.0/fpm/config/smtp.config.php index 59f1eaa1..62880e4b 100644 --- a/21.0/fpm/config/smtp.config.php +++ b/21.0/fpm/config/smtp.config.php @@ -8,8 +8,15 @@ if (getenv('SMTP_HOST') && getenv('MAIL_FROM_ADDRESS') && getenv('MAIL_DOMAIN')) 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', 'mail_smtpname' => getenv('SMTP_NAME') ?: '', - 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), 'mail_domain' => getenv('MAIL_DOMAIN'), ); + + if (getenv('SMTP_PASSWORD_FILE') && file_exists(getenv('SMTP_PASSWORD_FILE'))) { + $CONFIG['mail_smtppassword'] = trim(file_get_contents(getenv('SMTP_PASSWORD_FILE'))); + } elseif (getenv('SMTP_PASSWORD')) { + $CONFIG['mail_smtppassword'] = getenv('SMTP_PASSWORD'); + } else { + $CONFIG['mail_smtppassword'] = ''; + } } diff --git a/22.0/apache/config/smtp.config.php b/22.0/apache/config/smtp.config.php index 59f1eaa1..62880e4b 100644 --- a/22.0/apache/config/smtp.config.php +++ b/22.0/apache/config/smtp.config.php @@ -8,8 +8,15 @@ if (getenv('SMTP_HOST') && getenv('MAIL_FROM_ADDRESS') && getenv('MAIL_DOMAIN')) 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', 'mail_smtpname' => getenv('SMTP_NAME') ?: '', - 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), 'mail_domain' => getenv('MAIL_DOMAIN'), ); + + if (getenv('SMTP_PASSWORD_FILE') && file_exists(getenv('SMTP_PASSWORD_FILE'))) { + $CONFIG['mail_smtppassword'] = trim(file_get_contents(getenv('SMTP_PASSWORD_FILE'))); + } elseif (getenv('SMTP_PASSWORD')) { + $CONFIG['mail_smtppassword'] = getenv('SMTP_PASSWORD'); + } else { + $CONFIG['mail_smtppassword'] = ''; + } } diff --git a/22.0/fpm-alpine/config/smtp.config.php b/22.0/fpm-alpine/config/smtp.config.php index 59f1eaa1..62880e4b 100644 --- a/22.0/fpm-alpine/config/smtp.config.php +++ b/22.0/fpm-alpine/config/smtp.config.php @@ -8,8 +8,15 @@ if (getenv('SMTP_HOST') && getenv('MAIL_FROM_ADDRESS') && getenv('MAIL_DOMAIN')) 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', 'mail_smtpname' => getenv('SMTP_NAME') ?: '', - 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), 'mail_domain' => getenv('MAIL_DOMAIN'), ); + + if (getenv('SMTP_PASSWORD_FILE') && file_exists(getenv('SMTP_PASSWORD_FILE'))) { + $CONFIG['mail_smtppassword'] = trim(file_get_contents(getenv('SMTP_PASSWORD_FILE'))); + } elseif (getenv('SMTP_PASSWORD')) { + $CONFIG['mail_smtppassword'] = getenv('SMTP_PASSWORD'); + } else { + $CONFIG['mail_smtppassword'] = ''; + } } diff --git a/22.0/fpm/config/smtp.config.php b/22.0/fpm/config/smtp.config.php index 59f1eaa1..62880e4b 100644 --- a/22.0/fpm/config/smtp.config.php +++ b/22.0/fpm/config/smtp.config.php @@ -8,8 +8,15 @@ if (getenv('SMTP_HOST') && getenv('MAIL_FROM_ADDRESS') && getenv('MAIL_DOMAIN')) 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', 'mail_smtpname' => getenv('SMTP_NAME') ?: '', - 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), 'mail_domain' => getenv('MAIL_DOMAIN'), ); + + if (getenv('SMTP_PASSWORD_FILE') && file_exists(getenv('SMTP_PASSWORD_FILE'))) { + $CONFIG['mail_smtppassword'] = trim(file_get_contents(getenv('SMTP_PASSWORD_FILE'))); + } elseif (getenv('SMTP_PASSWORD')) { + $CONFIG['mail_smtppassword'] = getenv('SMTP_PASSWORD'); + } else { + $CONFIG['mail_smtppassword'] = ''; + } } diff --git a/README.md b/README.md index 53a1c2bb..f0501730 100644 --- a/README.md +++ b/README.md @@ -373,7 +373,7 @@ secrets: file: ./postgres_user.txt # put postgresql username to this file ``` -Currently, this is only supported for `NEXTCLOUD_ADMIN_PASSWORD`, `NEXTCLOUD_ADMIN_USER`, `MYSQL_DATABASE`, `MYSQL_PASSWORD`, `MYSQL_USER`, `POSTGRES_DB`, `POSTGRES_PASSWORD`, `POSTGRES_USER` and `REDIS_HOST_PASSWORD`. +Currently, this is only supported for `NEXTCLOUD_ADMIN_PASSWORD`, `NEXTCLOUD_ADMIN_USER`, `MYSQL_DATABASE`, `MYSQL_PASSWORD`, `MYSQL_USER`, `POSTGRES_DB`, `POSTGRES_PASSWORD`, `POSTGRES_USER`, `REDIS_HOST_PASSWORD` and `SMTP_PASSWORD`. # Make your Nextcloud available from the internet Until here, your Nextcloud is just available from your docker host. If you want your Nextcloud available from the internet adding SSL encryption is mandatory.