Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix adding/deleting keys #31

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions commands
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ EOF

add_shared_key() {
check_install
if [[ ! -n "$2" ]]; then
if [[ -n "$SHARED_KEY_TO_ADD" ]]; then
echo $SHARED_KEY_TO_ADD >> "$SHARED_HOSTKEYS_FILE"
echo "Added $SHARED_KEY_TO_ADD to the list of shared hostkeys"
else
Expand All @@ -141,12 +141,12 @@ add_shared_key() {

delete_shared_keys() {
check_install
if [[ ! -n "$2" ]]; then
if [[ -n "$HOSTNAME_TO_REMOVE" ]]; then
ssh-keygen -f "$SHARED_HOSTKEYS_FILE" -R "$HOSTNAME_TO_REMOVE"
rm "$SHARED_HOSTKEYS_FOLDER/known_hosts.old"
echo "Deleted hostkey for $HOSTNAME_TO_REMOVE as well as the backup."
else
> $SHARED_HOSTKEYS_FILE
true > $SHARED_HOSTKEYS_FILE
echo "Emptied the shared hostkey file. All apps will loose the shared keys on next push. Make sure you add the required ones"
fi
}
Expand All @@ -165,7 +165,7 @@ add_app_key() {
check_app
check_exists
check_install_app
if [[ ! -n "$3" ]]; then
if [[ -n "$SHARED_KEY_TO_ADD_APP" ]]; then
echo $SHARED_KEY_TO_ADD_APP >> "$APP_SPECIFIC_HOSTKEYS_FILE"
echo "Added $SHARED_KEY_TO_ADD_APP to the list of shared hostkeys"
else
Expand All @@ -189,12 +189,12 @@ delete_app_keys() {
check_app
check_exists
check_install_app
if [[ -n "$3" ]]; then
if [[ -n "$HOSTNAME_TO_REMOVE_APP" ]]; then
ssh-keygen -f "$APP_SPECIFIC_HOSTKEYS_FILE" -R "$HOSTNAME_TO_REMOVE_APP"
rm "$APP_SPECIFIC_HOSTKEYS_FOLDER/known_hosts.old"
echo "Deleted hostkey for $HOSTNAME_TO_REMOVE as well as the backup."
else
> $APP_SPECIFIC_HOSTKEYS_FILE
true > $APP_SPECIFIC_HOSTKEYS_FILE
echo "Emptied the app specific hostkey file. Your app looses the specific keys on the next push. Make sure you add the required ones"
fi
}
Expand Down Expand Up @@ -227,11 +227,11 @@ case "$1" in
;;

hostkeys:shared:add)
add_shared_key "$@"
add_shared_key
;;

hostkeys:shared:delete)
delete_shared_keys "$@"
delete_shared_keys
;;

hostkeys:shared:autoadd)
Expand All @@ -243,11 +243,11 @@ case "$1" in
;;

hostkeys:app:add)
add_app_key "$@"
add_app_key
;;

hostkeys:app:delete)
delete_app_keys "$@"
delete_app_keys
;;

hostkeys:app:autoadd)
Expand Down
5 changes: 3 additions & 2 deletions pre-build
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
# shellcheck source=/dev/null
source "$PLUGIN_ENABLED_PATH/common/functions"
APP="$1"
IMAGE=$(get_app_image_name $APP)
Expand All @@ -20,14 +21,14 @@ fi

if [[ -f "$SHARED_KEY_FOLDER/known_hosts" ]]; then
dokku_log_verbose_quiet "Adding shared keys"
if ([[ -z "$KNOWN_HOSTS_COMBINED" ]]); then
if [[ -z "$KNOWN_HOSTS_COMBINED" ]]; then
KNOWN_HOSTS_COMBINED="$KNOWN_HOSTS_COMBINED"$(cat "$SHARED_KEY_FOLDER/known_hosts")
else
KNOWN_HOSTS_COMBINED="$KNOWN_HOSTS_COMBINED"$'\n'$(cat "$SHARED_KEY_FOLDER/known_hosts")
fi
fi

if [[ ! -z "$KNOWN_HOSTS_COMBINED" ]]; then
if [[ -n "$KNOWN_HOSTS_COMBINED" ]]; then
# 1. Create the .ssh folder
id=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d $IMAGE /bin/bash -c "mkdir -p -m 700 /app/.ssh")
test $(docker wait $id) -eq 0
Expand Down