Install and hosting

Install and hosting

Every setup needs a MASTER_KEY: a random secret that encrypts every stored file. Make one now and keep a copy somewhere other than the server, such as a password manager or a printed sheet with your recovery codes.

openssl rand -base64 32

Without MASTER_KEY, stored files can't be decrypted. A recent backup plus its passphrase is the only other way back.

Cloudflare (free plan)

The recommended setup. Kagaz runs as a Cloudflare Worker, keeps records in a D1 database and encrypted files in an R2 bucket. A family-sized vault fits in the free plan.

With the Deploy to Cloudflare button

The button in the README copies the repository to your GitHub account, creates the D1 database and R2 bucket, asks for MASTER_KEY, then builds and deploys. Your vault is then live at https://kagaz.<your-subdomain>.workers.dev.

The button only works while the repository is public. If it doesn't work for you, use the manual steps below.

Manually, with Wrangler

  1. Install Node.js 22 or newer, then get the code:
    git clone https://github.com/bnap00/kagaz
    cd kagaz
    npm install
  2. Sign in to Cloudflare and store the master key as a secret:
    npx wrangler login
    npx wrangler secret put MASTER_KEY
  3. Build and deploy. The first deploy creates the D1 database and the R2 bucket:
    npm run build
    npm run deploy
  4. Open the address Wrangler prints and create your family vault.

R2 has to be enabled once on your Cloudflare account (R2 Object Storage in the dashboard). It has a free tier, but Cloudflare may ask for a payment method.

What gets created

ResourceBindingHolds
Worker kagazThe API and the web app
D1 database kagazDBRecords. Tables are created on the first request.
R2 bucket kagaz-filesFILESEncrypted files
Daily cron triggerClears expired sessions and links

Your own domain

In the Cloudflare dashboard, open Workers & Pages › kagaz › Settings › Domains & Routes and add a custom domain such as docs.example.com. Then set PUBLIC_URL under vars in wrangler.jsonc so invite links use it, and deploy again.

Why it fits the free plan

The free plan allows 10 ms of CPU time per request. Kagaz keeps the expensive work in the browser (password stretching, building print PDFs, opening locked PDFs, backups), and the Worker only does fast AES-GCM encryption and small database queries. Uploads are limited to 10 MB per file on Cloudflare, and photos are shrunk in the browser first.

Home server, NAS or Raspberry Pi

  1. Install Docker, then:
    git clone https://github.com/bnap00/kagaz
    cd kagaz
    cp docker.env.example .env
  2. Edit .env: set MASTER_KEY, and set PUBLIC_URL to the address the family will use.
  3. Start it:
    docker compose up -d
  4. Open http://localhost:8080 (or the server's address) and create the vault.

Everything lives in ./data. To use Kagaz away from home without opening ports on your router:

A free cloud VM

For example an Oracle Cloud Always Free VM running Ubuntu with Docker installed.

  1. Follow the Docker steps above on the VM, with PUBLIC_URL=https://docs.example.com.
  2. Point your domain's DNS at the VM and open ports 80 and 443.
  3. Add HTTPS with Caddy, which gets certificates automatically:
    caddy reverse-proxy --from docs.example.com --to localhost:8080

Download a backup regularly and keep it off the VM.

Any container host

Use this on platforms that can wipe your container at any time, such as Google Cloud Run, Render or Koyeb. Nothing important lives in the container.

  1. Database: create a Turso database and token.
    turso db create kagaz
    turso db show kagaz --url       # DATABASE_URL
    turso db tokens create kagaz    # DATABASE_AUTH_TOKEN
  2. Files: create a private bucket on Cloudflare R2 or Backblaze B2, with an access key limited to that bucket.
  3. Run the repository's Dockerfile with these environment variables:
    MASTER_KEY=...
    PUBLIC_URL=https://your-app-url
    DATABASE_URL=libsql://kagaz-you.turso.io
    DATABASE_AUTH_TOKEN=...
    STORAGE_DRIVER=s3
    S3_ENDPOINT=https://<account-id>.r2.cloudflarestorage.com
    S3_REGION=auto
    S3_BUCKET=kagaz
    S3_ACCESS_KEY_ID=...
    S3_SECRET_ACCESS_KEY=...

In this mode Kagaz refuses to start without MASTER_KEY, so a key can't be silently lost on a redeploy. Hosts that put idle apps to sleep make the first page load slower, which is fine for family use.

Upgrading

Take a backup first. Database changes are applied automatically when the new version starts.

# Docker
git pull && docker compose up -d --build

# Cloudflare
git pull && npm install && npm run build && npm run deploy