From 1ac52bd057c4094e89048e153635908b90acb245 Mon Sep 17 00:00:00 2001 From: BilliAlpha Date: Fri, 8 Jul 2022 14:41:21 +0200 Subject: [PATCH 1/2] Return both host and container config dir --- functions | 5 +++-- subcommands/enable | 8 +++++--- subcommands/revoke | 8 +++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/functions b/functions index 79fa4f3..6791ae7 100755 --- a/functions +++ b/functions @@ -188,8 +188,9 @@ letsencrypt_configure_and_get_dir() { # store config settings echo "--http.port :$acme_port $config" >"$config_dir/config" - # re-implement entire path to respect mapped DOKKU_ROOT when running in a container - echo "$DOKKU_HOST_ROOT/$app/letsencrypt/certs/$config_hash" + # send both host and container path + # to respect mapped DOKKU_ROOT when running in a container + echo "$DOKKU_HOST_ROOT/$app/letsencrypt/certs/$config_hash:$config_dir" } letsencrypt_get_email() { diff --git a/subcommands/enable b/subcommands/enable index 90ef987..3f5e150 100755 --- a/subcommands/enable +++ b/subcommands/enable @@ -84,8 +84,10 @@ letsencrypt_acme() { dokku_log_info1 "Getting letsencrypt certificate for ${app}..." # read arguments from appropriate config file into the config array - config_dir="$(letsencrypt_configure_and_get_dir "$app" "$acme_port")" - read -r -a config <"$config_dir/config" + config_dirs="$(letsencrypt_configure_and_get_dir "$app" "$acme_port")" + host_config_dir="$(echo "$config_dirs" | cut -d: -f1)" + container_config_dir="$(echo "$config_dirs" | cut -d: -f2)" + read -r -a config <"$container_config_dir/config" # run letsencrypt as a docker container using "certonly" mode # port 80 of the standalone webserver will be forwarded by the proxy @@ -95,7 +97,7 @@ letsencrypt_acme() { docker run --rm \ --user $DOKKU_UID:$DOKKU_GID \ -p "$acme_port:$acme_port" \ - -v "$config_dir:/certs" \ + -v "$host_config_dir:/certs" \ "${PLUGIN_IMAGE}:${PLUGIN_IMAGE_VERSION}" \ "${config[@]}" run | sed "s/^/ /" diff --git a/subcommands/revoke b/subcommands/revoke index 4f96277..d27bc82 100755 --- a/subcommands/revoke +++ b/subcommands/revoke @@ -17,8 +17,10 @@ letsencrypt_acme_revoke() { local acme_port=$(get_available_port) # read arguments from appropriate config file into the config array - local config_dir="$(letsencrypt_configure_and_get_dir "$app" "$acme_port")" - read -r -a config <"$config_dir/config" + config_dirs="$(letsencrypt_configure_and_get_dir "$app" "$acme_port")" + host_config_dir="$(echo "$config_dirs" | cut -d: -f1)" + container_config_dir="$(echo "$config_dirs" | cut -d: -f2)" + read -r -a config <"$container_config_dir/config" # run letsencrypt as a docker container using "certonly" mode # port 80 of the standalone webserver will be forwarded by the proxy @@ -28,7 +30,7 @@ letsencrypt_acme_revoke() { docker run --rm \ --user $DOKKU_UID:$DOKKU_GID \ -p "$acme_port:$acme_port" \ - -v "$config_dir:/certs" \ + -v "$host_config_dir:/certs" \ "${PLUGIN_IMAGE}:${PLUGIN_IMAGE_VERSION}" \ "${config[@]}" revoke | sed "s/^/ /" From 71af85fef2769164c6cef7b9ce8f6300539a65bc Mon Sep 17 00:00:00 2001 From: BilliAlpha Date: Mon, 11 Jul 2022 22:48:14 +0200 Subject: [PATCH 2/2] Fix missing config_dir references Fixes #271 --- subcommands/enable | 2 +- subcommands/revoke | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/subcommands/enable b/subcommands/enable index 3f5e150..f06f6a4 100755 --- a/subcommands/enable +++ b/subcommands/enable @@ -115,7 +115,7 @@ letsencrypt_acme() { # got certificate dokku_log_info1 "Certificate retrieved successfully." - letsencrypt_link "$app" "$config_dir" + letsencrypt_link "$app" "$container_config_dir" nginx_build_config "$app" } diff --git a/subcommands/revoke b/subcommands/revoke index d27bc82..b4094d7 100755 --- a/subcommands/revoke +++ b/subcommands/revoke @@ -50,11 +50,11 @@ letsencrypt_acme_revoke() { local domain="$(get_app_domains "$app" | xargs | awk '{print $1}')" # move revoked certificates away - mv -f "$config_dir/certificates/$domain.crt" "$config_dir/certificates/$domain.crt.revoked" - mv -f "$config_dir/certificates/$domain.issuer.crt" "$config_dir/certificates/$domain.issuer.crt" - mv -f "$config_dir/certificates/$domain.key" "$config_dir/certificates/$domain.key" - mv -f "$config_dir/certificates/$domain.key" "$config_dir/certificates/$domain.key" - mv -f "$config_dir/certificates/$domain.pem" "$config_dir/certificates/key.pem.revoked" + mv -f "$container_config_dir/certificates/$domain.crt" "$container_config_dir/certificates/$domain.crt.revoked" + mv -f "$container_config_dir/certificates/$domain.issuer.crt" "$container_config_dir/certificates/$domain.issuer.crt" + mv -f "$container_config_dir/certificates/$domain.key" "$container_config_dir/certificates/$domain.key" + mv -f "$container_config_dir/certificates/$domain.key" "$container_config_dir/certificates/$domain.key" + mv -f "$container_config_dir/certificates/$domain.pem" "$container_config_dir/certificates/key.pem.revoked" # removing the certificate will automatically reconfigure nginx if [[ -z $DOKKU_APP_NAME ]]; then