Skip to content

Commit c212d68

Browse files
committed
feat: implement GPG Public Key encryption support
1 parent 3f5db87 commit c212d68

File tree

5 files changed

+102
-1
lines changed

5 files changed

+102
-1
lines changed

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# dokku mysql [![Build Status](https://img.shields.io/github/actions/workflow/status/dokku/dokku-mysql/ci.yml?branch=master&style=flat-square "Build Status")](https://github.com/dokku/dokku-mysql/actions/workflows/ci.yml?query=branch%3Amaster) [![IRC Network](https://img.shields.io/badge/irc-libera-blue.svg?style=flat-square "IRC Libera")](https://webchat.libera.chat/?channels=dokku)
22

3-
Official mysql plugin for dokku. Currently defaults to installing [mysql 9.0.1](https://hub.docker.com/_/mysql/).
3+
Official mysql plugin for dokku. Currently defaults to installing [mysql 9.1.0](https://hub.docker.com/_/mysql/).
44

55
## Requirements
66

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

680+
### set GPG Public Key encryption for all future backups of mysql service
681+
682+
```shell
683+
# usage
684+
dokku mysql:backup-set-public-key-encryption <service> <public-key-id>
685+
```
686+
687+
Set the `GPG` Public Key for encrypting backups:
688+
689+
```shell
690+
dokku mysql:backup-set-public-key-encryption lollipop
691+
```
692+
678693
### unset encryption for future backups of the mysql service
679694

680695
```shell
@@ -688,6 +703,19 @@ Unset the `GPG` encryption passphrase for backups:
688703
dokku mysql:backup-unset-encryption lollipop
689704
```
690705

706+
### unset GPG Public Key encryption for future backups of the mysql service
707+
708+
```shell
709+
# usage
710+
dokku mysql:backup-unset-public-key-encryption <service>
711+
```
712+
713+
Unset the `GPG` Public Key encryption for backups:
714+
715+
```shell
716+
dokku mysql:backup-unset-public-key-encryption lollipop
717+
```
718+
691719
### schedule a backup of the mysql service
692720

693721
```shell

bin/generate

Lines changed: 2 additions & 0 deletions
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

Lines changed: 23 additions & 0 deletions
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"
Lines changed: 25 additions & 0 deletions
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-public-key-encryption-cmd "$@"
Lines changed: 23 additions & 0 deletions
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)