burrow-cli 0.0.0-stage → 0.1.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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +594 -2
  3. package/bin/burrow.js +200 -0
  4. package/examples/acme-shop.tunnel.yml +18 -0
  5. package/package.json +45 -4
  6. package/src/access.js +163 -0
  7. package/src/add.js +106 -0
  8. package/src/cloudflare.js +131 -0
  9. package/src/commands.js +386 -0
  10. package/src/completion.js +127 -0
  11. package/src/config-file.js +31 -0
  12. package/src/config.js +82 -0
  13. package/src/dashboard/auth.js +79 -0
  14. package/src/dashboard/data.js +70 -0
  15. package/src/dashboard/logs.js +95 -0
  16. package/src/dashboard/manage.js +102 -0
  17. package/src/dashboard/panels/README.md +50 -0
  18. package/src/dashboard/panels/access.js +218 -0
  19. package/src/dashboard/panels/alerts.js +244 -0
  20. package/src/dashboard/panels/backup.js +193 -0
  21. package/src/dashboard/panels/bulk.js +246 -0
  22. package/src/dashboard/panels/cleanup.js +237 -0
  23. package/src/dashboard/panels/doctor.js +119 -0
  24. package/src/dashboard/panels/health.js +146 -0
  25. package/src/dashboard/panels/history.js +104 -0
  26. package/src/dashboard/panels/hooks.js +86 -0
  27. package/src/dashboard/panels/live.js +153 -0
  28. package/src/dashboard/panels/project-form.js +463 -0
  29. package/src/dashboard/panels/quick-actions.js +133 -0
  30. package/src/dashboard/panels/sessions.js +267 -0
  31. package/src/dashboard/panels/shares.js +280 -0
  32. package/src/dashboard/panels/stats.js +165 -0
  33. package/src/dashboard/panels/updates.js +156 -0
  34. package/src/dashboard/panels/uptime.js +115 -0
  35. package/src/dashboard/panels.js +53 -0
  36. package/src/dashboard/server.js +390 -0
  37. package/src/dashboard/session-store.js +47 -0
  38. package/src/dashboard/totp.js +103 -0
  39. package/src/dashboard/ui.js +454 -0
  40. package/src/doctor.js +342 -0
  41. package/src/edit.js +135 -0
  42. package/src/health-observer.js +81 -0
  43. package/src/history.js +145 -0
  44. package/src/hooks.js +256 -0
  45. package/src/naming.js +38 -0
  46. package/src/open.js +67 -0
  47. package/src/pending.js +72 -0
  48. package/src/process.js +95 -0
  49. package/src/project-form.js +134 -0
  50. package/src/project.js +114 -0
  51. package/src/prune.js +99 -0
  52. package/src/rename-state.js +39 -0
  53. package/src/restart.js +35 -0
  54. package/src/service.js +173 -0
  55. package/src/share-expiry.js +55 -0
  56. package/src/share.js +275 -0
  57. package/src/shell-words.js +284 -0
  58. package/src/stats.js +180 -0
  59. package/src/transfer.js +124 -0
  60. package/src/update.js +254 -0
  61. package/src/uptime.js +91 -0
  62. package/src/watch.js +263 -0
  63. package/src/zones.js +102 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zafir Sk Heerah
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,595 @@
1
- # Temporary Holding Version
1
+ # burrow
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `burrow` is a small CLI that exposes local projects through **Cloudflare Tunnel**.
4
+ It creates a remotely-managed tunnel, its ingress rules and the DNS records through
5
+ the Cloudflare API, and runs `cloudflared` in the background. `burrow down` stops it; `burrow destroy` removes
6
+ all of it, so no stale tunnels or CNAMEs are left behind.
7
+
8
+ ![burrow dashboard: tunnel list](docs/dashboard.png)
9
+
10
+ ## Naming rule
11
+
12
+ Only flat, one-level hostnames are used, so Cloudflare's free Universal SSL
13
+ certificate (`*.<domain>`) covers every hostname:
14
+
15
+ | Service | Hostname |
16
+ | ------------------ | ------------------------------ |
17
+ | root (`app`) | `<project>.<domain>` |
18
+ | any other service | `<service>-<project>.<domain>` |
19
+
20
+ Example with `BURROW_DOMAIN=example.dev`: `acme-shop.example.dev`,
21
+ `mail-acme-shop.example.dev`, `studio-acme-shop.example.dev`.
22
+
23
+ Cloudflare objects are named and tagged so burrow can find them again:
24
+
25
+ - tunnel: `burrow-<project>`
26
+ - DNS records: proxied `CNAME <host> -> <tunnel-id>.cfargotunnel.com` with comment `burrow:<project>`
27
+
28
+ ## Install
29
+
30
+ Requires Node 18+ and [`cloudflared`](https://github.com/cloudflare/cloudflared/releases).
31
+ From npm (the package is `burrow-cli`; it installs the `burrow` command globally, with its dependencies):
32
+
33
+ ```sh
34
+ npm install -g burrow-cli
35
+ ```
36
+
37
+ Or from git, to follow a branch or a tag:
38
+
39
+ ```sh
40
+ npm install -g github:zfir-dev/burrow-cli # or git+ssh://git@github.com/zfir-dev/burrow-cli.git
41
+ npm install -g github:zfir-dev/burrow-cli#main # a branch or tag
42
+ ```
43
+
44
+ From a checkout (handy while hacking on it, since edits apply immediately):
45
+
46
+ ```sh
47
+ git clone <this-repo-url> burrow && cd burrow
48
+ npm install
49
+ npm link # or: npm install -g .
50
+ ```
51
+
52
+ Check it with `burrow --version`. Remove it with `npm uninstall -g burrow-cli` (or `npm unlink -g burrow-cli` for a checkout).
53
+
54
+ With nvm, global packages belong to the active Node version, so reinstall after switching
55
+ versions. The systemd unit (if you use one) records the Node binary path when it is installed.
56
+
57
+ ## Setup
58
+
59
+ 1. Add the tunnel domain to Cloudflare (it has to be an active zone).
60
+ 2. Create an API token at **My Profile > API Tokens > Create Token > Custom token**:
61
+ - **Account > Cloudflare Tunnel > Edit**
62
+ - **Zone > DNS > Edit**, limited to the tunnel domain's zone
63
+ - optional **Zone > Analytics > Read**, only for `burrow stats`
64
+ - optional **Zone > Zone > Read**, only if you leave `CF_ZONE_ID` empty (used to look up the zone ID)
65
+ - optional **Account > Access: Apps and Policies > Edit**, only for services with `private: true`
66
+ 3. Run `burrow init`. It writes `~/.config/burrow/config.env` (mode 600):
67
+
68
+ ```env
69
+ CF_API_TOKEN=...
70
+ CF_ACCOUNT_ID=...
71
+ CF_ZONE_ID= # optional
72
+ BURROW_DOMAIN=example.dev
73
+ BURROW_DASHBOARD_PASSWORD=... # for burrow dashboard, 12+ characters
74
+ BURROW_DASHBOARD_PORT=7070
75
+ CLOUDFLARED_BIN=cloudflared
76
+ ```
77
+
78
+ 4. Fill it in and run `burrow init` again. It verifies the token
79
+ (`/user/tokens/verify`) and checks tunnel and DNS access. The token is never printed.
80
+
81
+ Every value can also come from the environment. `BURROW_CONFIG` and
82
+ `BURROW_STATE_DIR` override the config file and state directory paths.
83
+
84
+ ## tunnel.yml
85
+
86
+ Put a `tunnel.yml` in the project directory, or pass one with `-f`.
87
+
88
+ ```yaml
89
+ project: acme-shop
90
+ services:
91
+ - name: app # "app" is the root service (or set root: true on one service)
92
+ url: http://localhost:3100
93
+ paths: # path rules on the same hostname, checked first
94
+ - { path: /auth/v1, url: http://localhost:54321 }
95
+ - { path: /rest/v1, url: http://localhost:54321 }
96
+ - { path: /storage/v1, url: http://localhost:54321 }
97
+ - { path: /realtime/v1, url: http://localhost:54321 }
98
+ - name: mail
99
+ url: http://localhost:54324
100
+ - name: studio
101
+ url: http://localhost:54323
102
+ ```
103
+
104
+ - `project` and `name` must be lowercase DNS labels with no dots.
105
+ - `domain: example.org` (optional) uses another Cloudflare zone on the same account for this project
106
+ instead of `BURROW_DOMAIN` ([details](docs/domains.md)).
107
+ - `paths[].path` is a prefix. `/auth/v1` matches `/auth/v1` and everything below it.
108
+ A value that starts with `^` is used as a raw regex.
109
+ - `originRequest` (on a service or a path) is passed through to cloudflared, e.g.
110
+ `originRequest: { noTLSVerify: true }`.
111
+ - `private: true` on a service puts its hostname behind **Cloudflare Access** (login by email),
112
+ allowing `allow: [you@example.dev, "@example.dev"]` or `BURROW_ACCESS_EMAILS`. Services stay
113
+ public by default ([details](docs/access.md)).
114
+ - burrow adds a final `http_status:404` rule.
115
+ - `hooks:` runs shell commands in the project directory around `up` and `down` (`pre_up`, `post_up`,
116
+ `pre_down`, `post_down`), e.g. start `next dev` in the background before the tunnel comes up
117
+ ([details](docs/hooks.md)). `--no-hooks` skips them.
118
+ - `autostart: true` makes `burrow service` bring the project up at boot ([details](docs/service.md)).
119
+
120
+ See [`examples/acme-shop.tunnel.yml`](examples/acme-shop.tunnel.yml).
121
+
122
+ ## Commands
123
+
124
+ | Command | What it does |
125
+ | -------------------------------- | ------------ |
126
+ | `burrow init` | Write the config template, or verify the token and access |
127
+ | `burrow update` | Update burrow itself: a git checkout gets `git pull --ff-only` + `npm install`, a global npm install is reinstalled (`npm i -g burrow-cli@latest` for a registry install, or from its git source); `--check` only reports newer commits ([details](docs/update.md)) |
128
+ | `burrow add [project]` | Create a `tunnel.yml` by answering prompts, or non-interactively with `--app`, `--path`, `--service` ([details](docs/add.md)) |
129
+ | `burrow up [project]` | Create or reuse tunnel `burrow-<project>`, PUT its ingress config, upsert the CNAMEs (and remove stale ones tagged for this project), then (re)start `cloudflared` in the background |
130
+ | `burrow edit [project]` | Open `tunnel.yml` in `$EDITOR` (or `vi`/`nano`), validate it on save (a broken edit never replaces the file), and offer to re-run `up` if the project is running; `--yes`, `--no-apply` ([details](docs/edit.md)) |
131
+ | `burrow share <port>` | Share a local port on a temporary `<random>.<domain>` hostname; Ctrl+C, `burrow down` or `burrow destroy` removes it, `--expires 2h` ends it on its own ([details](docs/share.md)) |
132
+ | `burrow down [project]` | Stop that project's `cloudflared` only. The tunnel and DNS records are kept, so the next `up` is quick |
133
+ | `burrow restart [project]` | Re-sync the tunnel config and DNS and restart `cloudflared` (same as `up`, which reuses the tunnel). With no project, restarts every connector that is running now; `--dry-run` shows the plan, `--no-hooks` skips the `pre_up`/`post_up` hooks. Detached shares are restarted on the same hostname, shares still attached to a `burrow share` in the foreground are skipped ([details](docs/share.md#restart-completion-and-export)) |
134
+ | `burrow down` | Stop **every** running burrow connector (each pid in `~/.local/state/burrow/`) |
135
+ | `burrow export [file]` / `burrow import <file>` | Export remembered project configs to YAML/JSON (tunnel.yml fields only, never tokens or passwords) and import them on another machine ([details](docs/export-import.md)) |
136
+ | `burrow destroy [project]` | Stop `cloudflared`, delete DNS records tagged `burrow:<project>`, delete the tunnel's connections and the tunnel. `burrow down <project> --purge` does the same. DNS in a zone that can't be read right now is queued and retried by `burrow prune` ([details](docs/prune.md#queued-dns-deletions)) |
137
+ | `burrow url [project]` / `burrow open [project] [service]` | Print a project's `https://` URLs (`--plain` for URLs only), or open one in the browser (`$BROWSER`, `xdg-open` or `open`; `--print` just prints it). Inside a project directory `burrow open mail` opens the `mail` service |
138
+ | `burrow destroy --all` | Delete every `burrow-*` tunnel and every `burrow:*` DNS record, and stop all local connectors. Asks `[y/N]` first; `--yes` skips the prompt (needed in non-interactive shells) |
139
+ | `burrow prune` | Find orphaned `burrow:*` DNS records and `burrow-*` tunnels with no local state; lists them and asks before deleting (`--dry-run`, `--yes`) ([details](docs/prune.md)) |
140
+ | `burrow dashboard` | Run the web dashboard in the foreground on `127.0.0.1:7070` |
141
+ | `burrow doctor [project]` | Check config, token, zone, cloudflared and whether each local service port answers, plus each project's `domain:` zone and `hooks:`; pass/fail per line ([details](docs/doctor.md)) |
142
+ | `burrow dashboard up` | Start the dashboard in the background and expose it at `https://burrow.<domain>` through its own tunnel (`--no-tunnel` for local only) |
143
+ | `burrow service install\|uninstall\|status` | systemd user unit that runs `burrow up` at boot for projects with `autostart: true` or listed in `BURROW_AUTOSTART` ([details](docs/service.md)) |
144
+ | `burrow dashboard down` | Stop the dashboard server and its tunnel connector (tunnel and DNS are kept) |
145
+ | `burrow completion bash\|zsh` | Print a completion script for commands, options and project names. Add `source <(burrow completion zsh)` (or `bash`) to your shell rc file |
146
+ | `burrow dashboard status` | Server, connector, URL, whether a password is set |
147
+ | `burrow ls` | List `burrow-*` tunnels with their hostnames and local running state (`--json` for a machine-readable array). A zone whose DNS can't be read is reported, not fatal ([details](docs/domains.md#when-a-zone-cant-be-read)) |
148
+ | `burrow status [project]` | Local process, tunnel health, DNS records (`--json` for an object with `running`, `pid`, `tunnel`, `records`, `zoneError`) |
149
+ | `burrow stats [project]` | Requests, bandwidth and 2xx/3xx/4xx/5xx counts per hostname from Cloudflare's GraphQL Analytics (`--since 24h`, `--json`). Needs **Zone > Analytics > Read** ([details](docs/stats.md)) |
150
+ | `burrow logs [project]` | Show the cloudflared log (`-n 200`, `--follow`) |
151
+ | `burrow watch [projects...]` | Check connectors, tunnel health and local service ports every `--interval` seconds and alert on changes through `BURROW_ALERT_WEBHOOK` (JSON; Slack/Discord-compatible) and/or `BURROW_ALERT_NTFY`; `--debounce`, `--once` for cron, `--install-service` for a systemd unit ([details](docs/alerts.md)) |
152
+
153
+ `destroy` with no project and no `--all` refuses to run.
154
+
155
+ Options:
156
+
157
+ - `-f, --file <path>` uses a specific tunnel.yml (and picks its project).
158
+ - `--dry-run` (`up`, `down`, `destroy`) prints the plan. `up` and `down` stay fully offline.
159
+ `destroy --all --dry-run` lists what is on Cloudflare when a token is configured.
160
+ - `--force` (`up`) replaces existing DNS records on the same hostnames that burrow doesn't manage.
161
+ Without it, burrow refuses to touch them.
162
+
163
+ `up` is idempotent, so run it again after editing tunnel.yml. Once a project has been
164
+ brought up, `burrow up <project>` works from any directory because burrow remembers
165
+ where its tunnel.yml lives.
166
+
167
+ State lives in `~/.local/state/burrow/`: `<project>.pid`, `<project>.log` and
168
+ `<project>.json` (tunnel id, file path). The tunnel token goes to cloudflared through
169
+ the `TUNNEL_TOKEN` environment variable. It is never written to disk or shown in `ps`.
170
+
171
+ ## Dashboard
172
+
173
+ `burrow dashboard up` starts a small web UI and runs `burrow up` for a built-in project called `burrow`, which maps
174
+ `https://burrow.<domain>` to `http://localhost:<BURROW_DASHBOARD_PORT>`. Its tunnel is
175
+ `burrow-burrow` with DNS comment `burrow:burrow`, and `burrow` is reserved as a project name.
176
+
177
+ The server is Node's built-in `http`. The UI uses [Pico CSS](https://picocss.com) (automatic
178
+ light/dark theme) and [Alpine.js](https://alpinejs.dev) with **no build step**. Both are npm
179
+ dependencies pinned to exact versions (`@picocss/pico` 2.1.1, `@alpinejs/csp` 3.17.5). The
180
+ server serves them from `node_modules` at `/vendor/pico.min.css` and `/vendor/alpine.min.js`,
181
+ so the dashboard works offline and never loads anything from a CDN. It uses Alpine's
182
+ [CSP build](https://alpinejs.dev/advanced/csp), so the Content-Security-Policy needs neither
183
+ `'unsafe-eval'` nor `'unsafe-inline'` (`script-src 'self'; style-src 'self'`). All UI logic is
184
+ in `Alpine.data()` components in `src/dashboard/ui.js`.
185
+
186
+ It shows every burrow project with:
187
+
188
+ - clickable hostnames
189
+ - local cloudflared state (running/stopped, pid, uptime)
190
+ - connector status from the Cloudflare API (healthy/degraded/down, connections, colos)
191
+ - a live log viewer that streams `~/.local/state/burrow/<project>.log` over SSE
192
+ - **Up** / **Down** buttons and **Destroy…** (in the row's **⋯** menu). **Destroy** opens a dialog and stays disabled until you type the project name.
193
+ The dashboard's own project can't be stopped from the UI.
194
+
195
+ | Sign in | Live logs |
196
+ | ------- | --------- |
197
+ | ![login](docs/dashboard-login.png) | ![log viewer](docs/dashboard-logs.png) |
198
+
199
+ The screenshots use fake demo data (`example.dev`, a mock Cloudflare API and made-up logs).
200
+
201
+ Security:
202
+
203
+ - The dashboard won't start unless `BURROW_DASHBOARD_PASSWORD` is set (12+ characters).
204
+ - The password is compared in constant time and is never logged. The login form posts with
205
+ `fetch` (JSON), and a plain HTML form post still works without JavaScript.
206
+ - Sessions use an HMAC-signed, `HttpOnly; Secure; SameSite=Strict` cookie (12 h), also tracked
207
+ server-side so **Sign out** really ends them. Restarting the server or changing the password
208
+ signs everyone out.
209
+ - Logins are limited to 5 failed attempts per IP per 15 minutes (429 after that). Behind the
210
+ tunnel the client IP comes from `CF-Connecting-IP`, which is trusted only from loopback.
211
+ - Every state-changing request needs an `X-Burrow: 1` header (CSRF protection). Responses carry a
212
+ strict CSP, `X-Frame-Options: DENY` and `no-store`.
213
+ - The server binds to `127.0.0.1` by default, so it is reachable only through the tunnel or
214
+ locally. Open it over HTTPS (or `http://localhost`), because the Secure cookie isn't sent over
215
+ plain HTTP to other hosts.
216
+
217
+ ### Panels
218
+
219
+ Dashboard features beyond the tunnel table are **panels**: one file each in
220
+ `src/dashboard/panels/`, loaded at start-up. A panel can add HTML at fixed slots (toolbar,
221
+ table cells, row buttons, sections, dialogs), an Alpine mixin, CSS, vendored files, API routes
222
+ and extra fields on `/api/tunnels`. Panel routes run only after the session check, and their
223
+ POSTs need the same `X-Burrow: 1` header, so every feature gets the same login, cookie and CSRF
224
+ protection. Commands the dashboard runs get `BURROW_SOURCE=dashboard` in their environment.
225
+ See [`src/dashboard/panels/README.md`](src/dashboard/panels/README.md) for the interface.
226
+
227
+ The page is laid out to fit a 1280px-wide screen with every panel loaded, without scrolling
228
+ sideways: the panels' buttons (**Shares**, **History**, **Uptime**, **Alerts**, **Hooks**,
229
+ **Cleanup**, **Doctor**, **Backup**, **Sessions**) are in the **More** menu of the top bar, which
230
+ otherwise keeps **Live**, **New project**, the bulk **Start**/**Stop**, **All logs**, **Refresh**
231
+ and **Sign out** on one row. Badges after a project name (such as **hook failed**) wrap under the
232
+ name, and rarely used row actions are in the row's **⋯** menu.
233
+
234
+ The table stays within the window with every panel merged: each row shows **Logs**, **Up** and
235
+ **Down**, and the rest (**Destroy…** and panel actions such as Edit, Stats and Restart) are in
236
+ the row's **⋯** menu. Long hostnames are shortened with an ellipsis (hover for the full name), the
237
+ Uptime column is hidden below 1240 px, and below 1180 px each project becomes a card, so it also
238
+ works on a phone. In card view, cells without an obvious meaning carry a small label (**Boot** in
239
+ front of the start-at-boot switch, **up** in front of the uptime).
240
+
241
+ ### Add and edit projects
242
+
243
+ **New project** (top bar) and **Edit** (per row) open a form for the domain, the app port or URL,
244
+ extra paths on the app, sub-services and `autostart`. **Check** shows the hostnames and the
245
+ `tunnel.yml` it will write; **Save** validates it with the same rules as `burrow up` and can run
246
+ `burrow up` right after (on by default for new and running projects).
247
+
248
+ - New files go to `~/.config/burrow/projects/<project>.tunnel.yml` (where `burrow import` puts
249
+ them) and are remembered, so **Up** works straight away. Existing names are refused.
250
+ - Edits go to the file `burrow up` remembered. They're made in place, so comments and keys the
251
+ form doesn't show (`hooks`, `private`, `originRequest`, …) are kept. The
252
+ dashboard's own project and shares can't be edited.
253
+ - **Domain** picks the project's zone ([per-project domains](docs/domains.md)). The default is
254
+ `BURROW_DOMAIN`, which writes no `domain:` key. The list has the Cloudflare zones on the
255
+ account (fetched with the dashboard's token, cached for 5 minutes, with a zone's status if it
256
+ isn't active yet), zones burrow has cached, and domains other projects use. **Other domain…**
257
+ takes any name. Changing an existing project's domain moves its hostnames: the next
258
+ `burrow up` deletes the records in the old zone and creates them in the new one.
259
+ `GET /api/domains` returns the choices.
260
+ - The browser never sends a file path.
261
+
262
+ **Rename…** in the edit form renames a project. Hostnames and the tunnel name are built from the
263
+ project name, so a rename really replaces the project in Cloudflare, and it's done the safe way:
264
+
265
+ 1. The project must be stopped (**Down** first); the dialog shows every old → new hostname (on the
266
+ project's own domain) before
267
+ anything happens, and names already used locally or by a Cloudflare tunnel are refused.
268
+ 2. `burrow destroy <old>` deletes the old tunnel and DNS records. If that fails, nothing else is
269
+ changed.
270
+ 3. Only `project:` in `tunnel.yml` changes (comments and other keys stay); a file in
271
+ `~/.config/burrow/projects/` is renamed to `<new>.tunnel.yml`. The new name is remembered.
272
+ 4. Optionally `burrow up <new>` creates the new tunnel and DNS records straight away.
273
+
274
+ Old URLs stop working. The project's local state moves with it: its cloudflared log
275
+ (`<old>.log` becomes `<new>.log`, appended to one that already exists), the background `pre_up`
276
+ log, and its `burrow watch` state. The event history and hook results keep the old name.
277
+ `POST /api/projects/<old>/rename {to, confirm: true, up}`; `dryRun: true` only returns the plan.
278
+
279
+ ### Local port health
280
+
281
+ Each hostname gets a dot for the local port behind it, checked every 10 s with a TCP connect
282
+ (the same check `burrow watch` uses; results are cached for 3 s):
283
+
284
+ - **green**: the port answers and the tunnel is up
285
+ - **red**: the app is down (nothing listening on its port; a service with paths is red if any of its ports is closed)
286
+ - **orange**: the app answers but the tunnel is down (cloudflared stopped, or no Cloudflare connections)
287
+ - **grey**: nothing to check (`http_status:…`) or no remembered `tunnel.yml`
288
+
289
+ Under the Local state a line says which it is, e.g. `app down: api :3001` or
290
+ `tunnel down: cloudflared stopped`. Hover a dot for the host and port.
291
+
292
+ ### Request stats
293
+
294
+ **Stats** on a row opens requests, bandwidth and status classes per hostname for the last
295
+ hour, 6 hours, 24 hours or 7 days, plus an inline-SVG chart of requests with 4xx and 5xx lines
296
+ (15-minute buckets up to 6 h, hourly beyond). Pick a hostname to chart only that one. It uses the
297
+ same Cloudflare GraphQL Analytics query as `burrow stats`, so the token needs
298
+ **Zone > Analytics > Read**; without it the panel shows the permission error. Results are cached
299
+ for 60 s per project and window, and Cloudflare samples these numbers.
300
+
301
+ ### Logs
302
+
303
+ The log viewer (**Logs** on a row, or **All logs** in the top bar for every tunnel at once):
304
+
305
+ - **Search** filters lines as you type (in the combined view it matches project names too).
306
+ - **Level** filter: all, info and up, warnings and errors, or errors only. Levels come from
307
+ cloudflared's `DBG/INF/WRN/ERR` (and `level=…`); warnings and errors are coloured.
308
+ - **All logs** interleaves every `~/.local/state/burrow/*.log` by timestamp, tags each line with
309
+ its project, and picks up projects that start logging later.
310
+ - **Download** saves the log as a file: the last 10 MB of one project, or the last 2 MB of each
311
+ project merged into one file for **All logs**.
312
+
313
+ The viewer keeps the newest 3000 lines in the browser.
314
+
315
+ ### Quick actions
316
+
317
+ Next to every hostname (hover to highlight) are three small icons: **copy** copies the URL, **open** (arrow out of a box) opens it in a new tab,
318
+ and **QR** shows a QR code to open it on a phone. The icons are inline SVG, so they look the same on every system and need no icon font. **Restart** on a row re-syncs `tunnel.yml` and
319
+ restarts cloudflared, like `burrow restart <project>` (not for the dashboard's own project).
320
+
321
+ The QR code is drawn in the browser by [qrcode-generator](https://github.com/kazuhikoarase/qrcode-generator)
322
+ (MIT, pinned to 2.0.4), served from `node_modules` at `/vendor/qrcode.js` and loaded the first time
323
+ you open a QR code, so it works offline and needs no CSP change (the image is a `data:` URL).
324
+ Copying uses the Clipboard API on HTTPS or localhost and falls back to a selection copy.
325
+
326
+ ### Event history
327
+
328
+ **History** in the top bar lists what changed and when: `up`, `down`, `destroy`, `restart`,
329
+ `share`, `prune`, `add`, `edit`, `import`, `autostart`, `service install|uninstall`,
330
+ `dashboard up|down` and `update`, with the project, the result (ok/failed), how long it took and
331
+ where it came from:
332
+
333
+ - `cli`: you ran it in a shell
334
+ - `dashboard`: a button in the dashboard (the dashboard runs the CLI with `BURROW_SOURCE=dashboard`),
335
+ or a dashboard-only action such as saving a `tunnel.yml` from the form
336
+ - `boot`: `burrow autostart` from the systemd unit
337
+
338
+ Dashboard **sign-in** (ok or wrong password, with the client IP) and **sign-out** are recorded
339
+ too, as `dashboard` events; the password never is. So are wrong or missing two-factor codes, and
340
+ sign-ins refused by the rate limit (5 failures per IP in 15 minutes): one entry per IP per
341
+ minute, `blocked by the rate limit from <ip>; retry in <n>s`, saying how many more were refused
342
+ since the previous entry. The server log still has every refused attempt.
343
+
344
+ A run that is cut short still leaves an entry, marked failed unless it exited with code 0:
345
+ `stopped by SIGINT` (Ctrl+C), `stopped by SIGTERM` / `SIGHUP`, or `exited before finishing`
346
+ when a command calls `process.exit()`. The exit code stays what it was (130 for Ctrl+C,
347
+ 143 for SIGTERM), and a command with its own Ctrl+C cleanup (such as `share`) still runs it.
348
+ Only `kill -9` (SIGKILL) leaves no entry: the kernel ends the process without running any of
349
+ its code, so nothing can be written. The same goes for a power loss or the OOM killer. If a
350
+ command seems to be missing from the history, check whether it was killed that way (for example
351
+ `journalctl -k` for the OOM killer); its effects (a running connector, DNS records) are still
352
+ visible in the project table.
353
+
354
+ Filter by project or source. Read-only commands (`ls`, `status`, `logs`, `stats`, …) and
355
+ `--dry-run` aren't recorded. Events are JSON Lines in `~/.local/state/burrow/history/events.jsonl`
356
+ (mode 600, no secrets); past 1 MB the file is cut to the newest 2000 events. Recording is best
357
+ effort and never makes a command fail.
358
+
359
+ ### Alerts
360
+
361
+ **Alerts** in the top bar configures [`burrow watch`](docs/alerts.md) from the browser:
362
+
363
+ - **Watcher**: install (or reinstall with a new interval and debounce) and uninstall the
364
+ `burrow-watch.service` systemd user unit, with its current state. Uninstalling asks first.
365
+ - **Channels**: set or remove the webhook (Slack, Discord or JSON), the ntfy topic or URL, and
366
+ the ntfy token. They're written to the burrow config file (kept at mode 600, other lines
367
+ untouched) and never sent back to the browser or logged; the page only shows what kind of
368
+ channel is set and its host. Values from the environment win over the file and are marked `(env)`.
369
+ - **Send test alert** delivers a `burrow-test is degraded` message to every channel and shows
370
+ any delivery errors.
371
+ - **Last seen by the watcher** lists the state `burrow watch` keeps per project (status, since
372
+ when, and a change it's still debouncing).
373
+
374
+ ### Cleanup
375
+
376
+ **Cleanup** in the top bar scans Cloudflare for orphans with the same rules as
377
+ [`burrow prune`](docs/prune.md): `burrow-*` tunnels with no local state on this machine, and
378
+ `burrow:*` DNS records whose tunnel is gone, points elsewhere, or is an orphan itself. Tunnels with
379
+ live connections but no local state (probably another machine) are left out unless you switch on
380
+ **Include tunnels with live connections**.
381
+
382
+ Everything found is pre-selected; untick what you want to keep. **Delete** asks you to type
383
+ `delete`. The server then scans again and deletes only picks that are still orphans (the DNS
384
+ records of a deleted tunnel go with it), so an out-of-date page can't delete a live tunnel.
385
+
386
+ DNS records are checked in every zone burrow knows about: `BURROW_DOMAIN`'s, the zones of
387
+ projects with their own [`domain:`](docs/domains.md), and zones cached from earlier runs. The
388
+ page lists the zones it checked; a zone whose DNS can't be read (for example a domain since
389
+ removed from the account) is shown as **not scanned** and skipped, and the rest still works.
390
+ That includes `BURROW_DOMAIN`'s own zone: if it can't be found, the scan and deletes still run
391
+ for the other zones, and the default domain appears as **not scanned** with the reason.
392
+
393
+ If a project is destroyed (or deleted from the dashboard) while one of those zones can't be
394
+ read, the tunnel is still deleted and its DNS deletion is queued in
395
+ `~/.local/state/burrow/cleanup/pending.json` (mode 600) instead of being forgotten. The panel
396
+ lists queued deletions under **Queued DNS deletions** with **Retry now**
397
+ (`POST /api/cleanup/pending/retry`); `burrow prune` retries them too. A project that has been
398
+ set up again by then keeps its records and the entry is dropped.
399
+
400
+ ### Bulk actions and auto-start
401
+
402
+ Tick the checkboxes in front of projects (or the header box for all of them) and use **Start** / **Stop** in the toolbar. Projects run one after another, each with the same busy lock as the row buttons; the result lists every project and the call returns `207` when some failed. The built-in `burrow` project can't be picked.
403
+
404
+ The **Boot** switch sets `autostart: true` in the project's tunnel file (comments and other keys are kept). Projects listed in `BURROW_AUTOSTART` show a locked switch: change those in `~/.config/burrow/config.env`. Projects without a tunnel file can't be toggled.
405
+
406
+ The bar under the table shows the `burrow.service` systemd unit and which projects it brings up. **Install** runs `burrow service install --now`; **Uninstall** asks first, because systemd runs `burrow down` when it stops the unit (every connector stops, tunnels and DNS are kept).
407
+
408
+ Endpoints: `POST /api/bulk {action: up|down|restart, projects: [...]}` (at most 50), `POST /api/autostart/:project {enabled}`, `GET /api/boot`, `POST /api/boot {action: install|uninstall, confirm}`.
409
+
410
+ Server state lives in `~/.local/state/burrow/dashboard/server.{pid,log}`. A bare
411
+ `burrow down` also stops the dashboard's tunnel connector, so run `burrow dashboard up` to bring it back.
412
+
413
+ ### Live updates
414
+
415
+ The page keeps itself current over a server-sent event stream (`GET /api/stream`) instead of
416
+ polling. While at least one page is open, the dashboard rebuilds the project list every 3
417
+ seconds and pushes `changed` when anything differs (the page then reloads the list), or a
418
+ `tick` with the server clock otherwise. Actions taken from the dashboard trigger a check right
419
+ away. The toolbar shows **Live**, **Connecting** or **Polling**.
420
+
421
+ The stream needs a signed-in session like every other endpoint. Each stream closes after 5
422
+ minutes and the page reconnects, so a signed-out session stops getting updates. If the stream
423
+ fails twice in a row, the page polls every 5 seconds and keeps retrying with backoff (up to 30
424
+ seconds). At most 20 streams are open at once; extra pages get `503` and poll.
425
+
426
+ | Variable | Default | Does |
427
+ | --- | --- | --- |
428
+ | `BURROW_DASHBOARD_LIVE` | on | `off` turns the stream off; pages poll every 5 seconds |
429
+ | `BURROW_LIVE_MS` | `3000` | How often the server checks for changes |
430
+ | `BURROW_LIVE_MAX_CLIENTS` | `20` | Open streams allowed at once |
431
+
432
+ ### Shares
433
+
434
+ **Shares** in the toolbar starts a temporary link to a local port or URL, the same as
435
+ `burrow share <target> --detach`. Pick a name (or leave it blank for a random one) and an
436
+ expiry: 15 minutes, 1 hour, 4 hours, 1 day, 7 days or never. The panel lists this machine's
437
+ shares with their link, target and time left. **+1 hour** resets the expiry to an hour from now.
438
+ **Stop** asks first, then stops cloudflared and deletes the share's tunnel and DNS record
439
+ (`burrow down share-<name>`).
440
+
441
+ A share with an expiry is removed on time even when the dashboard isn't running: each one has
442
+ a small background expiry watcher ([details](docs/share.md#expiry)). The dashboard also stops
443
+ expired shares within about 30 seconds, and one that expired while it was off when it starts. A share started in a terminal with
444
+ `burrow share` (with or without `--expires`) is listed too and can be extended or stopped
445
+ here: the dashboard updates its state file and that process removes the share itself
446
+ ([details](docs/share.md#from-the-dashboard)).
447
+
448
+ | Endpoint | Does |
449
+ | --- | --- |
450
+ | `GET /api/shares` | List shares: `project`, `hostname`, `target`, `expiresAt`, `running`, `foreground` |
451
+ | `POST /api/shares` | `{target, name?, expiresIn}` (minutes; `0` = never) starts a detached share |
452
+ | `POST /api/shares/<share>/extend` | `{expiresIn}` sets a new expiry from now |
453
+ | `POST /api/shares/<share>/stop` | `{confirm: true}` stops it and deletes its tunnel and DNS |
454
+
455
+ ### Cloudflare Access
456
+
457
+ **Access** (per row) lists the project's hostnames, each with a switch that puts it behind
458
+ [Cloudflare Access](docs/access.md) (`private: true`) and an optional allow list of emails and
459
+ `@domain`s. An empty list uses `BURROW_ACCESS_EMAILS`. Services stay public unless you switch
460
+ them on. Saving edits `private:`/`allow:` in the project's `tunnel.yml` in place, so comments
461
+ and other keys stay. Access apps are created and removed by `burrow up`, so **Apply now** runs
462
+ it; it's on by default when the project is running. Until then, the row shows
463
+ **access: pending** and each hostname shows **not applied yet** or **still protected**.
464
+ Protected rows show **private N**.
465
+
466
+ Making a private service public again lists the hostnames that will open up and needs an
467
+ explicit "I understand" tick (the API wants `confirmPublic: true`). The token needs
468
+ **Account > Access: Apps and Policies > Edit** only once you use `private: true`.
469
+
470
+ `GET /api/access/<project>` returns `services: [{service, hostname, private, allow, effective, applied}]`.
471
+ `POST /api/access/<project>` takes `{services: [{service, private, allow}], up, confirmPublic}`.
472
+
473
+ ### Doctor
474
+
475
+ **Doctor** in the top bar runs `burrow doctor --json --all` on the server and lists every check
476
+ with a **pass**, **warning**, **fail** or **skipped** badge: the config file and its permissions,
477
+ `CF_API_TOKEN`, `CF_ACCOUNT_ID`, `BURROW_DOMAIN`, the token, zone, tunnel and DNS permissions
478
+ (through the Cloudflare API), cloudflared, and the local services of every remembered project.
479
+ Problems come with a **Fix** line (for example `chmod 600 …`, which token permission to add, or
480
+ which local URL to start). **Skip Cloudflare API checks** runs it offline. The last report is kept
481
+ until the dashboard restarts; one run at a time. Secrets are never part of the report.
482
+
483
+ On the command line, `burrow doctor --json` prints the same report as one JSON line
484
+ (`{ counts, checks: [{ section, status, label, detail, fix }] }`), and `--all` checks every
485
+ remembered project instead of `./tunnel.yml`.
486
+
487
+ ### Uptime timeline
488
+
489
+ **Uptime** in the toolbar shows a bar per project for the last hour, 24 hours or 7 days. Each
490
+ bar is coloured **up**, **degraded**, **down**, **stopped** (on purpose) or **no data**, with
491
+ the uptime percentage and the latest incidents. The bar is built from the event history: starts,
492
+ stops and restarts from the CLI and the dashboard, plus health changes that `burrow watch`
493
+ records (action `health`, source `watch`, e.g. `down: cloudflared is not running (was ok)`).
494
+
495
+ Without `burrow watch` the dashboard records health changes itself (source `dashboard`): on
496
+ every refresh of the project list and once a minute even with no browser open, it checks
497
+ whether each started project's cloudflared is still running and what Cloudflare says about its
498
+ tunnel, and writes a `health` event when that changes (a change has to be seen twice, 15 s
499
+ apart, so a restart isn't a crash). It doesn't probe local ports (`burrow watch` does), and it
500
+ can only see a crash while the dashboard is running. While `burrow watch` is active (its state
501
+ was written in the last 5 minutes) it owns health changes and the dashboard records none.
502
+ Projects stopped with `burrow down` aren't tracked; their starts and stops are already `up` and
503
+ `down` events. The current state comes from the watch state (or the dashboard's own
504
+ observations in `~/.local/state/burrow/watch/observed.json`), or from whether cloudflared is
505
+ running.
506
+
507
+ Stopped time and time with no data don't count against the percentage. `GET /api/uptime?window=1h|24h|7d` returns
508
+ `projects: [{project, segments: [{from, to, status, pct}], uptimePct, incidents}]`.
509
+
510
+ ### Sessions and two-factor sign-in
511
+
512
+ **Sessions** in the toolbar lists the browsers signed in to the dashboard: browser and OS, IP,
513
+ when each signed in and when it was last active. Your own session is marked **this browser**.
514
+ You can sign out one session, **Sign out other sessions**, or **Sign out everywhere** (asks
515
+ first, and signs you out too). Sessions are listed by an opaque handle; session ids never leave
516
+ the server. Sessions last 12 hours and survive a restart of `burrow dashboard`: the session
517
+ list and its signing secret are kept in `~/.local/state/burrow/dashboard/sessions.json` (mode 600,
518
+ no password in it). Expired sessions are dropped when it is loaded, signing out (one, others or
519
+ everywhere) is saved at once, and changing the dashboard password still ends every session.
520
+ Deleting `sessions.json` and restarting the dashboard ends them all too.
521
+
522
+ **Two-factor sign-in** is optional and off by default. Turning it on makes sign-in ask for a
523
+ 6-digit code from an authenticator app (TOTP, SHA-1, 30 s; works with any common app):
524
+
525
+ 1. Open **Sessions** and click **Set up two-factor sign-in**.
526
+ 2. Scan the QR code with your app, or type the key shown under it. The key is shown only during
527
+ setup. Once two-factor is on, the dashboard never shows or returns it again.
528
+ 3. Enter the app's current code and click **Turn on**. A wrong code changes nothing. Setup
529
+ expires after 15 minutes. **Sign out other sessions** is ticked by default.
530
+
531
+ From then on, the sign-in page has a code field. Each code works once, and the server accepts
532
+ the code before or after the current one, to allow for clock drift. Wrong codes count toward
533
+ the same limit as wrong passwords (5 per 15 minutes per IP). **Turn off** asks first and needs
534
+ a current code that hasn't been used yet. The key is stored in
535
+ `~/.local/state/burrow/dashboard/totp.json` (mode 600). If you lose the phone, delete that file
536
+ on the server to turn two-factor off ([details](docs/two-factor.md)).
537
+
538
+ | Endpoint | Does |
539
+ | --- | --- |
540
+ | `GET /api/sessions` | `sessions: [{handle, current, createdAt, lastSeen, ip, agent}]`, `twoFactor: {enabled, pending}` |
541
+ | `POST /api/sessions/revoke` | `{handle}` signs one session out |
542
+ | `POST /api/sessions/revoke-others` | Signs out every other session |
543
+ | `POST /api/sessions/revoke-all` | `{confirm: true}` signs out every session, this one included |
544
+ | `POST /api/two-factor/setup` | Starts setup; the only response that ever carries the key |
545
+ | `POST /api/two-factor/enable` | `{code, signOutOthers}` turns it on |
546
+ | `POST /api/two-factor/disable` | `{code, confirm: true}` turns it off and deletes the key |
547
+
548
+ ### Backup and restore
549
+
550
+ **Backup** in the top bar has **Download backup**: a `burrow export` bundle of every remembered
551
+ project (`burrow-projects-<date>.yml`), with `tunnel.yml` settings only. Tokens, passwords and
552
+ `hooks:` are never in it, and temporary shares aren't either.
553
+
554
+ To restore, pick a backup file. Before anything is written, the server lists each project in it
555
+ with what would happen: **new**, **file exists** or **already remembered** (somewhere else), or
556
+ **invalid**, plus the hostnames it would get. New projects are ticked; existing ones can only be
557
+ picked with **Replace projects that already exist**. **Restore** asks you to type `restore`; the
558
+ server plans again and writes the picked projects to `~/.config/burrow/projects/<project>.tunnel.yml`
559
+ and remembers them, like `burrow import` (with `--force` for replaced ones). Nothing is started:
560
+ use **Up** afterwards. Backups are limited to 1 MB.
561
+
562
+ ### Hooks and updates
563
+
564
+ **Hooks** in the toolbar lists recent [hook](docs/hooks.md) runs: when, project, hook
565
+ (`pre_up`, `post_up`, `pre_down`, `post_down`, background or not), ok or the reason it failed
566
+ (`post_up hook failed (exit 1)`, `timed out after 120s`, …), how long it took, and where it
567
+ came from (`cli`, `dashboard`, `boot`). A row whose latest hook run failed gets a
568
+ **hook failed** badge. `burrow up` and `down` record runs in
569
+ `~/.local/state/burrow/hooks/results.jsonl`, keeping the last 500. The hook's command and
570
+ output are never recorded, because they can hold secrets. Dry runs aren't recorded.
571
+ `GET /api/hooks?project=&limit=` returns them.
572
+
573
+ The page footer shows the burrow version and whether an update is available. While a page is
574
+ open, the dashboard runs `burrow update --check --json` at most once a day and caches the
575
+ result in `~/.local/state/burrow/cache/update.json`. For a git checkout that's a `git fetch`;
576
+ for a global npm install from the registry it's `npm view burrow-cli version`, and from git a `git ls-remote` on the install source. **Check for updates**
577
+ runs it now. When newer commits exist, an **Update available** button opens the version
578
+ change, the new commits, and the commands to run in a terminal (`burrow update`, then
579
+ `burrow dashboard up`). Installing isn't done from the browser. **Remind me later** hides the
580
+ notice until something newer appears. A failed check keeps the last result and shows the
581
+ error, with any credentials in a URL removed.
582
+
583
+ | Variable | Default | Does |
584
+ | --- | --- | --- |
585
+ | `BURROW_UPDATE_CHECK` | on | `off` turns the dashboard's update check off (no git calls) |
586
+ | `BURROW_UPDATE_CHECK_HOURS` | `24` | How old the cached result can get before the next check |
587
+
588
+ ## Tests
589
+
590
+ `BURROW_CF_API_BASE` (environment only) points burrow at a mock Cloudflare API. It's used for
591
+ tests and for the README screenshots; leave it unset in normal use.
592
+
593
+ ```sh
594
+ npm test
595
+ ```