From b78da1f2a386e6c427b204efeb31e155bc8c32ec Mon Sep 17 00:00:00 2001 From: lordrobincbz Date: Sat, 21 Dec 2024 16:22:07 +0100 Subject: [PATCH] fix(config.inc.php/docker-entrypoint.sh,dockerfile,helpers.php): Move TLS logic from entrypoint to php configuration files --- apache/Dockerfile | 1 + apache/config.inc.php | 44 +++++++++++++++++++++++++ apache/docker-entrypoint.sh | 64 ------------------------------------- apache/helpers.php | 43 +++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 64 deletions(-) create mode 100644 apache/helpers.php diff --git a/apache/Dockerfile b/apache/Dockerfile index 2984356..dfae652 100644 --- a/apache/Dockerfile +++ b/apache/Dockerfile @@ -140,6 +140,7 @@ RUN set -ex; \ # Copy configuration COPY config.inc.php /etc/phpmyadmin/config.inc.php +COPY helpers.php /etc/phpmyadmin/helpers.php RUN chown www-data:www-data -R /etc/phpmyadmin/ # Copy main script diff --git a/apache/config.inc.php b/apache/config.inc.php index 693a715..74e5085 100644 --- a/apache/config.inc.php +++ b/apache/config.inc.php @@ -1,6 +1,9 @@ /etc/phpmyadmin/config.user.inc.php fi -if [ ! -z "${PMA_SSL_CA_BASE64}" ]; then - mkdir -p /etc/phpmyadmin/ssl - echo "Adding the custom pma-ssl-ca from base64." - echo "${PMA_SSL_CA_BASE64}" | base64 -d > /etc/phpmyadmin/ssl/pma-ssl-ca.pem - export "PMA_SSL_CA"="/etc/phpmyadmin/ssl/pma-ssl-ca.pem" -fi - -if [ ! -z "${PMA_SSL_KEY_BASE64}" ]; then - mkdir -p /etc/phpmyadmin/ssl - echo "Adding the custom pma-ssl-key from base64." - echo "${PMA_SSL_KEY_BASE64}" | base64 -d > /etc/phpmyadmin/ssl/pma-ssl-key.key - export "PMA_SSL_KEY"="/etc/phpmyadmin/ssl/pma-ssl-key.key" -fi - -if [ ! -z "${PMA_SSL_CERT_BASE64}" ]; then - mkdir -p /etc/phpmyadmin/ssl - echo "Adding the custom pma-ssl-cert from base64." - echo "${PMA_SSL_CERT_BASE64}" | base64 -d > /etc/phpmyadmin/ssl/pma-ssl-cert.pem - export "PMA_SSL_CERT"="/etc/phpmyadmin/ssl/pma-ssl-cert.pem" -fi - -if [ ! -z "${PMA_SSL_CAS_BASE64}" ]; then - echo "Adding multiples custom pma-ssl-ca from base64." - PMA_SSL_CAS=$(generate_ssl_files "${PMA_SSL_CAS_BASE64}" "CA" "pem") - export "PMA_SSL_CAS" -fi - -if [ ! -z "${PMA_SSL_KEYS_BASE64}" ]; then - echo "Adding multiples custom pma-ssl-key from base64." - PMA_SSL_KEYS=$(generate_ssl_files "${PMA_SSL_KEYS_BASE64}" "CERT" "cert") - export "PMA_SSL_KEYS" -fi - -if [ ! -z "${PMA_SSL_CERTS_BASE64}" ]; then - echo "Adding multiples custom pma-ssl-cert from base64." - PMA_SSL_CERTS=$(generate_ssl_files "${PMA_SSL_CERTS_BASE64}" "KEY" "key") - export "PMA_SSL_CERTS" -fi - # start: Apache specific settings if [ -n "${APACHE_PORT+x}" ]; then echo "Setting apache port to ${APACHE_PORT}." @@ -89,31 +50,6 @@ get_docker_secret() { fi } -# This function generates SSL files from a base64 encoded string. -# Arguments: -# 1. base64_string: A comma-separated string of base64 encoded SSL files. -# 2. prefix: A prefix to be used in the output file names. -# 3. extension: The file extension to be used for the output files. -# The function creates a directory for the SSL files, decodes each base64 string, -# writes the decoded content to a file, and returns a comma-separated list of the generated file paths. -# -generate_ssl_files() { - local base64_string="${1}" - local output_dir="/etc/phpmyadmin/ssl" - mkdir -p "${output_dir}" - IFS=',' read -ra FILES <<< "${base64_string}" - local counter=1 - local ssl_files="" - for file in "${FILES[@]}"; do - local output_file="${output_dir}/pma-ssl-${2}-${counter}.${3}" - echo "${file}" | base64 -d > "${output_file}" - ssl_files="${ssl_files}${output_file}," - counter=$((counter + 1)) - done - ssl_files="${ssl_files%,}" - echo "${ssl_files}" -} - get_docker_secret PMA_USER get_docker_secret PMA_PASSWORD get_docker_secret MYSQL_ROOT_PASSWORD diff --git a/apache/helpers.php b/apache/helpers.php new file mode 100644 index 0000000..54d2942 --- /dev/null +++ b/apache/helpers.php @@ -0,0 +1,43 @@ +