@cuongtran001/kanna 0.46.1 → 0.47.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -293,7 +293,30 @@ bun link # registers @cuongtran001/kanna → repo
293
293
 
294
294
  After this, `~/.bun/install/global/node_modules/@cuongtran001/kanna` is a symlink to your repo.
295
295
 
296
- ### 2. (Migrating from launchd) Unload the old agent
296
+ ### 2. Create a named Cloudflare tunnel
297
+
298
+ In the [Cloudflare Zero Trust dashboard](https://one.dash.cloudflare.com/) → **Networks → Tunnels → Create tunnel** (type: **Cloudflared**):
299
+
300
+ 1. Name the tunnel (e.g. `kanna`) and copy the **connector token** Cloudflare shows you. You will paste it as `KANNA_CLOUDFLARED_TOKEN` in the next step.
301
+ 2. Add a **public hostname** route: pick your subdomain (e.g. `kanna.example.com`) and point service to `HTTP` → `localhost:5174` (or whatever `--port` you plan to run). Kanna binds `127.0.0.1` automatically when `--cloudflared` is set, so the tunnel is the only ingress.
302
+ 3. Save. The hostname's TLS is terminated at Cloudflare's edge.
303
+
304
+ ### 3. Write `scripts/pm2.env` (untracked secrets)
305
+
306
+ `scripts/deploy.sh` reads this file and passes the values to kanna as `--cloudflared <TOKEN> --password <PW>`. Without it, deploy launches kanna with no token and no password — kanna will then run as plain HTTP on localhost, **`trustProxy` will not auto-enable**, and every `/auth/login` POST through the tunnel will return **403** because the CSRF origin check compares the browser's `https://` Origin against the server's `http://` `req.url`.
307
+
308
+ Create `scripts/pm2.env` (gitignored) with at least:
309
+
310
+ ```env
311
+ KANNA_CLOUDFLARED_TOKEN=<paste the connector token from step 2>
312
+ KANNA_PASSWORD=<a long random password>
313
+ # Optional: pass through to spawned Claude Code agents
314
+ # CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-...
315
+ ```
316
+
317
+ Generate a strong password with `openssl rand -base64 24`.
318
+
319
+ ### 4. (Migrating from launchd) Unload the old agent
297
320
 
298
321
  If you previously ran Kanna under launchd, unload it once so pm2 can take over:
299
322
 
@@ -301,7 +324,7 @@ If you previously ran Kanna under launchd, unload it once so pm2 can take over:
301
324
  launchctl bootout gui/$(id -u)/io.silentium.kanna || true
302
325
  ```
303
326
 
304
- ### 3. First deploy
327
+ ### 5. First deploy
305
328
 
306
329
  `scripts/deploy.sh` installs pm2 if missing, renders `scripts/pm2.config.cjs` from the template (via `envsubst` from `brew install gettext`), and starts the pm2 process:
307
330
 
@@ -315,7 +338,7 @@ pm2 logs kanna --lines 50
315
338
 
316
339
  The pm2 config sets `KANNA_RELOADER=pm2` and `KANNA_REPO_DIR=<repo>` so the in-app Update button triggers the pm2 reload pipeline (see next section). Override the pm2 process name with `KANNA_PM2_PROCESS_NAME` before running `./scripts/deploy.sh` if you need to run multiple instances.
317
340
 
318
- ### 4. Redeploy / update
341
+ ### 6. Redeploy / update
319
342
 
320
343
  Two ways to ship a new build:
321
344
 
@@ -328,7 +351,20 @@ git pull
328
351
  ./scripts/deploy.sh
329
352
  ```
330
353
 
331
- ### 5. Update strategies
354
+ ### 7. Troubleshooting: 403 on login
355
+
356
+ If the login screen rejects the correct password with **403** behind a Cloudflare (or any HTTPS-terminating) tunnel, the server is running without `trustProxy` enabled. The CSRF origin check then compares the browser's `https://kanna.example.com` `Origin` against the local `http://127.0.0.1:<port>` `req.url` and rejects them as mismatched. Two ways to enable it:
357
+
358
+ - **Recommended.** Pass `--cloudflared <TOKEN>` (or `--share`) on the kanna command line. Both flags auto-enable `trustProxy` and bind to `127.0.0.1`. With `scripts/pm2.env` populated, `scripts/deploy.sh` does this for you — verify with `pm2 logs kanna --lines 20` that the startup line includes `--cloudflared`.
359
+ - **Running cloudflared separately?** Use `--cloudflared` on kanna anyway and let kanna spawn the tunnel; the standalone `cloudflared` daemon does not set `trustProxy` for you. (There is no standalone `--trust-proxy` CLI flag today.)
360
+
361
+ Other things to check if the 403 persists:
362
+
363
+ - Cloudflare tunnel **public hostname** points to `http://localhost:<KANNA_PORT>`, not `https://` — kanna terminates plain HTTP locally.
364
+ - The public hostname's **TLS mode** is `Full` or `Flexible` (Cloudflare → Origin is HTTP), not `Full (strict)` against a self-signed origin.
365
+ - No `Access` policy in front of the hostname is stripping or rewriting the `Origin` header.
366
+
367
+ ### 8. Update strategies
332
368
 
333
369
  The update mechanism is abstracted behind `UpdateChecker` + `UpdateReloader` interfaces in `src/server/update-strategy.ts`, selected at startup by `KANNA_RELOADER`:
334
370