Skip to content

Commit 50a7923

Browse files
✨ Implement GPG Public Key encryption support
First introduced in dokku/docker-s3backup#81.
1 parent 13e46ba commit 50a7923

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
lines changed

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ postgres:backup-deauth <service> # remove backup authenticatio
2424
postgres:backup-schedule <service> <schedule> <bucket-name> [--use-iam] # schedule a backup of the postgres service
2525
postgres:backup-schedule-cat <service> # cat the contents of the configured backup cronfile for the service
2626
postgres:backup-set-encryption <service> <passphrase> # set encryption for all future backups of postgres service
27+
postgres:backup-set-public-key-encryption <service> <public-key-id> # set GPG Public Key encryption for all future backups of postgres service
2728
postgres:backup-unschedule <service> # unschedule the backup of the postgres service
2829
postgres:backup-unset-encryption <service> # unset encryption for future backups of the postgres service
30+
postgres:backup-unset-public-key-encryption <service> # unset GPG Public Key encryption for future backups of the postgres service
2931
postgres:clone <service> <new-service> [--clone-flags...] # create container <new-name> then copy data from <name> into <new-name>
3032
postgres:connect <service> # connect to the service via the postgres connection tool
3133
postgres:create <service> [--create-flags...] # create a postgres service
@@ -718,6 +720,19 @@ Set the GPG-compatible passphrase for encrypting backups for backups:
718720
dokku postgres:backup-set-encryption lollipop
719721
```
720722

723+
### set GPG Public Key encryption for all future backups of postgres service
724+
725+
```shell
726+
# usage
727+
dokku postgres:backup-set-public-key-encryption <service> <public-key-id>
728+
```
729+
730+
Set the `GPG` Public Key for encrypting backups:
731+
732+
```shell
733+
dokku postgres:backup-set-public-key-encryption lollipop
734+
```
735+
721736
### unset encryption for future backups of the postgres service
722737

723738
```shell
@@ -731,6 +746,19 @@ Unset the `GPG` encryption passphrase for backups:
731746
dokku postgres:backup-unset-encryption lollipop
732747
```
733748

749+
### unset GPG Public Key encryption for future backups of the postgres service
750+
751+
```shell
752+
# usage
753+
dokku postgres:backup-unset-public-key-encryption <service>
754+
```
755+
756+
Unset the `GPG` Public Key encryption for backups:
757+
758+
```shell
759+
dokku postgres:backup-unset-public-key-encryption lollipop
760+
```
761+
734762
### schedule a backup of the postgres service
735763

736764
```shell

bin/generate

+2
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@ def usage_backup(
290290
"backup-deauth",
291291
"backup",
292292
"backup-set-encryption",
293+
"backup-set-public-key-encryption",
293294
"backup-unset-encryption",
295+
"backup-unset-public-key-encryption",
294296
"backup-schedule",
295297
"backup-schedule-cat",
296298
"backup-unschedule",

common-functions

+23
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ service_backup() {
308308
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e ENCRYPTION_KEY=$(cat "$BACKUP_ENCRYPTION_CONFIG_ROOT/ENCRYPTION_KEY")"
309309
fi
310310

311+
if [[ -f "$BACKUP_ENCRYPTION_CONFIG_ROOT/ENCRYPT_WITH_PUBLIC_KEY_ID" ]]; then
312+
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e ENCRYPT_WITH_PUBLIC_KEY_ID=$(cat "$BACKUP_ENCRYPTION_CONFIG_ROOT/ENCRYPT_WITH_PUBLIC_KEY_ID")"
313+
fi
314+
311315
# shellcheck disable=SC2086
312316
"$DOCKER_BIN" container run --rm $BACKUP_PARAMETERS "$PLUGIN_S3BACKUP_IMAGE"
313317
}
@@ -433,6 +437,16 @@ service_backup_set_encryption() {
433437
echo "$ENCRYPTION_KEY" >"${SERVICE_BACKUP_ENCRYPTION_ROOT}/ENCRYPTION_KEY"
434438
}
435439

440+
service_backup_set_public_key_encryption() {
441+
declare desc="set up backup GPG Public Key encryption"
442+
declare SERVICE="$1" ENCRYPT_WITH_PUBLIC_KEY_ID="$2"
443+
local SERVICE_ROOT="${PLUGIN_DATA_ROOT}/${SERVICE}"
444+
local SERVICE_BACKUP_ENCRYPTION_ROOT="${SERVICE_ROOT}/backup-encryption/"
445+
446+
mkdir "$SERVICE_BACKUP_ENCRYPTION_ROOT"
447+
echo "$ENCRYPT_WITH_PUBLIC_KEY_ID" >"${SERVICE_BACKUP_ENCRYPTION_ROOT}/ENCRYPT_WITH_PUBLIC_KEY_ID"
448+
}
449+
436450
service_backup_unschedule() {
437451
declare desc="unschedule the backup of the service"
438452
declare SERVICE="$1"
@@ -450,6 +464,15 @@ service_backup_unset_encryption() {
450464
rm -rf "$SERVICE_BACKUP_ENCRYPTION_ROOT"
451465
}
452466

467+
service_backup_unset_encryption() {
468+
declare desc="remove backup encryption"
469+
declare SERVICE="$1"
470+
local SERVICE_ROOT="${PLUGIN_DATA_ROOT}/${SERVICE}"
471+
local SERVICE_BACKUP_ENCRYPTION_ROOT="${SERVICE_ROOT}/backup-encryption/"
472+
473+
rm -rf "$SERVICE_BACKUP_ENCRYPTION_ROOT"
474+
}
475+
453476
service_container_rm() {
454477
declare desc="stop a service and remove the running container"
455478
declare SERVICE="$1"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config"
3+
set -eo pipefail
4+
[[ $DOKKU_TRACE ]] && set -x
5+
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
6+
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
7+
8+
service-backup-set-public-key-encryption-cmd() {
9+
#E set the GPG Public Key for encrypting backups
10+
#E dokku $PLUGIN_COMMAND_PREFIX:backup-set-public-key-encryption lollipop
11+
#A service, service to run command against
12+
#A public-key-id, a GPG Public Key ID (or fingerprint) to use for encryption. Must be uploaded to the GPG keyserver beforehand.
13+
declare desc="set GPG Public Key encryption for all future backups of $PLUGIN_SERVICE service"
14+
local cmd="$PLUGIN_COMMAND_PREFIX:backup-set-public-key-encryption" argv=("$@")
15+
[[ ${argv[0]} == "$cmd" ]] && shift 1
16+
declare SERVICE="$1" PUBLIC_KEY_ID="$2"
17+
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented"
18+
19+
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service"
20+
[[ -z "$PUBLIC_KEY_ID" ]] && dokku_log_fail "Please specify a valid GPG Public Key ID (or fingerprint)"
21+
verify_service_name "$SERVICE"
22+
service_backup_set_public_key_encryption "$SERVICE" "$PUBLIC_KEY_ID"
23+
}
24+
25+
service-backup-set-encryption-cmd "$@"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config"
3+
set -eo pipefail
4+
[[ $DOKKU_TRACE ]] && set -x
5+
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
6+
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
7+
8+
service-backup-unset-public-key-encryption-cmd() {
9+
#E unset the GPG Public Key encryption for backups
10+
#E dokku $PLUGIN_COMMAND_PREFIX:backup-unset-public-key-encryption lollipop
11+
#A service, service to run command against
12+
declare desc="unset GPG Public Key encryption for future backups of the $PLUGIN_SERVICE service"
13+
local cmd="$PLUGIN_COMMAND_PREFIX:backup-unset-public-key-encryption" argv=("$@")
14+
[[ ${argv[0]} == "$cmd" ]] && shift 1
15+
declare SERVICE="$1"
16+
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented" # TODO: [22.03.2024 by Mykola]
17+
18+
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service"
19+
verify_service_name "$SERVICE"
20+
service_backup_unset_public_key_encryption "$SERVICE" # TODO: [22.03.2024 by Mykola]
21+
}
22+
23+
service-backup-unset-encryption-cmd "$@"

0 commit comments

Comments
 (0)