shapewall 0.6.0 → 0.7.0

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 (127) hide show
  1. package/CHANGELOG.md +252 -0
  2. package/README.md +39 -2
  3. package/THIRD_PARTY.md +15 -0
  4. package/dist/agent/package-lock.json +594 -2
  5. package/dist/client/assets/{BoardChat-DdwBcb2N.js → BoardChat-WS8mAIW6.js} +1 -1
  6. package/dist/client/assets/{BuzzDialog-DpUcnU6S.js → BuzzDialog-B-Mlr6wF.js} +1 -1
  7. package/dist/client/assets/{ChecksPanel-CngYV4yz.js → ChecksPanel-Dx1ZLBR6.js} +1 -1
  8. package/dist/client/assets/{History-CD0saQA5.js → History-sXhmpcvs.js} +1 -1
  9. package/dist/client/assets/{LocalSettings-MZy2baig.js → LocalSettings-CtGzz9F3.js} +1 -1
  10. package/dist/client/assets/{Management-CSvZ-SHO.js → Management-CGHe8Wt9.js} +1 -1
  11. package/dist/client/assets/{QuickConnect-foLh2QUm.js → QuickConnect-DEk84E4A.js} +1 -1
  12. package/dist/client/assets/{ShareDialog-DPWDftoL.js → ShareDialog-CGGx-AYK.js} +1 -1
  13. package/dist/client/assets/{app-update-dialog-CtiXpTRD.js → app-update-dialog-_bVp8hnC.js} +1 -1
  14. package/dist/client/assets/{circle-x-CteRBtXC.js → circle-x-BWoHA1QY.js} +1 -1
  15. package/dist/client/assets/index-Bm-Xd3YN.js +37 -0
  16. package/dist/client/assets/index-C7Ostk3K.css +2 -0
  17. package/dist/client/assets/{play-BjRNIGSf.js → play-BzQ3tRTv.js} +1 -1
  18. package/dist/client/assets/{refresh-cw-r_tZiFfB.js → refresh-cw-BYBMyDKT.js} +1 -1
  19. package/dist/client/assets/{ui-zQpn-PdL.js → ui-CAY6myRA.js} +1 -1
  20. package/dist/client/build-info.json +1 -1
  21. package/dist/client/index.html +3 -3
  22. package/dist/client/sw.js +2 -2
  23. package/dist/console/assets/LocalAccountsApp-CWRguRRL.js +1 -0
  24. package/dist/console/assets/LocalConsole--I2SaIpr.js +2 -0
  25. package/dist/console/assets/LocalUsage-BmpCZ36k.js +1 -0
  26. package/dist/console/assets/app-update-dialog-B8M9plaT.js +1 -0
  27. package/dist/console/assets/app-version-muKrQqbL.js +1 -0
  28. package/dist/console/assets/console-CrhTsPbz.css +2 -0
  29. package/dist/console/assets/console-DxapQ9oS.js +11 -0
  30. package/dist/console/assets/local-agents-CoqD4dSN.js +6 -0
  31. package/dist/console/assets/minus-DDQ0ydcM.js +1 -0
  32. package/dist/console/assets/tailnet-C5Flwl_d.js +2 -0
  33. package/dist/console/assets/theme-DCd0qh4l.js +1 -0
  34. package/dist/console/assets/ui-Bry1mnCY.js +41 -0
  35. package/dist/console/assets/usage-CIPWnHaS.css +1 -0
  36. package/dist/console/assets/usage-CqVjMb7m.js +5 -0
  37. package/dist/console/assets/usage-D1G0GgE3.js +56 -0
  38. package/dist/console/build-info.json +1 -1
  39. package/dist/console/console.html +8 -2
  40. package/docs/agent-hardening.md +31 -17
  41. package/docs/agents.md +35 -0
  42. package/docs/architecture.md +10 -4
  43. package/docs/deployment.md +39 -17
  44. package/docs/design-system.md +56 -7
  45. package/docs/hosted.md +1004 -43
  46. package/docs/images/board-overview.png +0 -0
  47. package/docs/images/journeys.png +0 -0
  48. package/docs/images/live-comment.png +0 -0
  49. package/docs/images/phone-comment.png +0 -0
  50. package/docs/images/phone-overview.png +0 -0
  51. package/docs/images/variant.png +0 -0
  52. package/docs/where-to-run.md +82 -1
  53. package/package.json +6 -1
  54. package/src/agent/backends/acp.js +224 -26
  55. package/src/agent/routes.js +21 -0
  56. package/src/agent/usage-log.js +251 -0
  57. package/src/cli/args.js +24 -0
  58. package/src/cli/help.js +37 -2
  59. package/src/cli/init.js +2 -1
  60. package/src/cli/serve.js +20 -5
  61. package/src/cli.js +8 -0
  62. package/src/hosted/access-cli.js +99 -1
  63. package/src/hosted/activity-core.js +232 -0
  64. package/src/hosted/activity.js +375 -0
  65. package/src/hosted/admin.js +80 -13
  66. package/src/hosted/agent-approvals.js +2 -2
  67. package/src/hosted/agent-routes.js +3 -3
  68. package/src/hosted/agents.js +11 -4
  69. package/src/hosted/app.js +89 -7
  70. package/src/hosted/auth-routes.js +156 -15
  71. package/src/hosted/auth.js +123 -20
  72. package/src/hosted/board-routes.js +3 -3
  73. package/src/hosted/chat-frames.js +5 -15
  74. package/src/hosted/chat-permissions.js +12 -0
  75. package/src/hosted/chat-routes.js +8 -8
  76. package/src/hosted/chat-store.js +20 -3
  77. package/src/hosted/comment-files.js +5 -2
  78. package/src/hosted/console-routes.js +111 -34
  79. package/src/hosted/db.js +130 -0
  80. package/src/hosted/device-routes.js +25 -3
  81. package/src/hosted/device.js +23 -4
  82. package/src/hosted/guards.js +337 -27
  83. package/src/hosted/http.js +6 -3
  84. package/src/hosted/membership.js +13 -2
  85. package/src/hosted/operator-access.js +418 -0
  86. package/src/hosted/operator.js +106 -2
  87. package/src/hosted/ops-cli.js +238 -3
  88. package/src/hosted/pages.js +2 -0
  89. package/src/hosted/passkey-policy.js +75 -0
  90. package/src/hosted/permissions.js +14 -6
  91. package/src/hosted/presence.js +14 -2
  92. package/src/hosted/projects.js +2 -1
  93. package/src/hosted/public.js +4 -4
  94. package/src/hosted/ratelimit.js +6 -0
  95. package/src/hosted/retention.js +18 -2
  96. package/src/hosted/server.js +123 -11
  97. package/src/hosted/shares.js +2 -2
  98. package/src/hosted/step-up-settings.js +68 -0
  99. package/src/hosted/step-up.js +135 -0
  100. package/src/hosted/tailnet-identity.js +24 -0
  101. package/src/hosted/tailnet-routes.js +342 -0
  102. package/src/hosted/tailnet.js +220 -0
  103. package/src/hosted/tailscale.js +75 -9
  104. package/src/hosted/tenancy.js +48 -1
  105. package/src/hosted/token-api.js +2 -2
  106. package/src/hosted/tokens.js +9 -2
  107. package/src/hosted/usage-core.js +624 -0
  108. package/src/hosted/usage-layout.js +724 -0
  109. package/src/hosted/usage-routes.js +375 -0
  110. package/src/hosted/usage-shape.js +256 -0
  111. package/src/hosted/usage.js +641 -0
  112. package/src/remote/agent-connect.js +37 -1
  113. package/src/remote/agent-link.js +2 -0
  114. package/src/remote/login.js +33 -8
  115. package/src/remote/share.js +1 -1
  116. package/src/remote/tailnet-cli.js +547 -0
  117. package/src/server/app.js +15 -0
  118. package/src/server/pairing-routes.js +34 -5
  119. package/src/server/tailscale.js +97 -4
  120. package/src/tailnet-proof.js +766 -0
  121. package/dist/client/assets/index-Cxz1UVcV.css +0 -2
  122. package/dist/client/assets/index-uUZVBYUS.js +0 -37
  123. package/dist/console/assets/LocalAccountsApp-DIdy1KnN.js +0 -1
  124. package/dist/console/assets/LocalConsole-DfcQztF-.js +0 -1
  125. package/dist/console/assets/app-update-dialog-ttl9lF5A.js +0 -1
  126. package/dist/console/assets/console-OqAjD0kV.js +0 -55
  127. package/dist/console/assets/console-kvjrAArQ.css +0 -2
@@ -15,8 +15,15 @@
15
15
  // An occupied port is never taken over, even if its target happens to match.
16
16
 
17
17
  import { execFile } from 'node:child_process'
18
+ import { SECRET_PREFIX, machineFacts, selfFromStatus, serveProblem, serveTarget, tailscaledProblem, whoisAnswer } from '../tailnet-proof.js'
19
+
20
+ export { reachesLocalPort, serveProblem } from '../tailnet-proof.js'
18
21
 
19
22
  export class TailscaleError extends Error {}
23
+ // Tailnet sign-in cannot be switched on with this tailscaled (the message says why).
24
+ export class TailnetSignInRefused extends Error {}
25
+ const NO_SELF =
26
+ 'tailscale status does not say which node this machine is (its id and own tailnet addresses), so a request from this machine itself could not be told apart'
20
27
 
21
28
  // Funnel only publishes these HTTPS ports.
22
29
  export const FUNNEL_PORTS = [443, 8443, 10000]
@@ -83,7 +90,7 @@ export async function tailscaleStatus({ run = runCommand } = {}) {
83
90
  throw new TailscaleError(
84
91
  `HTTPS certificates are off for this tailnet, so ${dnsName} cannot serve https. Turn on "HTTPS Certificates" in the admin console, DNS page.`,
85
92
  )
86
- return { dnsName: dnsName.toLowerCase(), version: status.Version || null }
93
+ return { dnsName: dnsName.toLowerCase(), version: status.Version || null, status }
87
94
  }
88
95
 
89
96
  // What `tailscale serve` already does on `port`: null (free), or the local
@@ -109,17 +116,29 @@ export async function servedOn(port, { run = runCommand, dnsName } = {}) {
109
116
 
110
117
  const localTarget = (port) => `http://127.0.0.1:${port}`
111
118
 
112
- async function claim(kind, httpsPort, localPort, { run, dnsName }) {
119
+ // A target as an error message may show it: never the secret path of a serve entry.
120
+ const shown = (target) => {
121
+ const at = String(target).indexOf(SECRET_PREFIX)
122
+ return at < 0 ? target : `${String(target).slice(0, at + SECRET_PREFIX.length)}...`
123
+ }
124
+
125
+ async function claim(kind, httpsPort, localPort, { run, dnsName, secret = null }) {
113
126
  const current = await servedOn(httpsPort, { run, dnsName })
114
- const target = localTarget(localPort)
127
+ // With tailnet sign-in the entry points at a secret path (src/tailnet-proof.js).
128
+ const target = secret ? serveTarget(localPort, secret) : localTarget(localPort)
115
129
  if (current) {
116
130
  throw new TailscaleError(
117
- `Tailscale already serves port ${httpsPort} on this machine (${current.targets.join(', ') || 'another service'}${current.funnel ? ', public through Funnel' : ''}). ` +
131
+ `Tailscale already serves port ${httpsPort} on this machine (${current.targets.map(shown).join(', ') || 'another service'}${current.funnel ? ', public through Funnel' : ''}). ` +
118
132
  `Pick another port (${kind === 'funnel' ? `--funnel-port, one of ${FUNNEL_PORTS.join(', ')}` : '--tailscale-port 8443'}) or remove it first: tailscale ${kind} --https=${httpsPort} off`,
119
133
  )
120
134
  }
121
135
  const result = await run('tailscale', [kind, '--bg', `--https=${httpsPort}`, target])
122
- if (result.code !== 0) throw explain(result, `tailscale ${kind} --https=${httpsPort}`)
136
+ if (result.code !== 0) {
137
+ const error = explain(result, `tailscale ${kind} --https=${httpsPort}`)
138
+ // tailscale may quote its arguments back: the secret never reaches a log.
139
+ if (secret) error.message = error.message.split(secret).join('...')
140
+ throw error
141
+ }
123
142
  return async () => {
124
143
  const active = await servedOn(httpsPort, { run, dnsName })
125
144
  if (!active) return true
@@ -131,8 +150,19 @@ async function claim(kind, httpsPort, localPort, { run, dnsName }) {
131
150
 
132
151
  // Puts the server on the tailnet. Returns { origin, shareOrigin, stop }:
133
152
  // `stop()` removes what was added.
134
- export async function startTailscale({ localPort, httpsPort = 443, funnel = null, run = runCommand }) {
135
- const { dnsName } = await tailscaleStatus({ run })
153
+ // `secret`: tailnet sign-in; the serve entry then carries it, and `verify`
154
+ // and `whois` are what the identity proof asks while the server runs.
155
+ // `facts`: what the machine says about tailscaled (tests).
156
+ export async function startTailscale({ localPort, httpsPort = 443, funnel = null, run = runCommand, secret = null, facts = machineFacts }) {
157
+ const { dnsName, status } = await tailscaleStatus({ run })
158
+ // This node (its stable id and own tailnet addresses): an identity that comes from it is never honoured.
159
+ let here = selfFromStatus(status)
160
+ if (secret) {
161
+ // Before anything is put on the tailnet.
162
+ const problem = tailscaledProblem(status, await facts())
163
+ if (problem) throw new TailnetSignInRefused(problem)
164
+ if (!here) throw new TailnetSignInRefused(NO_SELF)
165
+ }
136
166
  if (!Number.isInteger(httpsPort) || httpsPort < 1 || httpsPort > 65535) throw new TailscaleError('--tailscale-port: a port number')
137
167
  if (funnel) {
138
168
  if (!FUNNEL_PORTS.includes(funnel.httpsPort))
@@ -147,13 +177,47 @@ export async function startTailscale({ localPort, httpsPort = 443, funnel = null
147
177
  return results.every(Boolean)
148
178
  }
149
179
  try {
150
- undo.push(await claim('serve', httpsPort, localPort, { run, dnsName }))
180
+ undo.push(await claim('serve', httpsPort, localPort, { run, dnsName, secret }))
151
181
  let shareOrigin = null
152
182
  if (funnel) {
153
183
  undo.push(await claim('funnel', funnel.httpsPort, funnel.localPort, { run, dnsName }))
154
184
  shareOrigin = originFor(dnsName, funnel.httpsPort)
155
185
  }
156
- return { origin: originFor(dnsName, httpsPort), shareOrigin, dnsName, stop }
186
+ // For tailnet sign-in: why the identity headers on this server's port
187
+ // cannot be believed right now, or null (see serveProblem).
188
+ const verify = async () => {
189
+ const result = await run('tailscale', ['serve', 'status', '--json'])
190
+ if (result.missing || result.code !== 0) return 'tailscale serve status could not be read'
191
+ let problem
192
+ try {
193
+ problem = serveProblem(JSON.parse(result.stdout || '{}') || {}, {
194
+ dnsName,
195
+ httpsPort,
196
+ localPort,
197
+ ...(secret ? { target: serveTarget(localPort, secret) } : {}),
198
+ })
199
+ } catch {
200
+ return 'tailscale serve status did not answer JSON'
201
+ }
202
+ if (problem || !secret) return problem
203
+ // And tailscaled itself: still one whose connections can be believed.
204
+ const now = await run('tailscale', ['status', '--json'])
205
+ if (now.missing || now.code !== 0) return 'tailscale status could not be read'
206
+ try {
207
+ const status = JSON.parse(now.stdout)
208
+ here = selfFromStatus(status)
209
+ return tailscaledProblem(status, await facts()) || (here ? null : NO_SELF)
210
+ } catch {
211
+ here = null
212
+ return 'tailscale status did not answer JSON'
213
+ }
214
+ }
215
+ // tailscaled's own word on who owns a tailnet address (LocalAPI whois, through the CLI).
216
+ const whois = async (address) => {
217
+ const result = await run('tailscale', ['whois', '--json', address])
218
+ return result.missing || result.code !== 0 ? null : whoisAnswer(result.stdout)
219
+ }
220
+ return { origin: originFor(dnsName, httpsPort), shareOrigin, dnsName, stop, verify, whois, self: () => here }
157
221
  } catch (error) {
158
222
  await stop()
159
223
  throw error
@@ -199,6 +263,8 @@ export function shareOnly(app) {
199
263
  .filter((part) => !/^\s*(__Host-)?sw_(session|ceremony)=/.test(part))
200
264
  .join(';')
201
265
  }
266
+ // Funnel traffic never carries a tailnet identity; whatever claims one is dropped here too.
267
+ for (const name of Object.keys(req.headers)) if (name.startsWith('tailscale-')) delete req.headers[name]
202
268
  return app(req, res)
203
269
  }
204
270
  }
@@ -36,6 +36,8 @@ export const TENANT_TABLES = [
36
36
  'chat_messages',
37
37
  'chat_turns',
38
38
  'chat_permissions',
39
+ 'saved_views',
40
+ 'usage_layouts',
39
41
  ]
40
42
  export { ROLES, roleAtLeast } from './permissions.js'
41
43
 
@@ -212,6 +214,17 @@ export function findInviteByHash(db, tokenHash) {
212
214
  )
213
215
  }
214
216
 
217
+ // The invites made for one tailnet login (src/hosted/tailnet.js), in any
218
+ // workspace, with what inviteUsable needs. The caller keeps the usable ones.
219
+ export function findInvitesForTailnetLogin(db, login) {
220
+ return prepare(
221
+ db,
222
+ `SELECT i.*, w.name AS workspace_name, m.role AS creator_role FROM invites i JOIN workspaces w ON w.id = i.workspace_id
223
+ LEFT JOIN memberships m ON m.workspace_id = i.workspace_id AND m.user_id = i.created_by
224
+ WHERE i.tailnet_login = :login AND i.used_at IS NULL AND i.revoked_at IS NULL ORDER BY i.created_at`,
225
+ ).all({ login })
226
+ }
227
+
215
228
  // Whether an invite row (from findInviteByHash) still works: unused, not
216
229
  // revoked, not expired, and its creator can still invite to that role (an
217
230
  // admin up to admin, an owner for owners). A removed or demoted admin's
@@ -243,7 +256,7 @@ export function roleIn(db, userId, workspaceId) {
243
256
  export function allWorkspaces(db) {
244
257
  return prepare(
245
258
  db,
246
- 'SELECT id, name, created_at, created_by, share_links, suspended_at, suspended_reason, retention_versions FROM workspaces ORDER BY created_at, id',
259
+ 'SELECT id, name, created_at, created_by, share_links, suspended_at, suspended_reason, retention_versions, retention_usage_days FROM workspaces ORDER BY created_at, id',
247
260
  ).all()
248
261
  }
249
262
 
@@ -301,6 +314,40 @@ export function seenDevice(db, userId, device) {
301
314
  )
302
315
  }
303
316
 
317
+ // The account events of a workspace's members (sign-ins, passkeys, sessions:
318
+ // rows with no workspace), for the workspace's Activity page: only of people
319
+ // who are members now, only since each joined, and only the actions listed
320
+ // (src/hosted/usage-shape.js ACCOUNT_ACTIONS). Newest first, `before` an
321
+ // entry id. `userId`: one member (a person reading their own activity).
322
+ export function memberAccountEvents(
323
+ db,
324
+ workspaceId,
325
+ { userId = null, actions, from = null, to = null, q = null, before = Number.MAX_SAFE_INTEGER, limit = 50 },
326
+ ) {
327
+ if (!ID_PATTERNS.workspace.test(String(workspaceId || ''))) return []
328
+ return prepare(
329
+ db,
330
+ `SELECT a.id, a.action, a.target, a.ip, a.detail, a.at, a.user_id, u.handle, u.display_name
331
+ FROM memberships m JOIN audit_log a ON a.user_id = m.user_id AND a.workspace_id IS NULL JOIN users u ON u.id = a.user_id
332
+ WHERE m.workspace_id = :ws AND a.at >= m.created_at AND a.id < :before
333
+ AND a.action IN (SELECT value FROM json_each(:actions))
334
+ AND (:user IS NULL OR a.user_id = :user) AND (:from IS NULL OR a.at >= :from) AND (:to IS NULL OR a.at < :to)
335
+ AND (:q IS NULL OR instr(lower(replace(a.action, '_', ' ') || ' ' || coalesce(a.ip, '') || ' ' || coalesce(a.detail, '') || ' ' ||
336
+ u.display_name || ' ' || u.handle), :q) > 0)
337
+ ORDER BY a.id DESC LIMIT :limit`,
338
+ ).all({ ws: workspaceId, actions: JSON.stringify(actions), user: userId, from, to, q, before, limit })
339
+ }
340
+
341
+ // Account deletion: the person's saved views, in every workspace, go with them.
342
+ export function deleteSavedViewsOf(db, userId) {
343
+ // With the layouts those views carry, and the person's own dashboard layouts.
344
+ prepare(db, "DELETE FROM usage_layouts WHERE kind = 'view' AND subject IN (SELECT id FROM saved_views WHERE user_id = :user)").run({
345
+ user: userId,
346
+ })
347
+ prepare(db, "DELETE FROM usage_layouts WHERE kind = 'person' AND subject = :user").run({ user: userId })
348
+ prepare(db, 'DELETE FROM saved_views WHERE user_id = :user').run({ user: userId })
349
+ }
350
+
304
351
  // Account deletion: the person's own account-level log goes with them.
305
352
  export function deleteAccountEvents(db, userId) {
306
353
  prepare(db, 'DELETE FROM audit_log WHERE workspace_id IS NULL AND user_id = :user').run({ user: userId })
@@ -53,7 +53,7 @@ export function mountTokenApi({
53
53
  policyFor,
54
54
  boardContext,
55
55
  dispatchView,
56
- needFresh,
56
+ stepUp,
57
57
  approvalApi,
58
58
  // Connected agents (src/hosted/agent-link.js): the chat store, the live
59
59
  // turns, the open links and what ends a turn.
@@ -649,7 +649,7 @@ export function mountTokenApi({
649
649
  policyFor,
650
650
  agentsFor,
651
651
  boardContext,
652
- needFresh,
652
+ stepUp,
653
653
  auditOf,
654
654
  now,
655
655
  })
@@ -19,7 +19,7 @@ export function createApiTokens({ iso, auditOf, agentsFor = null }) {
19
19
  // ("login" for `shapewall login`) in the audit log. A token that may take
20
20
  // work (the claim scope) is an agent from the start (src/hosted/agents.js),
21
21
  // for the person who made it only; `machine` is the label a login sent.
22
- function createApiToken(req, body, { via = null, machine = null, agent = null } = {}) {
22
+ function createApiToken(req, body, { via = null, machine = null, agent = null, approvedBy = null } = {}) {
23
23
  // A name too long is refused, not cut (as on a rename): it is what people will see.
24
24
  const name = cleanName(body.name, 61)
25
25
  if (!name || name.length > 60) throw new HttpError(400, 'invalid_name', 'Token name: 1 to 60 characters.')
@@ -59,7 +59,14 @@ export function createApiTokens({ iso, auditOf, agentsFor = null }) {
59
59
  expires: days ? iso(days * DAY) : null,
60
60
  },
61
61
  )
62
- auditOf(req, 'token_created', id, { project: req.project.id, scopes, ...(days ? { days } : {}), ...(via ? { via } : {}) })
62
+ auditOf(req, 'token_created', id, {
63
+ project: req.project.id,
64
+ scopes,
65
+ ...(days ? { days } : {}),
66
+ ...(via ? { via } : {}),
67
+ // A login approved from the command line by tailnet identity says so, with the machine.
68
+ ...(approvedBy ? { approvedBy, machine } : {}),
69
+ })
63
70
  let agentId = null
64
71
  if (scopes.includes('claim') && agentsFor)
65
72
  agentId = agentsFor(req.t).create(