shapewall 0.6.0 → 0.7.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/CHANGELOG.md +267 -0
- package/README.md +39 -2
- package/THIRD_PARTY.md +15 -0
- package/dist/agent/package-lock.json +594 -2
- package/dist/client/assets/{BoardChat-DdwBcb2N.js → BoardChat-Bv4UDOjO.js} +1 -1
- package/dist/client/assets/{BuzzDialog-DpUcnU6S.js → BuzzDialog-DwEAN6va.js} +1 -1
- package/dist/client/assets/{ChecksPanel-CngYV4yz.js → ChecksPanel-C6r_Tc9g.js} +1 -1
- package/dist/client/assets/{History-CD0saQA5.js → History-ajFROfWC.js} +1 -1
- package/dist/client/assets/{LocalSettings-MZy2baig.js → LocalSettings-BSbmmpbN.js} +1 -1
- package/dist/client/assets/{Management-CSvZ-SHO.js → Management-mo8uv2qG.js} +1 -1
- package/dist/client/assets/{QuickConnect-foLh2QUm.js → QuickConnect-DlaijESK.js} +1 -1
- package/dist/client/assets/{ShareDialog-DPWDftoL.js → ShareDialog-CdLdd6WQ.js} +1 -1
- package/dist/client/assets/{app-update-dialog-CtiXpTRD.js → app-update-dialog-BHVNR5Cp.js} +1 -1
- package/dist/client/assets/{circle-x-CteRBtXC.js → circle-x-D5MkDLJk.js} +1 -1
- package/dist/client/assets/index-B4AoX3ZW.css +2 -0
- package/dist/client/assets/index-CQeHY7en.js +37 -0
- package/dist/client/assets/{play-BjRNIGSf.js → play--xrZ7VCR.js} +1 -1
- package/dist/client/assets/{refresh-cw-r_tZiFfB.js → refresh-cw-B-npxKae.js} +1 -1
- package/dist/client/assets/{ui-zQpn-PdL.js → ui-2lMx-4bc.js} +2 -2
- package/dist/client/build-info.json +1 -1
- package/dist/client/index.html +3 -3
- package/dist/client/sw.js +2 -2
- package/dist/console/assets/LocalAccountsApp-C1sCag6a.js +1 -0
- package/dist/console/assets/LocalConsole-LXQmzRFT.js +2 -0
- package/dist/console/assets/LocalUsage-Br3Ddp7_.js +1 -0
- package/dist/console/assets/app-update-dialog-CVniDJKA.js +1 -0
- package/dist/console/assets/app-version-CTHwlY6g.js +1 -0
- package/dist/console/assets/console-CMNNLtFw.js +11 -0
- package/dist/console/assets/console-sMMn_Rwc.css +2 -0
- package/dist/console/assets/local-agents-DwYJ9cPb.js +6 -0
- package/dist/console/assets/minus-887msXez.js +1 -0
- package/dist/console/assets/tailnet--wXsG3uh.js +2 -0
- package/dist/console/assets/theme-CPfJOmcz.js +1 -0
- package/dist/console/assets/ui-DnyJhoQU.js +41 -0
- package/dist/console/assets/usage-C5CJHejQ.js +5 -0
- package/dist/console/assets/usage-CIPWnHaS.css +1 -0
- package/dist/console/assets/usage-DjmUlnXL.js +56 -0
- package/dist/console/build-info.json +1 -1
- package/dist/console/console.html +8 -2
- package/docs/agent-hardening.md +31 -17
- package/docs/agents.md +35 -0
- package/docs/architecture.md +10 -4
- package/docs/deployment.md +39 -17
- package/docs/design-system.md +56 -7
- package/docs/hosted.md +1004 -43
- package/docs/images/board-overview.png +0 -0
- package/docs/images/journeys.png +0 -0
- package/docs/images/live-comment.png +0 -0
- package/docs/images/phone-comment.png +0 -0
- package/docs/images/phone-overview.png +0 -0
- package/docs/images/variant.png +0 -0
- package/docs/where-to-run.md +82 -1
- package/package.json +6 -1
- package/src/agent/backends/acp.js +224 -26
- package/src/agent/routes.js +21 -0
- package/src/agent/usage-log.js +251 -0
- package/src/cli/args.js +24 -0
- package/src/cli/help.js +37 -2
- package/src/cli/init.js +2 -1
- package/src/cli/serve.js +20 -5
- package/src/cli.js +8 -0
- package/src/hosted/access-cli.js +99 -1
- package/src/hosted/activity-core.js +232 -0
- package/src/hosted/activity.js +375 -0
- package/src/hosted/admin.js +80 -13
- package/src/hosted/agent-approvals.js +2 -2
- package/src/hosted/agent-routes.js +3 -3
- package/src/hosted/agents.js +11 -4
- package/src/hosted/app.js +89 -7
- package/src/hosted/auth-routes.js +156 -15
- package/src/hosted/auth.js +123 -20
- package/src/hosted/board-routes.js +3 -3
- package/src/hosted/chat-frames.js +5 -15
- package/src/hosted/chat-permissions.js +12 -0
- package/src/hosted/chat-routes.js +8 -8
- package/src/hosted/chat-store.js +20 -3
- package/src/hosted/comment-files.js +5 -2
- package/src/hosted/console-routes.js +111 -34
- package/src/hosted/db.js +130 -0
- package/src/hosted/device-routes.js +25 -3
- package/src/hosted/device.js +23 -4
- package/src/hosted/guards.js +337 -27
- package/src/hosted/http.js +6 -3
- package/src/hosted/membership.js +13 -2
- package/src/hosted/operator-access.js +418 -0
- package/src/hosted/operator.js +106 -2
- package/src/hosted/ops-cli.js +238 -3
- package/src/hosted/pages.js +2 -0
- package/src/hosted/passkey-policy.js +75 -0
- package/src/hosted/permissions.js +14 -6
- package/src/hosted/presence.js +14 -2
- package/src/hosted/projects.js +2 -1
- package/src/hosted/public.js +4 -4
- package/src/hosted/ratelimit.js +6 -0
- package/src/hosted/retention.js +18 -2
- package/src/hosted/server.js +123 -11
- package/src/hosted/shares.js +2 -2
- package/src/hosted/step-up-settings.js +68 -0
- package/src/hosted/step-up.js +135 -0
- package/src/hosted/tailnet-identity.js +24 -0
- package/src/hosted/tailnet-routes.js +342 -0
- package/src/hosted/tailnet.js +220 -0
- package/src/hosted/tailscale.js +75 -9
- package/src/hosted/tenancy.js +48 -1
- package/src/hosted/token-api.js +2 -2
- package/src/hosted/tokens.js +9 -2
- package/src/hosted/usage-core.js +624 -0
- package/src/hosted/usage-layout.js +724 -0
- package/src/hosted/usage-routes.js +375 -0
- package/src/hosted/usage-shape.js +256 -0
- package/src/hosted/usage.js +641 -0
- package/src/remote/agent-connect.js +37 -1
- package/src/remote/agent-link.js +2 -0
- package/src/remote/login.js +33 -8
- package/src/remote/share.js +1 -1
- package/src/remote/tailnet-cli.js +547 -0
- package/src/server/app.js +15 -0
- package/src/server/pairing-routes.js +34 -5
- package/src/server/tailscale.js +97 -4
- package/src/tailnet-proof.js +766 -0
- package/dist/client/assets/index-Cxz1UVcV.css +0 -2
- package/dist/client/assets/index-uUZVBYUS.js +0 -37
- package/dist/console/assets/LocalAccountsApp-DIdy1KnN.js +0 -1
- package/dist/console/assets/LocalConsole-DfcQztF-.js +0 -1
- package/dist/console/assets/app-update-dialog-ttl9lF5A.js +0 -1
- package/dist/console/assets/console-OqAjD0kV.js +0 -55
- package/dist/console/assets/console-kvjrAArQ.css +0 -2
package/src/hosted/admin.js
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
// every query goes through the request's tenant handle (req.t).
|
|
6
6
|
//
|
|
7
7
|
// Who may do what: src/hosted/permissions.js (NEEDS), shared with the
|
|
8
|
-
// console and the public demo. Deleting the workspace
|
|
9
|
-
// passkey check and the workspace's name typed back
|
|
8
|
+
// console and the public demo. Deleting the workspace always needs a fresh
|
|
9
|
+
// passkey check and the workspace's name typed back; what else asks for the
|
|
10
|
+
// passkey again is the workspace's own choice (src/hosted/step-up.js).
|
|
10
11
|
|
|
11
12
|
import fs from 'node:fs'
|
|
12
13
|
import path from 'node:path'
|
|
@@ -16,9 +17,11 @@ import { ID_RE } from '../config.js'
|
|
|
16
17
|
import { createCommentStore } from './comments.js'
|
|
17
18
|
import { NEEDS, ROLE_ACCESS, tokenCreatorOk } from './permissions.js'
|
|
18
19
|
import { projectDir } from './projects.js'
|
|
20
|
+
import { stepUpSettings } from './step-up-settings.js'
|
|
19
21
|
import { auditAccount } from './tenancy.js'
|
|
20
22
|
import { ZIP_MAX_BYTES, createZip } from './zip.js'
|
|
21
23
|
import { createChatStore } from './chat-store.js'
|
|
24
|
+
import { createUsage } from './usage.js'
|
|
22
25
|
|
|
23
26
|
const AUDIT_PAGE = 50
|
|
24
27
|
const AUDIT_PAGE_MAX = 200
|
|
@@ -30,7 +33,7 @@ const AUDIT_CSV_MAX = 10_000
|
|
|
30
33
|
const AUDIT_EXPORT_MAX = 100_000
|
|
31
34
|
const AUDIT_EXPORT_PAGE = 1000
|
|
32
35
|
|
|
33
|
-
const AUDIT_SELECT = `SELECT a.id, a.action, a.target, a.ip, a.detail, a.at, a.user_id, a.token_id, a.share_id,
|
|
36
|
+
export const AUDIT_SELECT = `SELECT a.id, a.action, a.target, a.ip, a.detail, a.at, a.user_id, a.token_id, a.share_id,
|
|
34
37
|
u.handle, u.display_name, k.name AS token_name, s.name AS share_name,
|
|
35
38
|
tu.handle AS target_handle, tu.display_name AS target_user, tp.name AS target_project,
|
|
36
39
|
tk.name AS target_token, ts.name AS target_share
|
|
@@ -45,7 +48,7 @@ const AUDIT_SELECT = `SELECT a.id, a.action, a.target, a.ip, a.detail, a.at, a.u
|
|
|
45
48
|
|
|
46
49
|
// What the search looks through: one string per row (no OR, which the tenant
|
|
47
50
|
// guard refuses).
|
|
48
|
-
const AUDIT_HAYSTACK = [
|
|
51
|
+
export const AUDIT_HAYSTACK = [
|
|
49
52
|
"replace(a.action, '_', ' ')",
|
|
50
53
|
'a.target',
|
|
51
54
|
'a.ip',
|
|
@@ -63,7 +66,7 @@ const AUDIT_HAYSTACK = [
|
|
|
63
66
|
.map((column) => `coalesce(${column}, '')`)
|
|
64
67
|
.join(" || ' ' || ")
|
|
65
68
|
|
|
66
|
-
function auditEntry(row) {
|
|
69
|
+
export function auditEntry(row) {
|
|
67
70
|
const detail = JSON.parse(row.detail || '{}')
|
|
68
71
|
return {
|
|
69
72
|
id: row.id,
|
|
@@ -325,6 +328,21 @@ export async function writeWorkspaceExport(t, exported, { write, now, iso, expor
|
|
|
325
328
|
}
|
|
326
329
|
await audit.write(count ? '\n]\n' : ']\n')
|
|
327
330
|
await audit.end()
|
|
331
|
+
// The usage records (src/hosted/usage.js): one row per agent turn, numbers
|
|
332
|
+
// and ids only, newest first, all of them.
|
|
333
|
+
const usage = zip.stream(`${root}usage.json`)
|
|
334
|
+
await usage.write('[')
|
|
335
|
+
let turns = 0
|
|
336
|
+
const end = Date.now() + 86_400_000
|
|
337
|
+
const store = createUsage(t)
|
|
338
|
+
// Every record, a page at a time: an export is the whole workspace.
|
|
339
|
+
for (const page of store.pages({ fromMs: 0, toMs: end }, { all: true, userId: null }, { max: Infinity })) {
|
|
340
|
+
let text = ''
|
|
341
|
+
for (const row of page) text += `${turns++ ? ',' : ''}\n ${JSON.stringify(row)}`
|
|
342
|
+
await usage.write(text)
|
|
343
|
+
}
|
|
344
|
+
await usage.write(turns ? '\n]\n' : ']\n')
|
|
345
|
+
await usage.end()
|
|
328
346
|
for (const { project, row, files, images = [] } of plan) {
|
|
329
347
|
const base = `${root}projects/${project.slug}/boards/${row.board_id}/`
|
|
330
348
|
const comments = createCommentStore(t, project.id, row.board_id).list()
|
|
@@ -387,7 +405,23 @@ function isoOrNull(value) {
|
|
|
387
405
|
}
|
|
388
406
|
|
|
389
407
|
export function mountAdmin(router, deps) {
|
|
390
|
-
const {
|
|
408
|
+
const {
|
|
409
|
+
db,
|
|
410
|
+
dataDir,
|
|
411
|
+
iso,
|
|
412
|
+
now,
|
|
413
|
+
handle,
|
|
414
|
+
inWorkspace,
|
|
415
|
+
needFresh,
|
|
416
|
+
stepUp,
|
|
417
|
+
stepUpOrThrow,
|
|
418
|
+
coreFreshOrThrow,
|
|
419
|
+
auditOf,
|
|
420
|
+
HttpError,
|
|
421
|
+
listTokens,
|
|
422
|
+
clientIp,
|
|
423
|
+
limit,
|
|
424
|
+
} = deps
|
|
391
425
|
// Workspaces with an export being written: one at a time each.
|
|
392
426
|
const exporting = new Set()
|
|
393
427
|
|
|
@@ -397,7 +431,7 @@ export function mountAdmin(router, deps) {
|
|
|
397
431
|
inWorkspace(NEEDS.invites),
|
|
398
432
|
handle(async (req, res) => {
|
|
399
433
|
const rows = req.t.all(
|
|
400
|
-
`SELECT i.id, i.role, i.created_at, i.expires_at, i.used_at, i.revoked_at, i.email, i.emailed_at, i.note,
|
|
434
|
+
`SELECT i.id, i.role, i.created_at, i.expires_at, i.used_at, i.revoked_at, i.email, i.emailed_at, i.note, i.tailnet_login,
|
|
401
435
|
c.handle AS creator_handle, c.display_name AS creator_name, u.handle AS used_handle, u.display_name AS used_name
|
|
402
436
|
FROM invites i LEFT JOIN users c ON c.id = i.created_by LEFT JOIN users u ON u.id = i.used_by
|
|
403
437
|
WHERE i.workspace_id = :ws ORDER BY i.created_at DESC LIMIT :limit`,
|
|
@@ -415,6 +449,7 @@ export function mountAdmin(router, deps) {
|
|
|
415
449
|
email: row.email || null,
|
|
416
450
|
emailedAt: row.emailed_at || null,
|
|
417
451
|
note: row.note || null,
|
|
452
|
+
tailnetLogin: row.tailnet_login || null,
|
|
418
453
|
createdBy: row.creator_handle ? { handle: row.creator_handle, displayName: row.creator_name } : null,
|
|
419
454
|
usedBy: row.used_handle ? { handle: row.used_handle, displayName: row.used_name } : null,
|
|
420
455
|
}))
|
|
@@ -555,6 +590,7 @@ export function mountAdmin(router, deps) {
|
|
|
555
590
|
inWorkspace(NEEDS.audit),
|
|
556
591
|
handle(async (req, res) => {
|
|
557
592
|
const rows = auditRows(req, { limit: AUDIT_CSV_MAX, before: Number.MAX_SAFE_INTEGER })
|
|
593
|
+
auditOf(req, 'audit_exported', null, { rows: rows.length, scope: 'workspace', view: 'audit' })
|
|
558
594
|
const lines = [['time', 'actor_type', 'actor', 'actor_handle', 'action', 'target', 'ip', 'detail']]
|
|
559
595
|
for (const row of rows) {
|
|
560
596
|
const entry = auditEntry(row)
|
|
@@ -600,15 +636,15 @@ export function mountAdmin(router, deps) {
|
|
|
600
636
|
// ---- Export: a zip of the workspace before it is deleted (admins) ----
|
|
601
637
|
// workspace.json (members, projects, tokens and share links without their
|
|
602
638
|
// secrets), audit.json, and per project and board the board definition,
|
|
603
|
-
// its comments and every pushed file.
|
|
604
|
-
//
|
|
639
|
+
// its comments and every pushed file. Everything in the workspace in one
|
|
640
|
+
// download: the passkey again when the workspace asks ("Exports and deletes").
|
|
605
641
|
// One export at a time per workspace (409 while one runs), a few an hour
|
|
606
642
|
// per person (LIMITS.export), and the audit log read 1000 rows at a time.
|
|
607
643
|
router.post(
|
|
608
644
|
'/workspaces/:ws/export',
|
|
609
645
|
inWorkspace(NEEDS.export),
|
|
610
646
|
limit('export', (req) => req.user.id),
|
|
611
|
-
|
|
647
|
+
stepUp('data'),
|
|
612
648
|
handle(async (req, res) => {
|
|
613
649
|
const t = req.t
|
|
614
650
|
if (exporting.has(t.workspaceId))
|
|
@@ -661,7 +697,7 @@ export function mountAdmin(router, deps) {
|
|
|
661
697
|
const { shareLinks } = req.body || {}
|
|
662
698
|
if (typeof shareLinks !== 'boolean') throw new HttpError(400, 'invalid_settings', 'shareLinks: true or false.')
|
|
663
699
|
// Letting people outside the workspace in is a sensitive change.
|
|
664
|
-
if (shareLinks)
|
|
700
|
+
if (shareLinks) stepUpOrThrow(req, 'tokens')
|
|
665
701
|
const current = req.t.get('SELECT share_links FROM workspaces WHERE workspace_id = :ws')
|
|
666
702
|
if (Boolean(current.share_links) !== shareLinks) {
|
|
667
703
|
req.t.run('UPDATE workspaces SET share_links = :on WHERE workspace_id = :ws', { on: shareLinks ? 1 : 0 })
|
|
@@ -671,6 +707,36 @@ export function mountAdmin(router, deps) {
|
|
|
671
707
|
}),
|
|
672
708
|
)
|
|
673
709
|
|
|
710
|
+
// When this workspace asks for the passkey again (src/hosted/step-up.js):
|
|
711
|
+
// one setting per request, { group, on } | { windowMinutes } | { adminIdle } | { cliApproval }.
|
|
712
|
+
// Owners only; asking for less needs a fresh passkey check itself.
|
|
713
|
+
router.patch(
|
|
714
|
+
'/workspaces/:ws/step-up',
|
|
715
|
+
inWorkspace(NEEDS.settings),
|
|
716
|
+
handle(async (req, res) => {
|
|
717
|
+
const body = req.body || {}
|
|
718
|
+
const actor = {
|
|
719
|
+
role: req.role,
|
|
720
|
+
fresh: () => coreFreshOrThrow(req),
|
|
721
|
+
audit: (action, target, detail) => auditOf(req, action, target, detail),
|
|
722
|
+
}
|
|
723
|
+
const settings = stepUpSettings(req.t)
|
|
724
|
+
const named = ['group', 'windowMinutes', 'adminIdle', 'cliApproval'].filter((key) => Object.hasOwn(body, key))
|
|
725
|
+
if (named.length !== 1)
|
|
726
|
+
throw new HttpError(400, 'invalid_settings', 'One setting at a time: group and on, windowMinutes, adminIdle or cliApproval.')
|
|
727
|
+
const stepUpNow = transaction(db, () =>
|
|
728
|
+
named[0] === 'group'
|
|
729
|
+
? settings.setGroup(actor, body.group, body.on)
|
|
730
|
+
: named[0] === 'windowMinutes'
|
|
731
|
+
? settings.setWindow(actor, body.windowMinutes)
|
|
732
|
+
: named[0] === 'adminIdle'
|
|
733
|
+
? settings.setAdminIdle(actor, body.adminIdle)
|
|
734
|
+
: settings.setCliApproval(actor, body.cliApproval),
|
|
735
|
+
)
|
|
736
|
+
res.json({ settings: { stepUp: stepUpNow } })
|
|
737
|
+
}),
|
|
738
|
+
)
|
|
739
|
+
|
|
674
740
|
// ---- Deleting a workspace (owner) ----
|
|
675
741
|
// Every row of the workspace goes, then its files. The account-level log
|
|
676
742
|
// keeps one line that it happened.
|
|
@@ -699,7 +765,7 @@ export function mountAdmin(router, deps) {
|
|
|
699
765
|
)
|
|
700
766
|
}
|
|
701
767
|
|
|
702
|
-
function actorOf(row, detail) {
|
|
768
|
+
export function actorOf(row, detail) {
|
|
703
769
|
if (row.user_id) return { type: 'user', id: row.user_id, label: row.display_name || 'Former member', handle: row.handle || null }
|
|
704
770
|
if (row.token_id) return { type: 'token', id: row.token_id, label: row.token_name || 'Deleted token' }
|
|
705
771
|
if (row.share_id) {
|
|
@@ -717,5 +783,6 @@ function actorOf(row, detail) {
|
|
|
717
783
|
link: row.share_name || 'Share link',
|
|
718
784
|
}
|
|
719
785
|
}
|
|
720
|
-
|
|
786
|
+
// Done on the server's machine with `shapewall hosted admin` (src/hosted/operator-access.js).
|
|
787
|
+
return { type: 'system', id: null, label: detail?.by === 'operator' ? 'Server operator' : 'System' }
|
|
721
788
|
}
|
|
@@ -16,7 +16,7 @@ export function mountHostedApprovals({
|
|
|
16
16
|
policyFor,
|
|
17
17
|
agentsFor = null,
|
|
18
18
|
boardContext,
|
|
19
|
-
|
|
19
|
+
stepUp,
|
|
20
20
|
auditOf,
|
|
21
21
|
now,
|
|
22
22
|
}) {
|
|
@@ -153,7 +153,7 @@ export function mountHostedApprovals({
|
|
|
153
153
|
)
|
|
154
154
|
boardApi.post(
|
|
155
155
|
'/boards/:bid/approvals/:aid',
|
|
156
|
-
|
|
156
|
+
stepUp('cards'),
|
|
157
157
|
handle((req, res) => {
|
|
158
158
|
if (!roleAtLeast(req.role, 'admin') || !policyFor(req.t).trusted(agentPolicy(req.t, req.project.id, req.params.bid), req.user.id))
|
|
159
159
|
throw error(403, 'forbidden', 'Only trusted admins approve shell commands.')
|
|
@@ -15,7 +15,7 @@ import { HttpError } from './http.js'
|
|
|
15
15
|
import { AGENT_AUDIENCES, APPROVAL_ROLES, APPROVAL_RULES, NEEDS, roleAtLeast } from './permissions.js'
|
|
16
16
|
import { AGENT_KINDS } from './agents.js'
|
|
17
17
|
|
|
18
|
-
export function mountAgentRoutes(consoleApi, { db, publicOrigin, handle, inWorkspace, inProject,
|
|
18
|
+
export function mountAgentRoutes(consoleApi, { db, publicOrigin, handle, inWorkspace, inProject, stepUp, auditOf, agentsFor }) {
|
|
19
19
|
const actorOf = (req) => ({
|
|
20
20
|
userId: req.user.id,
|
|
21
21
|
role: req.role,
|
|
@@ -85,7 +85,7 @@ export function mountAgentRoutes(consoleApi, { db, publicOrigin, handle, inWorks
|
|
|
85
85
|
consoleApi.put(
|
|
86
86
|
'/workspaces/:ws/projects/:pid/agents/:aid/audience',
|
|
87
87
|
inWorkspace(NEEDS.tokens),
|
|
88
|
-
|
|
88
|
+
stepUp('agents'),
|
|
89
89
|
inProject,
|
|
90
90
|
handle((req, res) => {
|
|
91
91
|
const { audience, users } = req.body || {}
|
|
@@ -98,7 +98,7 @@ export function mountAgentRoutes(consoleApi, { db, publicOrigin, handle, inWorks
|
|
|
98
98
|
consoleApi.put(
|
|
99
99
|
'/workspaces/:ws/projects/:pid/agents/:aid/approval',
|
|
100
100
|
inWorkspace(NEEDS.tokens),
|
|
101
|
-
|
|
101
|
+
stepUp('agents'),
|
|
102
102
|
inProject,
|
|
103
103
|
handle((req, res) => {
|
|
104
104
|
const { rule, changeRole, answerRole } = req.body || {}
|
package/src/hosted/agents.js
CHANGED
|
@@ -39,6 +39,7 @@ import { logoForAgent } from '../agent/agent-logos.js'
|
|
|
39
39
|
import { cleanAgentName, isAgentTint, isBuiltInIcon } from '../agent/identity.js'
|
|
40
40
|
import { agentPolicy, trustedMember } from './agent-policy.js'
|
|
41
41
|
import { newId } from './crypto.js'
|
|
42
|
+
import { RUN_DURATION } from './usage-shape.js'
|
|
42
43
|
import { HttpError } from './http.js'
|
|
43
44
|
import {
|
|
44
45
|
AGENT_AUDIENCES,
|
|
@@ -695,7 +696,7 @@ export function createAgentStore(t, { now = () => new Date(), presence = null, h
|
|
|
695
696
|
})
|
|
696
697
|
for (const item of mine) {
|
|
697
698
|
t.run(
|
|
698
|
-
|
|
699
|
+
`UPDATE agent_runs SET ended_at = :at, outcome = :reason, ${RUN_DURATION} WHERE workspace_id = :ws AND project_id = :project AND agent_id = :agent AND board_id = :board AND comment_number = :number AND ended_at IS NULL`,
|
|
699
700
|
{ project: projectId, agent: agent.id, board: item.board, number: item.number, at, reason },
|
|
700
701
|
)
|
|
701
702
|
t.run(`UPDATE comments SET agent_status = NULL, agent_status_at = NULL, agent_id = NULL WHERE ${where}`, {
|
|
@@ -772,8 +773,10 @@ export function createAgentStore(t, { now = () => new Date(), presence = null, h
|
|
|
772
773
|
// NULL: a watcher reports none of them.
|
|
773
774
|
function startRun({ projectId, boardId, number, agentId, claimId, askedBy }) {
|
|
774
775
|
t.run(
|
|
775
|
-
`INSERT INTO agent_runs (workspace_id, project_id, id, kind, agent_id, claim_id, board_id, comment_number, asked_by, started_at
|
|
776
|
-
|
|
776
|
+
`INSERT INTO agent_runs (workspace_id, project_id, id, kind, agent_id, claim_id, board_id, comment_number, asked_by, started_at,
|
|
777
|
+
agent_owner)
|
|
778
|
+
VALUES (:ws, :project, :id, 'fix', :agent, :claim, :board, :number, :asked, :at,
|
|
779
|
+
(SELECT a.created_by FROM agents a WHERE a.id = :agent))`,
|
|
777
780
|
{
|
|
778
781
|
project: projectId,
|
|
779
782
|
id: newId('run'),
|
|
@@ -819,7 +822,11 @@ export function createAgentStore(t, { now = () => new Date(), presence = null, h
|
|
|
819
822
|
: 'released'
|
|
820
823
|
const at =
|
|
821
824
|
comment?.status === 'resolved' && comment.resolved_at && comment.resolved_at < run.ended_at ? comment.resolved_at : run.ended_at
|
|
822
|
-
t.run(
|
|
825
|
+
t.run(`UPDATE agent_runs SET ended_at = :at, outcome = :outcome, ${RUN_DURATION} WHERE workspace_id = :ws AND id = :id`, {
|
|
826
|
+
id: run.id,
|
|
827
|
+
at,
|
|
828
|
+
outcome,
|
|
829
|
+
})
|
|
823
830
|
}
|
|
824
831
|
return ended.length
|
|
825
832
|
}
|
package/src/hosted/app.js
CHANGED
|
@@ -63,10 +63,14 @@ import { mountTokenApi } from './token-api.js'
|
|
|
63
63
|
import { createAgentPresence } from './agent-presence.js'
|
|
64
64
|
import { COMMENT_ROUTING, createAgentStore } from './agents.js'
|
|
65
65
|
import { mountAgentRoutes } from './agent-routes.js'
|
|
66
|
+
import { mountUsageRoutes } from './usage-routes.js'
|
|
66
67
|
import { createAgentLinks, createChatService } from './agent-link.js'
|
|
67
68
|
import { createChatStore } from './chat-store.js'
|
|
68
69
|
import { createTurnHub } from './turn-hub.js'
|
|
69
70
|
import { mountPages } from './pages.js'
|
|
71
|
+
import { createPasskeyPolicy } from './passkey-policy.js'
|
|
72
|
+
import { createTailnetAccounts } from './tailnet.js'
|
|
73
|
+
import { mountTailnetAdmin } from './tailnet-routes.js'
|
|
70
74
|
|
|
71
75
|
export { changeEventType, publicBoardView, TOKEN_SCOPES, INVITE_DAYS }
|
|
72
76
|
|
|
@@ -125,7 +129,23 @@ export function createHostedApp({
|
|
|
125
129
|
turnstile = null,
|
|
126
130
|
// Where "Report this board" on a public project goes (an email address).
|
|
127
131
|
reportEmail = null,
|
|
132
|
+
// Whether a workspace's owners see their members' account events (sign-ins,
|
|
133
|
+
// passkeys, sessions) in Activity. Off: those are each person's own. For a
|
|
134
|
+
// server with one team; set by the operator (--owners-see-sign-ins).
|
|
135
|
+
ownersSeeSignIns = false,
|
|
136
|
+
// Tailnet sign-in: { identityOf(req) } says who a request is from, by the
|
|
137
|
+
// identity headers of Tailscale's serve proxy and only when the request
|
|
138
|
+
// provably came through it (src/hosted/tailnet-identity.js). null: off,
|
|
139
|
+
// and the headers are never read.
|
|
140
|
+
tailnet = null,
|
|
141
|
+
// With tailnet sign-in: also allow passkeys (--tailnet-passkeys). Off by
|
|
142
|
+
// default there; the operator's switch in the database wins
|
|
143
|
+
// (src/hosted/passkey-policy.js). Without tailnet sign-in passkeys are
|
|
144
|
+
// always the sign-in.
|
|
145
|
+
tailnetPasskeys = false,
|
|
128
146
|
}) {
|
|
147
|
+
if (guestOnly) tailnet = null
|
|
148
|
+
const passkeys = createPasskeyPolicy({ db, tailnet, flag: tailnetPasskeys })
|
|
129
149
|
const base = new URL(origin)
|
|
130
150
|
if (!['http:', 'https:'].includes(base.protocol) || base.pathname !== '/' || base.search)
|
|
131
151
|
throw new Error('origin: an http(s) origin without a path')
|
|
@@ -250,12 +270,42 @@ export function createHostedApp({
|
|
|
250
270
|
needSession,
|
|
251
271
|
needFresh,
|
|
252
272
|
needFreshOrRecovery,
|
|
253
|
-
|
|
273
|
+
passkeysGate,
|
|
274
|
+
tailnetOnly,
|
|
275
|
+
needFreshOrHeldRemoval,
|
|
276
|
+
removesHeldPasskey,
|
|
277
|
+
noPasskey,
|
|
278
|
+
needUnrestricted,
|
|
279
|
+
needPasskeyBacked,
|
|
280
|
+
fixedCore,
|
|
281
|
+
cutTailnetSessions,
|
|
282
|
+
passkeyOrThrow,
|
|
283
|
+
machineTokensOrThrow,
|
|
284
|
+
adminMakingOrThrow,
|
|
285
|
+
coreFreshOrThrow,
|
|
286
|
+
stepUp,
|
|
287
|
+
stepUpOrThrow,
|
|
254
288
|
inWorkspace,
|
|
255
289
|
inProject,
|
|
256
290
|
handle,
|
|
257
291
|
auditOf,
|
|
258
|
-
} = createGuards({
|
|
292
|
+
} = createGuards({
|
|
293
|
+
db,
|
|
294
|
+
dataDir,
|
|
295
|
+
auth,
|
|
296
|
+
quotas,
|
|
297
|
+
secure,
|
|
298
|
+
trustProxy,
|
|
299
|
+
rateLimiter,
|
|
300
|
+
siteOf,
|
|
301
|
+
SESSION_COOKIE,
|
|
302
|
+
iso,
|
|
303
|
+
now,
|
|
304
|
+
log,
|
|
305
|
+
tailnet,
|
|
306
|
+
passkeys,
|
|
307
|
+
})
|
|
308
|
+
const tailnetAccounts = createTailnetAccounts({ db, iso, now })
|
|
259
309
|
|
|
260
310
|
// ---- Headers for everything ----
|
|
261
311
|
app.use((req, res, next) => {
|
|
@@ -270,6 +320,10 @@ export function createHostedApp({
|
|
|
270
320
|
app.use(usercontent.gate)
|
|
271
321
|
// While moving: which origin a request is for; the old one serves only the move.
|
|
272
322
|
app.use(previousHostGate(sites))
|
|
323
|
+
// Passkeys off (a tailnet sign-in server, by default): their routes say so.
|
|
324
|
+
app.use(passkeysGate)
|
|
325
|
+
// The fixed core: what always asks for a fresh passkey check (one table, src/hosted/step-up.js).
|
|
326
|
+
app.use(fixedCore)
|
|
273
327
|
|
|
274
328
|
const { publicUser, createWorkspace, acceptInvite, revokeGrantsOf, ownerCount } = createMembership({
|
|
275
329
|
db,
|
|
@@ -317,12 +371,23 @@ export function createHostedApp({
|
|
|
317
371
|
needSession,
|
|
318
372
|
needFresh,
|
|
319
373
|
needFreshOrRecovery,
|
|
374
|
+
tailnetOnly,
|
|
375
|
+
passkeys,
|
|
376
|
+
needFreshOrHeldRemoval,
|
|
377
|
+
removesHeldPasskey,
|
|
378
|
+
noPasskey,
|
|
379
|
+
needUnrestricted,
|
|
380
|
+
needPasskeyBacked,
|
|
381
|
+
cutTailnetSessions,
|
|
320
382
|
auditOf,
|
|
321
383
|
publicUser,
|
|
322
384
|
createWorkspace,
|
|
323
385
|
acceptInvite,
|
|
324
386
|
revokeGrantsOf,
|
|
325
387
|
ownerCount,
|
|
388
|
+
secure,
|
|
389
|
+
tailnet,
|
|
390
|
+
tailnetAccounts,
|
|
326
391
|
})
|
|
327
392
|
app.use('/auth', authRouter)
|
|
328
393
|
app.use('/auth', (req, res) => fail(res, 404, 'not_found', 'No such route.'))
|
|
@@ -352,7 +417,9 @@ export function createHostedApp({
|
|
|
352
417
|
inWorkspace,
|
|
353
418
|
inProject,
|
|
354
419
|
needFresh,
|
|
355
|
-
|
|
420
|
+
coreFreshOrThrow,
|
|
421
|
+
stepUp,
|
|
422
|
+
stepUpOrThrow,
|
|
356
423
|
auditOf,
|
|
357
424
|
HttpError,
|
|
358
425
|
listTokens,
|
|
@@ -384,6 +451,7 @@ export function createHostedApp({
|
|
|
384
451
|
const createApiToken = createApiTokens({ iso, auditOf, agentsFor })
|
|
385
452
|
const consoleDeps = {
|
|
386
453
|
db,
|
|
454
|
+
passkeys,
|
|
387
455
|
dataDir,
|
|
388
456
|
auth,
|
|
389
457
|
iso,
|
|
@@ -402,7 +470,12 @@ export function createHostedApp({
|
|
|
402
470
|
inWorkspace,
|
|
403
471
|
inProject,
|
|
404
472
|
needFresh,
|
|
405
|
-
|
|
473
|
+
coreFreshOrThrow,
|
|
474
|
+
passkeyOrThrow,
|
|
475
|
+
machineTokensOrThrow,
|
|
476
|
+
adminMakingOrThrow,
|
|
477
|
+
stepUp,
|
|
478
|
+
stepUpOrThrow,
|
|
406
479
|
auditOf,
|
|
407
480
|
createWorkspace,
|
|
408
481
|
acceptInvite,
|
|
@@ -410,6 +483,9 @@ export function createHostedApp({
|
|
|
410
483
|
ownerCount,
|
|
411
484
|
createApiToken,
|
|
412
485
|
agentsFor,
|
|
486
|
+
ownersSeeSignIns: ownersSeeSignIns === true,
|
|
487
|
+
tailnet,
|
|
488
|
+
tailnetAccounts,
|
|
413
489
|
}
|
|
414
490
|
mountInviteLinks(consoleApi, consoleDeps)
|
|
415
491
|
// Share link preview and opening: no session, the link is the secret.
|
|
@@ -420,7 +496,9 @@ export function createHostedApp({
|
|
|
420
496
|
consoleApi.use(needSession)
|
|
421
497
|
consoleApi.use(limit('session', (req) => req.user.id))
|
|
422
498
|
mountConsoleRoutes(consoleApi, consoleDeps)
|
|
499
|
+
mountTailnetAdmin(consoleApi, consoleDeps)
|
|
423
500
|
mountAgentRoutes(consoleApi, consoleDeps)
|
|
501
|
+
mountUsageRoutes(consoleApi, consoleDeps)
|
|
424
502
|
mountAdmin(consoleApi, deps)
|
|
425
503
|
mountShareAdmin(consoleApi, deps)
|
|
426
504
|
mountPublicAdmin(consoleApi, deps)
|
|
@@ -440,7 +518,8 @@ export function createHostedApp({
|
|
|
440
518
|
inWorkspace,
|
|
441
519
|
inProject,
|
|
442
520
|
handle,
|
|
443
|
-
|
|
521
|
+
stepUp,
|
|
522
|
+
stepUpOrThrow,
|
|
444
523
|
auditOf,
|
|
445
524
|
clientIp,
|
|
446
525
|
policyFor,
|
|
@@ -481,7 +560,7 @@ export function createHostedApp({
|
|
|
481
560
|
agentsFor,
|
|
482
561
|
boardContext,
|
|
483
562
|
dispatchView,
|
|
484
|
-
|
|
563
|
+
stepUp,
|
|
485
564
|
approvalApi,
|
|
486
565
|
chatFor,
|
|
487
566
|
hub: turnHub,
|
|
@@ -531,6 +610,7 @@ export function createHostedApp({
|
|
|
531
610
|
return mintSetupLink(db, publicOrigin, now())
|
|
532
611
|
}
|
|
533
612
|
app.locals.deviceLogins = deviceLogins
|
|
613
|
+
app.locals.cutTailnetSessions = cutTailnetSessions
|
|
534
614
|
app.locals.sites = sites
|
|
535
615
|
|
|
536
616
|
// Staging sweep at start and on a timer (unref'd: it never keeps the
|
|
@@ -583,7 +663,9 @@ export function createHostedApp({
|
|
|
583
663
|
while (i < hops.length - 1 && hops[i + 1] && trusted(hops[i], i)) i += 1
|
|
584
664
|
return hops[i] || 'unknown'
|
|
585
665
|
}
|
|
586
|
-
const presence = hub.listener(presenceAuthorizer({ db, dataDir, origin: publicOrigin, auth, now, guestOnly }), {
|
|
666
|
+
const presence = hub.listener(presenceAuthorizer({ db, dataDir, origin: publicOrigin, auth, now, guestOnly, tailnet, passkeys }), {
|
|
667
|
+
clientIp: upgradeIp,
|
|
668
|
+
})
|
|
587
669
|
app.locals.presence = { attach: presence.attach, close: presence.close, hub }
|
|
588
670
|
app.locals.events = events
|
|
589
671
|
app.locals.agentPresence = agentPresence
|