Skip to content

Quickstart (self-host)

You need a Linux host with Docker and Compose, a domain name, and a TLS reverse proxy such as Caddy, nginx or Traefik.

  1. Create a project and enable the Gmail API (and the Google Calendar API if you set FEATURES=mail,calendar).
  2. Google Auth Platform → Branding: set the app name, support email, home page, privacy policy link and authorized domain.
  3. Audience: choose External, then click Publish app to move it to In production. Don’t submit it for verification. In Testing mode Google expires refresh tokens after 7 days, so you would have to relink weekly.
  4. Data Access: add openid, .../auth/userinfo.email, .../auth/gmail.readonly and .../auth/gmail.compose. If you turn on triage, also add .../auth/gmail.modify; for the calendar module, .../auth/calendar.readonly and .../auth/calendar.events.
  5. Clients → create a Web application client with these redirect URIs:
    • https://<host>/auth/callback
    • https://<host>/gmail/callback
    • https://<host>/send/auth/callback (only needed with SENDING_ENABLED=true or FEATURES=mail,calendar)
  6. If you use Google Workspace, the admin should go to Admin console → Security → API controls → Manage third-party app access, add the app by client ID and mark it Trusted. Otherwise Workspace policy may block mailbox linking.
Terminal window
git clone <this repo> /opt/surfski && cd /opt/surfski
Terminal window
sudo install -d -m 700 /etc/surfski && sudo install -m 600 deploy/env.example /etc/surfski/env
Terminal window
python3 scripts/gen_secrets.py

Paste the four generated secrets into /etc/surfski/env, then fill in BASE_URL, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET and ALLOWED_USERS (and/or ALLOWED_DOMAINS to allow a whole Workspace domain). The server refuses to start if any secret is missing or malformed, or if both allowlists are empty.

Aliases: Google sign-in reports a user’s primary address. If your Workspace uses alias domains, put the primary addresses in ALLOWED_USERS, or the Workspace primary domain in ALLOWED_DOMAINS (an alias domain never matches; Google’s hd claim must equal the primary domain). Linking an alias address links the primary mailbox behind it.

Secondary domains: if a user’s address is on a secondary domain of a Workspace org, Google’s hd claim may still be the org’s primary domain, so list the primary domain in ALLOWED_DOMAINS (or list the user in ALLOWED_USERS). A mismatch fails closed: the user is refused.

Terminal window
sudo docker compose -p surfski up -d --build
Terminal window
curl -s 127.0.0.1:38000/healthz

Prebuilt image (optional). Instead of building locally, you can use the multi-arch (amd64/arm64) image published on each release. In compose.yaml, replace build: . and image: surfski:latest with:

image: ghcr.io/rayhu/surfski:latest # or pin a release, e.g. ghcr.io/rayhu/surfski:v0.1.0

Then start it without --build:

Terminal window
sudo docker compose -p surfski up -d

Point your reverse proxy at 127.0.0.1:38000. deploy/Caddyfile.snippet is a Caddy example. Don’t enable response compression on this route, because the MCP stream uses SSE.

In Claude, go to Settings → Connectors → Add custom connector and enter https://<host>/mcp. Click Connect and sign in with an allowlisted Google account. Then say: “link my work Gmail as work” and open the link Claude returns.

When you link a mailbox, sign in as that mailbox and tick both permission checkboxes.

What changed in each version is in CHANGELOG.md; surfski --version (or docker compose -p surfski exec app surfski --version) shows what you run.

Terminal window
git pull && sudo docker compose -p surfski up -d --build

With the prebuilt image, run git pull && sudo docker compose -p surfski pull && sudo docker compose -p surfski up -d instead. The git pull picks up changes to compose.yaml and the env reference.

scripts/backup.sh backs up the surfski_surfski-data volume to /var/backups/surfski/surfski-data-YYYYmmdd-HHMMSS.tgz (mode 600) and deletes archives older than 14 days. It takes a consistent SQLite snapshot with Python’s online backup API inside the Surfski image, so the server can keep running, and adds oauth/ as files. It refuses to run if anything named env/*.env is in the volume. --dry-run shows what it would do; --help lists options (--dest, --keep, --volume, --image).

Nightly at 03:15 from root’s crontab (it uses the local surfski:latest image that docker compose build creates):

15 3 * * * /opt/surfski/scripts/backup.sh --keep 14 >> /var/log/surfski-backup.log 2>&1

Restore:

Terminal window
docker compose stop app
sudo scripts/backup.sh --restore /var/backups/surfski/surfski-data-20260101-031500.tgz --yes
# add --force if the volume isn't empty; its contents are replaced
docker compose start app

The backup is useless without TOKEN_ENCRYPTION_KEY and STORAGE_ENCRYPTION_KEY, and it never contains them. Keep the env file in a separate place, such as a password manager, never in the same backup. Restore with the same keys that were in use when the backup was made. If you lose the keys, users simply relink their mailboxes.

surfski with no arguments (or surfski serve) runs the server; that is what the container’s CMD does. The admin subcommands work on the database directly and run only from a shell on the host or inside the container. There is no network admin endpoint. They never print refresh tokens, ciphertext or keys, and they are safe to run while the server is up.

Terminal window
sudo docker compose -p surfski exec app surfski admin list
CommandWhat it does
admin list [--json]Every owner with their mailboxes: alias, address, created / last used, send policy, triage
admin unlink --owner X --alias Y [--revoke]Remove one mailbox (as unlink_account). --revoke also revokes its token at Google
admin purge-owner --owner X --yesErase all of one owner’s data, exactly as their delete_my_data would (revokes at Google; audit rows follow AUDIT_ON_DELETE). Without --yes nothing is deleted
admin rotate-token-key [--dry-run]Re-encrypt every refresh token with the current key (see below)
admin audit --owner X [--since 7d|2026-10-01]Audit row counts per tool (ok / failed), never details

Exit codes: 0 success; 1 refused or failed (unknown owner or alias, missing --yes, a failed revocation at Google, undecryptable rows during rotation); 2 usage or configuration error. When a revocation fails, unlink and purge-owner have still removed the data. An unexpected error (for example database is locked) prints one line and exits 1; surfski admin --debug … shows the traceback.

TOKEN_ENCRYPTION_KEY (Gmail refresh tokens in SQLite). While TOKEN_ENCRYPTION_KEY_OLD is set, the server decrypts with the new key, then the old one, and always encrypts with the new one, so it keeps working during the whole rotation:

  1. Generate a key: python3 scripts/gen_secrets.py and take its TOKEN_ENCRYPTION_KEY line.
  2. In /etc/surfski/env, move the current value to TOKEN_ENCRYPTION_KEY_OLD and put the new key in TOKEN_ENCRYPTION_KEY.
  3. Restart the server on the new key before rotating: sudo docker compose -p surfski up -d (a plain restart doesn’t reread the env file). This order matters: a server still running on the old key keeps writing old-key rows (every link or relink), and any it writes after step 4 stay on the old key. docker compose exec also takes the container’s env, so the rotate command only sees the new key once the container was recreated. If you got the order wrong, restart and run step 4 again; it is idempotent and only touches rows that aren’t on the current key yet.
  4. Rotate: sudo docker compose -p surfski exec app surfski admin rotate-token-key. It re-encrypts every row in one SQLite write transaction and reports the counts. If any row can’t be decrypted with the new or the old key, it changes nothing, lists the affected owner / alias pairs and exits 1 (relink or admin unlink those, or supply the right old key, then run it again).
  5. Remove TOKEN_ENCRYPTION_KEY_OLD and restart again.

Per-owner keys work the same way with TOKEN_ENCRYPTION_KEYS_OLD=owner=oldkey,…. Giving an existing owner their own TOKEN_ENCRYPTION_KEYS entry is a rotation too: set TOKEN_ENCRYPTION_KEYS_OLD=owner=<the default key> for it (an owner with a per-owner key never falls back to the default key on its own). Removing an owner’s entry: set TOKEN_ENCRYPTION_KEYS_OLD to their former key.

Pending confirmation links (send, calendar and policy confirmations, which live 10 minutes) are encrypted with the owner’s token key too. They stay valid during a rotation while the old key is configured, and only break if you remove TOKEN_ENCRYPTION_KEY_OLD (or the owner’s TOKEN_ENCRYPTION_KEYS_OLD entry) within 10 minutes of the link being issued; the owner then asks for a new link.

Backups after a rotation: older backups still need the old key. Keep the old key with the backups it protects until they expire, or take a fresh backup right after rotating.

STORAGE_ENCRYPTION_KEY (FastMCP’s OAuth store under DATA_DIR/oauth: Claude’s client registrations and session tokens). Set STORAGE_ENCRYPTION_KEY_OLD to the previous key alongside the new one and restart: existing entries stay readable and new ones are written with the new key. There is no rewrite command, because that file store has no locking and a rewrite could race the running server. When you finally remove STORAGE_ENCRYPTION_KEY_OLD, entries still under the old key read as missing, so Claude users whose connector registration predates the rotation must reconnect the connector (Settings → Connectors). Nothing else is lost: linked mailboxes are in SQLite.


Synced from rayhu/surfski/README.md@0165816. The repository is the source of truth.