🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Update ClickHouse backup configuration to include password management
Bill Yang988ed19d67ee
diff --git a/ops/backups/README.md b/ops/backups/README.mdindex 46c4082d5..3f3de3d8c 100644--- a/ops/backups/README.md+++ b/ops/backups/README.md@@ -85,6 +85,25 @@ sudo install -m 0640 -o root -g 101 \sudoedit /etc/rybbit-backup/clickhouse-s3.xml```+Create a dedicated backup-user password, store its hash in the user XML, and+store only the plaintext password in the root-readable backup environment:++```bash+backup_password="$(openssl rand -hex 32)"+backup_password_hash="$(printf '%s' "$backup_password" | sha256sum | cut -d' ' -f1)"++sudo install -m 0640 -o root -g 101 \+ ops/backups/clickhouse/backup-user.xml \+ /etc/rybbit-backup/clickhouse-backup-user.xml+sudo sed -i \+ "s/REPLACE_WITH_SHA256_PASSWORD/${backup_password_hash}/" \+ /etc/rybbit-backup/clickhouse-backup-user.xml+sudo sed -i \+ "s/^CLICKHOUSE_BACKUP_PASSWORD=.*/CLICKHOUSE_BACKUP_PASSWORD=${backup_password}/" \+ /etc/rybbit-backup.env+unset backup_password backup_password_hash+```+Then mount it into the FrogStats ClickHouse container:```yaml@@ -92,7 +111,7 @@ 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+ - /etc/rybbit-backup/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 it@@ -104,10 +123,10 @@ docker exec clickhouse clickhouse-client \--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.+The `backup` user is 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 diskdiff --git a/ops/backups/clickhouse/backup-user.xml b/ops/backups/clickhouse/backup-user.xmlindex a1c1c70d6..832eb06d6 100644--- a/ops/backups/clickhouse/backup-user.xml+++ b/ops/backups/clickhouse/backup-user.xml@@ -2,7 +2,9 @@<!-- This user can connect only from inside the ClickHouse container. --><users><backup>- <password></password>+ <!-- Replace with SHA-256(password), generated for example with:+ printf '%s' "$PASSWORD" | sha256sum -->+ <password_sha256_hex>REPLACE_WITH_SHA256_PASSWORD</password_sha256_hex><networks><ip>127.0.0.1</ip><ip>::1</ip>@@ -17,4 +19,3 @@</backup></users></clickhouse>-diff --git a/ops/backups/config/frogstats.env.example b/ops/backups/config/frogstats.env.exampleindex 53c61f2f7..9f261d6a7 100644--- a/ops/backups/config/frogstats.env.example+++ b/ops/backups/config/frogstats.env.example@@ -13,9 +13,8 @@ CLICKHOUSE_CONTAINER=clickhouseCLICKHOUSE_DATABASE=analyticsCLICKHOUSE_BACKUP_MODE=s3CLICKHOUSE_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=+# Must match the SHA-256 hash installed in clickhouse-backup-user.xml.+CLICKHOUSE_BACKUP_PASSWORD=replace-meCLICKHOUSE_S3_NAMED_COLLECTION=b2_backups# Optional monitoring endpoints, such as Healthchecks.io ping URLs.