|
@@ -12,19 +12,20 @@ fi
|
|
unset SSHD_HOST_KEYS_DIR
|
|
unset SSHD_HOST_KEYS_DIR
|
|
|
|
|
|
authorize_key() {
|
|
authorize_key() {
|
|
- if echo -E "$2" | grep -q '^[a-z]'; then
|
|
|
|
- echo "command=\"/usr/bin/borg serve --restrict-to-repository '$1'$3\",restrict $2" >> ~/.ssh/authorized_keys
|
|
|
|
|
|
+ if echo -E "$1" | grep -q '^[a-z]'; then
|
|
|
|
+ echo "command=\"/usr/bin/borg serve$2\",restrict $1" >> ~/.ssh/authorized_keys
|
|
fi
|
|
fi
|
|
}
|
|
}
|
|
authorize_keys() {
|
|
authorize_keys() {
|
|
printenv "$1" | while IFS=$'\n' read -r key; do
|
|
printenv "$1" | while IFS=$'\n' read -r key; do
|
|
- authorize_key "$2" "$key" "$3"
|
|
|
|
|
|
+ authorize_key "$key" " --restrict-to-repository '$2'$3"
|
|
done
|
|
done
|
|
unset "$1"
|
|
unset "$1"
|
|
}
|
|
}
|
|
authorize_keys SSH_CLIENT_PUBLIC_KEYS "$REPO_PATH" ""
|
|
authorize_keys SSH_CLIENT_PUBLIC_KEYS "$REPO_PATH" ""
|
|
# https://borgbackup.readthedocs.io/en/stable/usage/notes.html#append-only-mode
|
|
# https://borgbackup.readthedocs.io/en/stable/usage/notes.html#append-only-mode
|
|
authorize_keys SSH_CLIENT_PUBLIC_KEYS_APPEND_ONLY "$REPO_PATH" " --append-only"
|
|
authorize_keys SSH_CLIENT_PUBLIC_KEYS_APPEND_ONLY "$REPO_PATH" " --append-only"
|
|
|
|
+all_repo_restrictions=" --restrict-to-repository '$REPO_PATH'"
|
|
unset REPO_PATH
|
|
unset REPO_PATH
|
|
while IFS=$'\n' read line; do
|
|
while IFS=$'\n' read line; do
|
|
repo_name="$(echo -E "$line" | cut -d = -f 1 | cut -d _ -f 3-)"
|
|
repo_name="$(echo -E "$line" | cut -d = -f 1 | cut -d _ -f 3-)"
|
|
@@ -33,10 +34,15 @@ while IFS=$'\n' read line; do
|
|
exit 1
|
|
exit 1
|
|
fi
|
|
fi
|
|
repo_path="$(printenv "REPO_PATH_${repo_name}")"
|
|
repo_path="$(printenv "REPO_PATH_${repo_name}")"
|
|
|
|
+ all_repo_restrictions="$all_repo_restrictions --restrict-to-repository '$repo_path'"
|
|
unset "REPO_PATH_${repo_name}"
|
|
unset "REPO_PATH_${repo_name}"
|
|
authorize_keys "SSH_CLIENT_PUBLIC_KEYS_${repo_name}" "$repo_path" ""
|
|
authorize_keys "SSH_CLIENT_PUBLIC_KEYS_${repo_name}" "$repo_path" ""
|
|
authorize_keys "SSH_CLIENT_PUBLIC_KEYS_APPEND_ONLY_${repo_name}" "$repo_path" " --append-only"
|
|
authorize_keys "SSH_CLIENT_PUBLIC_KEYS_APPEND_ONLY_${repo_name}" "$repo_path" " --append-only"
|
|
done < <(printenv | grep '^REPO_PATH_')
|
|
done < <(printenv | grep '^REPO_PATH_')
|
|
|
|
+printenv SSH_CLIENT_PUBLIC_KEYS_ALL | while IFS=$'\n' read -r key; do
|
|
|
|
+ authorize_key "$key" "$all_repo_restrictions"
|
|
|
|
+done
|
|
|
|
+unset SSH_CLIENT_PUBLIC_KEYS_ALL
|
|
|
|
|
|
set -x
|
|
set -x
|
|
|
|
|