Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The master key, backups and restore

Read this before you put real notes on a server.

What the master key does

Every standard workspace has its own key, which seals its documents, history and files. The server keeps those keys in the database wrapped (encrypted) by the master key, so a copy of the database alone opens nothing. The master key also wraps each account’s own data key, which seals the API keys people save for their own AI providers.

End-to-end encrypted workspaces are different: their keys live on the members’ devices, and the master key opens none of them.

If you lose the master key, every standard workspace on the server is unreadable, for good. Nobody, including Drusite’s developers, can get it back.

Where it comes from: [keys] source

env: an environment variable

[keys]
source = "env"            # reads DRUSITE_MASTER_KEY; `var` names another

file: a file

What the Compose file and the Helm chart use, with a Docker or Kubernetes secret:

[keys]
source = "file"
path = "/run/secrets/master_key"

For both, make a key with:

docker run --rm ghcr.io/pranavajk1/drusite-server:1 keys generate

It prints one entry, mk-1a2b3c4d:<32 bytes in base64>: an ID, a colon and the key. The variable or file holds one or more entries, separated by spaces, commas or new lines. The first one wraps new keys; the others still unwrap what they wrapped.

transit: OpenBao or Vault

With the Transit engine of OpenBao or HashiCorp Vault, the master key never leaves the key management service: the server sends each workspace key to be wrapped and unwrapped there.

bao secrets enable transit
bao write -f transit/keys/drusite type=chacha20-poly1305
bao policy write drusite - <<'HCL'
path "transit/encrypt/drusite" { capabilities = ["update"] }
path "transit/decrypt/drusite" { capabilities = ["update"] }
HCL
bao token create -policy=drusite -period=768h
[keys]
source = "transit"
address = "https://bao.example.com"
key = "drusite"
token_file = "/run/secrets/bao-token"
# mount = "transit"
# namespace = "drusite"   # Vault Enterprise and OpenBao namespaces

The key type must support associated data (chacha20-poly1305 or aes256-gcm96). Renew a periodic token before its period ends, or use your platform’s agent to keep it fresh. Rotating the Transit key (bao write -f transit/keys/drusite/rotate) needs nothing from Drusite.

On every start the server wraps and unwraps a throwaway key to prove the source works, and with transit its readiness check does the same, so /readyz fails while OpenBao is unreachable.

Rotating a local master key

  1. Make a new key with keys generate.
  2. Put it first, keeping the old one after it: mk-new…:… mk-old…:…
  3. Restart the server.

New workspace keys (new workspaces, and new key versions made when someone is removed from a workspace) are wrapped with the new master key. Keys wrapped with the old one stay wrapped with it: 1.0 has no command that wraps them again, so keep every old master key in the list. To see which master keys are in use:

SELECT master_key_id, count(*) FROM workspace_keys GROUP BY 1;

What to back up

WhatWhyHow often
The master key (or OpenBao’s Transit key)Without it, standard workspaces can’t be readOnce, and after each rotation. Keep it apart from the database’s backups.
PostgreSQLAccounts, workspaces, members, documents and historyDaily, or continuously with WAL archiving
The bucketAttachments and recordingsAs often as the database
The configdrusite.toml, or your Helm valuesWhen it changes

Back up the database first, then the bucket. A file uploaded in between is a harmless extra in the bucket’s backup; the other order could leave pages pointing at files the backup lacks.

Who can read a backup

Standard workspaceEncrypted workspace
Pages, files, historySealed with workspace keys, which the master key wrapsSealed on the members’ devices; no key on the server opens them
To restore it you needThe backup and the master key that was current when it was madeThe backup; members’ devices still hold their keys
Search words and vectorsIn the database, derived from the text (search)None, unless an owner lets the server’s AI read pages

So anyone with a database backup and the master key can read standard workspaces. Store them apart. A workspace converted to end-to-end encryption can still be read from backups made before the conversion, with the master key of that time, until those backups expire.

Docker Compose

A nightly backup into backups/, from the folder with compose.yaml:

mkdir -p backups
day=$(date +%F)
docker compose exec -T postgres pg_dump -U postgres -Fc --no-comments drusite > "backups/drusite-$day.dump"
docker compose stop seaweedfs
docker run --rm -v drusite_seaweedfs:/data:ro -v "$PWD/backups:/backup" alpine \
  tar czf "/backup/seaweedfs-$day.tgz" -C /data .
docker compose start seaweedfs

SeaweedFS is stopped for the copy so its files are consistent; while it’s down, attachments can’t be opened or uploaded, and the apps retry. --no-comments leaves out the comment on the pgvector extension, which only its owner may set again on restore.

Copy backups/ and, once, secrets/ somewhere else: another machine, or an object store in another place.

Restoring

On a new machine, with the same compose.yaml, drusite.toml and the old secrets/:

docker compose up -d postgres seaweedfs
docker compose exec -T postgres pg_restore -U postgres -d drusite --no-owner --role=drusite \
  < backups/drusite-2026-11-29.dump
docker compose stop seaweedfs
docker run --rm -v drusite_seaweedfs:/data -v "$PWD/backups:/backup" alpine \
  sh -c 'rm -rf /data/* && tar xzf /backup/seaweedfs-2026-11-29.tgz -C /data'
docker compose up -d
curl -s http://localhost:8080/readyz

The first up makes an empty database with the drusite role and pgvector, as on any first start, and pg_restore fills it. If you made new secrets by mistake, put the old master_key (and db_password and database_url) back before starting the server: the restored workspaces need the old master key.

Kubernetes and managed services

Use what your platform has: CloudNativePG’s backups or your provider’s snapshots for PostgreSQL, and bucket replication or versioning for the store. Keep the master key in your secret manager and somewhere outside the cluster.

Test the restore

A backup you’ve never restored is a hope. Restore into a scratch Compose project now and then, sign in, and open a page with an attachment.