Skip to content

Commit 4b66c57

Browse files
committed
feat: implement machine enrollment and authentication features
- Added HubMachineIdentity interface for machine identity representation. - Enhanced HubStore class with methods for creating, authenticating, and revoking machines. - Introduced credential_digest column in machines table for secure credential storage. - Implemented heartbeat functionality for machine status updates. - Created hub-machine-enrollment module for managing machine credentials, including reading, writing, and validating credentials. - Added tests for machine enrollment functionality to ensure security and correctness. - Updated useWorkspaceTabs hook to manage active tabs more effectively across workspaces. - Refactored App component to improve workspace tab handling and navigation history. - Changed TypeScript configuration to use ESNext module for better compatibility.
1 parent ac6faa7 commit 4b66c57

16 files changed

Lines changed: 2239 additions & 1494 deletions

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ The shared React renderer supports desktop and direct browser clients. New rende
147147

148148
Remote-access credentials are authority boundaries. Pairing tokens must remain short-lived, memory-only, and single-use. Persist only device-session digests in owner-only atomic stores; enforce expiry and revocation. Browser HTTP/WebSocket origins must match exactly or be explicitly configured—never reflect arbitrary `Origin`/forwarded headers. Keep authentication limiters bounded, and do not hardcode CJ's `crewcode.logixhub.icu` deployment as a default Hub URL.
149149

150-
The self-hosted Hub is a separate `crewcode hub` process, not Electron renderer state. Keep its SQLite store owner-only and server-side; persist WebAuthn public credentials and only digests of browser/CSRF secrets. Bootstrap credentials and WebAuthn challenges stay short-lived and memory-only. Require user verification, exact configured RP origin/id, one-use challenges, secure HttpOnly SameSite cookies, and CSRF checks for mutations. Do not let Hub identity imply brain execution authority: enrollment, tickets, relay, and brain-side authorization remain separate gates.
150+
The self-hosted Hub is a separate `crewcode hub` process, not Electron renderer state. Keep its SQLite store owner-only and server-side; persist WebAuthn public credentials and only digests of browser/CSRF secrets. Bootstrap credentials and WebAuthn challenges stay short-lived and memory-only. Require user verification, exact configured RP origin/id, one-use challenges, secure HttpOnly SameSite cookies, and CSRF checks for mutations. Machine enrollment tokens must also stay short-lived, memory-only, single-use, and rate-limited; persist only machine bearer digests at the Hub and keep the brain credential file owner-only. Presence is outbound-only and revocation must fail closed. Do not let Hub identity or machine presence imply brain execution authority: tickets, relay, command scope, and brain-side authorization remain separate gates.
151151

152152
### Path alias
153153

‎bin/crewcode-server.mjs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import { spawnSync } from 'child_process'
77

88
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..')
99
const args = process.argv.slice(2)
10-
const command = args[0] === 'hub' ? 'hub' : 'serve'
11-
const entry = join(root, 'out', 'main', command === 'hub' ? 'hub.js' : 'headless.js')
10+
const requested = args[0]
11+
const command = requested === 'hub' || requested === 'enroll' || requested === 'brain' ? requested : 'serve'
12+
const entry = join(root, 'out', 'main', command === 'hub' ? 'hub.js' : command === 'serve' ? 'headless.js' : 'brain.js')
1213
if (!existsSync(entry)) {
1314
console.error(`CrewCode ${command} build is missing. Run \`npm run build\` before starting from this checkout.`)
1415
process.exit(1)
@@ -19,8 +20,8 @@ if (!existsSync(entry)) {
1920
delete process.env.ELECTRON_RUN_AS_NODE
2021
const require = createRequire(import.meta.url)
2122
const module = require(entry)
22-
const run = command === 'hub' ? module.runHub : module.runHeadless
23-
run(command === 'hub' || args[0] === 'serve' ? args.slice(1) : args).catch(error => {
23+
const run = command === 'hub' ? module.runHub : command === 'serve' ? module.runHeadless : (argv => module.runBrainCommand(command, argv))
24+
run(command !== 'serve' || requested === 'serve' ? args.slice(1) : args).catch(error => {
2425
console.error(error?.message || String(error))
2526
process.exitCode = 1
2627
})

‎docs/security-model.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,37 @@ per-authenticated-session RPC bandwidth/request budget, remote execution custody
5959
not fully persisted, and public deployment still depends on correctly configured
6060
TLS/reverse-proxy infrastructure. Prefer loopback or a trusted tailnet.
6161

62+
## Hub owner -> enrolled machine boundary
63+
64+
**Boundary:** signing into the Hub must not silently enroll a machine or grant remote
65+
execution. A stolen/replayed enrollment link, database disclosure, cross-site
66+
request, or revoked machine credential must not produce lasting machine presence.
67+
68+
**Enforcement:** only a valid owner browser session plus its rotated CSRF secret can
69+
issue an enrollment token. Tokens contain 256 bits of random secret, live only in
70+
Hub memory, expire after ten minutes, are single-use, and are consumed after a failed
71+
secret presentation for a known id. Issuance/enrollment requests are bounded by a
72+
per-peer limiter. Enrollment creates an Ed25519 identity on the brain and a separate
73+
256-bit bearer credential; the brain stores both in an owner-only atomic file while
74+
the Hub stores the public key and only SHA-256 of the bearer secret. Heartbeats are
75+
outbound HTTPS requests. Presence goes offline after 90 seconds without a successful
76+
heartbeat, and owner revocation immediately makes the bearer credential fail closed.
77+
Browser mutations retain exact-origin and CSRF enforcement.
78+
79+
**Authority limit:** presence proves only that the enrolled process recently
80+
possessed its machine credential. It does not authorize commands, filesystem access,
81+
agent execution, a relay, or a connection ticket. The current Ed25519 key is reserved
82+
for later signed-ticket/relay work; heartbeats currently authenticate with the
83+
separate bearer credential over TLS.
84+
85+
**Tests:** `hub-server.test.ts` covers CSRF, issue/enroll, replay rejection, stale
86+
presence, heartbeat, and revocation. `hub-machine-enrollment.test.ts` covers URL
87+
policy, argument-secret avoidance, credential validation, and owner-only file mode.
88+
89+
**Residual limitation:** machine credential rotation/logout and recovery are not yet
90+
implemented. The long-running brain presence process requires an external service
91+
manager for automatic restart and does not yet use signed per-request challenges.
92+
6293
## Hop 1 — untrusted content -> agent
6394

6495
**Boundary:** injected instructions in scraped/file/MCP content must not gain

‎docs/web-remote-access.md‎

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,12 @@ AuditEvent(id, user_id?, machine_id?, browser_session_id?, type, created_at, met
261261
7. Implement the self-hosted `crewcode hub` process, local owner bootstrap,
262262
passkey sessions, machine registry, audit events, and signed single-use tickets.
263263
**Process/CLI, SQLite identity schema, passkey bootstrap/sign-in, browser sessions,
264-
audit storage, and read-only machine-list skeleton are complete. Enrollment writes,
265-
recovery, machine credentials, and signed connection tickets remain.**
264+
audit storage, and machine registry are complete. Recovery and signed connection
265+
tickets remain.**
266266
8. Implement `crewcode enroll`, persistent machine identity, outbound presence, and
267-
explicit machine revoke/logout commands.
267+
explicit machine revocation. **Enrollment, owner-only machine credentials,
268+
outbound heartbeat presence, dashboard status, and revocation are complete.
269+
Machine logout/credential rotation remain.**
268270
9. Implement the bounded Hub relay and a transport-neutral multiplexed tunnel with
269271
authenticated end-to-end browser-to-brain encryption.
270272
10. Replace the direct-only browser connection screen with local Hub sign-in,
@@ -302,24 +304,48 @@ require an explicit final public origin; non-loopback origins require HTTPS beca
302304
the origin is cryptographically bound to passkeys. Put a TLS reverse proxy or
303305
Tailscale HTTPS in front of the HTTP listener for network deployment.
304306

307+
After signing in, select **Enroll a machine**. The Hub issues a memory-only,
308+
ten-minute, single-use token. On that machine run the displayed command and paste
309+
the token at the hidden prompt:
310+
311+
```bash
312+
crewcode enroll --hub https://your-hub.example
313+
crewcode brain
314+
```
315+
316+
Enrollment creates an Ed25519 machine identity plus a random bearer credential in
317+
`~/.crewcode/brain/hub-machine.json`, written with owner-only permissions. The Hub
318+
stores the public key and only a SHA-256 digest of the bearer secret. `crewcode brain`
319+
then makes outbound HTTPS heartbeat requests every 30 seconds; the dashboard marks a
320+
machine offline after 90 seconds without a successful heartbeat. Revoking it in the
321+
dashboard immediately rejects later heartbeats. Enrollment tokens are never written
322+
to the Hub database and are invalidated by Hub restart, expiry, first successful use,
323+
or a failed guess against their id.
324+
325+
This presence process does **not** accept commands, expose workspaces, start agents,
326+
or establish a relay. The Ed25519 key is reserved for the later signed-ticket and
327+
encrypted-relay stages; current heartbeat authentication uses the separate random
328+
machine bearer credential over HTTPS.
329+
305330
Planned direct-auth and remaining Hub commands:
306331

307332
```bash
308333
crewcode pair
309334
crewcode auth sessions
310335
crewcode auth revoke <session-id>
311-
crewcode enroll --hub <https-url>
312336
crewcode hub machines
313337
crewcode hub revoke <machine-id>
338+
crewcode brain logout
314339
```
315340

316341
The initial CLI distribution is implemented. From a checkout, run `npm run serve`;
317342
from a published package, run `npx crewcode@latest` or `crewcode serve`. It
318343
builds/serves the shared renderer, defaults to loopback, prints a single-use pairing
319344
URL, resolves installed provider CLIs without Electron, and shuts down cleanly on
320-
SIGINT/SIGTERM. The direct-auth, enrollment, machine-management, and relay commands
321-
above remain planned. `crewcode hub` has its own standalone setup/sign-in/machine-list
322-
screen; it does not yet mount the shared CrewCode workspace client.
345+
SIGINT/SIGTERM. The direct-auth CLI and remaining machine-management/relay commands above remain
346+
planned. Enrollment and dashboard revocation are implemented. `crewcode hub` has its
347+
own standalone setup/sign-in/machine-list screen; it does not yet mount the shared
348+
CrewCode workspace client.
323349

324350
## Current backend extraction
325351

‎electron.vite.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default defineConfig({
2424
index: resolve('src/main/index.ts'),
2525
headless: resolve('src/main/headless.ts'),
2626
hub: resolve('src/main/hub.ts'),
27+
brain: resolve('src/main/hub-machine-enrollment.ts'),
2728
},
2829
},
2930
}

0 commit comments

Comments
 (0)