🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Enhance ClickHouse backup configuration and documentation
Bill Yangd621370f0216
diff --git a/ops/backups/README.md b/ops/backups/README.mdindex e290c81eb..46c4082d5 100644--- a/ops/backups/README.md+++ b/ops/backups/README.md@@ -92,17 +92,23 @@ services:clickhouse:volumes:- /etc/rybbit-backup/clickhouse-s3.xml:/etc/clickhouse-server/config.d/backup-s3.xml:ro+ - ./ops/backups/clickhouse/backup-user.xml:/etc/clickhouse-server/users.d/backup-user.xml:ro```UID/GID 101 is the default ClickHouse user in the official image; confirm itbefore installation if the image changes. Recreate ClickHouse and verify the-collection without printing its contents:+dedicated user's grants without printing the named collection contents:```bashdocker exec clickhouse clickhouse-client \- --query "SELECT name FROM system.named_collections WHERE name = 'b2_backups'"+ --user backup --query "SHOW GRANTS FOR backup"```+The `backup` user is passwordless but restricted to connections originating+inside the ClickHouse container. It can back up `analytics`, use the B2 named+collection, and access S3; it cannot read or mutate application data through+ordinary SQL. The FrogStats environment example selects this user for backups.+## Standalone ClickHouse staging diskThe standalone host creates one native backup and uploads the same completeddiff --git a/ops/backups/bin/backup-clickhouse.sh b/ops/backups/bin/backup-clickhouse.shindex e3cfe8b7e..2ef81d5c0 100755--- a/ops/backups/bin/backup-clickhouse.sh+++ b/ops/backups/bin/backup-clickhouse.sh@@ -25,10 +25,18 @@ trap finish EXITrun_clickhouse_query() {local query="$1"- # Feed SQL over stdin so S3 credentials do not appear in the host process- # list. Query logging is disabled for this client session by the query.- printf '%s\n' "$query" | docker exec -i "$CLICKHOUSE_CONTAINER" sh -ec \- 'exec clickhouse-client --user "$CLICKHOUSE_USER" --password "$CLICKHOUSE_PASSWORD" --multiquery'+ # Feed SQL over stdin so it does not appear in the host process list. When a+ # dedicated backup user is configured, pass its credentials only to this+ # short-lived exec process. Otherwise use the container's application user.+ printf '%s\n' "$query" | docker exec -i \+ -e RYBBIT_BACKUP_USER="${CLICKHOUSE_BACKUP_USER:-}" \+ -e RYBBIT_BACKUP_PASSWORD="${CLICKHOUSE_BACKUP_PASSWORD:-}" \+ "$CLICKHOUSE_CONTAINER" sh -ec '+ if [ -n "$RYBBIT_BACKUP_USER" ]; then+ exec clickhouse-client --user "$RYBBIT_BACKUP_USER" --password "$RYBBIT_BACKUP_PASSWORD" --multiquery+ fi+ exec clickhouse-client --user "$CLICKHOUSE_USER" --password "$CLICKHOUSE_PASSWORD" --multiquery+ '}load_backup_configdiff --git a/ops/backups/clickhouse/backup-user.xml b/ops/backups/clickhouse/backup-user.xmlnew file mode 100644index 000000000..a1c1c70d6--- /dev/null+++ b/ops/backups/clickhouse/backup-user.xml@@ -0,0 +1,20 @@+<clickhouse>+ <!-- This user can connect only from inside the ClickHouse container. -->+ <users>+ <backup>+ <password></password>+ <networks>+ <ip>127.0.0.1</ip>+ <ip>::1</ip>+ </networks>+ <profile>default</profile>+ <quota>default</quota>+ <grants>+ <query>GRANT BACKUP ON analytics.*</query>+ <query>GRANT NAMED COLLECTION ON b2_backups</query>+ <query>GRANT S3 ON *.*</query>+ </grants>+ </backup>+ </users>+</clickhouse>+diff --git a/ops/backups/clickhouse/s3-named-collection.xml.example b/ops/backups/clickhouse/s3-named-collection.xml.exampleindex 5d2fd9940..c62999be1 100644--- a/ops/backups/clickhouse/s3-named-collection.xml.example+++ b/ops/backups/clickhouse/s3-named-collection.xml.example@@ -2,7 +2,6 @@<!-- Install this file outside the repository, replace all placeholders,make it readable only by root and the ClickHouse group, and mount itread-only into /etc/clickhouse-server/config.d/. -->- <allow_named_collection_override_by_default>false</allow_named_collection_override_by_default><named_collections><b2_backups><url overridable="false">https://s3.YOUR-B2-REGION.backblazeb2.com/YOUR-BUCKET/frogstats/clickhouse/</url>@@ -11,4 +10,3 @@</b2_backups></named_collections></clickhouse>-diff --git a/ops/backups/config/frogstats.env.example b/ops/backups/config/frogstats.env.exampleindex 881dc9971..53c61f2f7 100644--- a/ops/backups/config/frogstats.env.example+++ b/ops/backups/config/frogstats.env.example@@ -12,6 +12,10 @@ POSTGRES_RCLONE_REMOTES=b2:rybbit-db-backups/frogstats/postgresCLICKHOUSE_CONTAINER=clickhouseCLICKHOUSE_DATABASE=analyticsCLICKHOUSE_BACKUP_MODE=s3+CLICKHOUSE_BACKUP_USER=backup+# The supplied backup user is localhost-only and passwordless. Set a password+# here only if you add the matching hash/password to backup-user.xml.+CLICKHOUSE_BACKUP_PASSWORD=CLICKHOUSE_S3_NAMED_COLLECTION=b2_backups# Optional monitoring endpoints, such as Healthchecks.io ping URLs.