A credential scoped to one lease, dead when the lease ends

未关闭
#1,895 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@V3RON 已经在做这个了。

开始于 2026年11月27日。

  • #1898 来自 @V3RON —— 未关闭

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃

调研方向

Start with ADR 0092 and ADR 0093, then trace the authentication dispatcher, HTTP path gate, agent-device front, and token create flow named in the issue. The completion conditions and behavior table identify the required worker and gateway cases, expiry behavior, and existing behavior to preserve. This spans authentication, routing, lease lifecycle, and CLI work, so it requires broad project familiarity.

由索引模型根据 Issue 内容生成。

描述

feature:planned

Request: #1407

Problem

A coordinator, such as a CI job or an agent orchestrator, often leases a device for an agent it does not fully trust. That might be an agent working on a contributor's branch, or a job on someone else's machine. Today it can only give that agent its own token, or ask an operator for a token per job. An agent token is one identity: every agent that holds it can exec on, stream, upload to, renew and release every lease of that token, and exec is a shell on the worker. Tokens never expire, so a forgotten one keeps its rights until someone runs token revoke.

In the reporter's words: "To hand a device to a short-lived job safely we'd have to mint and revoke a token per job ourselves, and even then the token reaches more than that one lease."

Who it is for

  • A coordinator that holds an agent token (or an operator token) and hands a device to an agent for one job.
  • An operator who gives a person or a pipeline a token for a fixed time.

Outcome

  • The owner of a lease can make a handover credential for that lease and give it to an agent. With it the agent can use that one device through agent-device, the screen, input, files and tunnels, renew the lease and end it. It cannot run commands on the worker (exec), lease anything else, or see the owner's other leases. The credential stops working the moment the lease ends, whoever ends it, and when the owner's token is revoked or expires.
  • An operator can make an agent or operator token that stops working at a set time.

How it works for the user

sequenceDiagram
  participant C as Coordinator (owner)
  participant D as Worker or gateway
  participant A as Agent
  C->>D: simlock lease --platform ios (lease L1)
  C->>D: simlock lease handover L1
  D-->>C: slk_… (shown once)
  C->>A: slk_…
  A->>D: agent-device connect proxy … --daemon-auth-token slk_…, then open
  D-->>A: opened on L1's device (no new lease)
  A->>D: snapshot, screen, files …
  A->>D: exec, another lease, a new lease
  D-->>A: 403 FORBIDDEN
  alt the agent ends it
    A->>D: agent-device close
  else the owner ends it
    C->>D: simlock release L1
  end
  A->>D: any call with slk_…
  D-->>A: 401 UNAUTHENTICATED

Before:

coordinator$ simlock token create --role agent --label job-42     # operator only
{"secret":"slk_9f…","token":{"id":"tok_ab12","role":"agent",…}}
agent$ SIMLOCK_TOKEN=slk_9f… simlock --url https://farm exec L7 -- uname -a   # another job's lease
Darwin worker-3 …

After:

coordinator$ simlock --url https://farm lease handover lse_4b2e
{"secret":"slk_c3…","handover":{"id":"hov_77","leaseId":"lse_4b2e","createdAt":…}}
agent$ agent-device connect proxy --daemon-base-url https://farm/v1/agent-device --daemon-auth-token slk_c3… --session s1
agent$ agent-device open --platform ios --session s1      # opens on lse_4b2e's device
agent$ curl -X POST -H 'Authorization: Bearer slk_c3…' https://farm/v1/leases/lse_4b2e/exec …
{"error":{"code":"FORBIDDEN","message":"A handover credential cannot call device.exec"}}
agent$ curl -H 'Authorization: Bearer slk_c3…' https://farm/v1/leases/lse_9d01
{"error":{"code":"FORBIDDEN","message":"A handover credential reaches only lease lse_4b2e"}}
coordinator$ simlock --url https://farm release lse_4b2e
agent$ curl -H 'Authorization: Bearer slk_c3…' https://farm/v1/leases/lse_4b2e
{"error":{"code":"UNAUTHENTICATED","message":"Unknown bearer token"}}

operator$ simlock token create --role agent --label contractor --expires-in 7d
{"secret":"slk_…","token":{"id":"tok_cd34","role":"agent","label":"contractor","createdAt":…,"expiresAt":…}}
# eight days later
{"error":{"code":"UNAUTHENTICATED","message":"Token tok_cd34 expired at 2026-12-04T09:00:00.000Z"}}

Examples

What a handover credential for lease L1 may reach (B5, B6):

Call Owner's agent token today Handover credential for L1
GET /v1/leases/L1, /events, /renew, DELETE /v1/leases/L1 allowed allowed
/v1/leases/L1/stream, /input, /tunnel, /files*, /rotate allowed allowed
POST /v1/leases/L1/exec allowed 403 "cannot call device.exec"
POST /v1/leases/L1/handovers allowed 403 "cannot call lease.handover"
any route of lease L2 the owner holds allowed 403 "reaches only lease L1"
GET /v1/leases the owner's leases L1 only
/v1/lease-requests*, /v1/status, /v1/devices*, /v1/catalog, /v1/stats, /v1/events*, /v1/inbox, /v1/tokens, /v1/stream/workers/*, every admin route per role 403 "reaches only lease L1"
GET /v1/identity, GET /v1/healthz allowed allowed (via: "handover")
GET /v1/session (remote CLI, MCP) allowed allowed; each call held as above. The MCP tools act only on a lease their own session was granted, so not on L1 (decided in delivery, pending the maintainer)
agent-device open leases a new device opens on L1's device
agent-device open a second time while the first is open a second lease refused: L1 is already open
agent-device devices, session list the token's L1's only

--expires-in on token create (B1):

Input Today After
none never expires never expires
7d, 12h, 90m flag unknown expires that long after create
30s, 0, 59999 (ms) flag unknown refused by the daemon: under one minute
90000 (a bare number is ms: 90 s) flag unknown expires 90 s after create
3651d flag unknown refused by the daemon: over 3650 days
-1h, 7days, 1.5h flag unknown usage error: not a duration
--role worker --expires-in 1d flag unknown refused: a join token cannot expire

What could go wrong

  • An agent with a handover credential finds a route or front path that still reads only the owner's identity and reaches the owner's other leases. The two allowlists keep a new route refused until someone adds it; the Examples table is the test.
  • For about a minute after a gateway restart, a handover credential for a lease whose worker has not reported yet is refused. Its row is kept, so the agent's retry works once the worker reports.
  • A worker that stays offline for more than a minute across a gateway restart has its leases read as ended, and their handovers are deleted. The owner makes a new one once the worker is back.
  • An operator sets --expires-in too short and a pipeline stops mid-run with "expired". The message names the token and the time.

Words used

  • handover credential: an slk_ secret made for one lease by its owner, e.g. simlock lease handover lse_4b2e. It acts as the owner on that lease only.
  • owner: the identity a lease belongs to. Over HTTP it is the token that requested the lease, e.g. tok_ab12.
  • principal: the identity a call is made as. For a token it is the token's id; for a handover credential it is the lease owner's.
  • scope: the one lease a handover identity is held to.
  • live lease: a lease that has not ended or expired on the daemon that made the credential.
  • agent-device lease id: the id agent-device makes up at open, 32 hex characters, e.g. 669b4a9e18d9144c093269b9b94a0bb9. Today the front uses it as the simlock lease id too; for a handed-over lease the two differ.

Non-goals

  • Exec, simctl or adb passthrough with a handover credential, in any form or behind any flag.
  • A handover credential that outlives its lease or its owner's token, moves to another lease, or makes another handover.
  • Listing or revoking handover credentials one by one. Ending the lease ends them all; token revoke of the owner ends that owner's.
  • An MCP tool or a console page for handovers.
  • A default lifetime for tokens, an expiry on worker join tokens, or changing a token's expiry after it is made.
  • Isolating agents that share one token from each other: one token per agent stays the advice.
  • Any change to agent-device.

Completion conditions

  • On a worker and through a gateway, an owner makes a handover credential for a lease made with simlock lease (through a gateway with --requires agent-device); with it an agent runs agent-device open, takes a screenshot, uploads a file and opens the screen stream on that lease's device, and is refused exec, any other lease and a new lease.
  • After the agent's agent-device close, and after the owner's release, the credential is refused at once on every route.
  • A token made with --expires-in 2m works, then is refused with "expired" after two minutes, and a remote session or screen stream opened with it ends at that time; a handover made by that token is refused from the same moment.
  • token create without --expires-in behaves as today.

Open questions

none

Decisions

  • ADR 0098 — A lease owner hands one lease to an agent with a credential that dies with it: the handover call, the scope and its two gates, no exec, death with the lease and the owner's token, agent-device attaching with two ids, the gateway's own.
  • ADR 0093 — An agent or operator token may carry an expiry: --expires-in, refusal, expiresAt on the identity.
  • Maintainer, in the session: exec is banned for handover credentials; agent-device is in the first version; token expiry is in this feature; agent-device close on a handed-over lease ends the simlock lease, so either side may end it; a handover dies when its owner's token expires; the front maps agent-device's lease id onto the handed-over lease, with no agent-device change.
  • Decided in the session: the handover is its own call after the grant, not a flag on lease.request, because a grant is re-read and replayed and a secret in it would be shown more than once.
  • Decided in the session: a handover identity carries the lease owner's principal plus its scope, because every ownership check then works unchanged and the agent shares the lease's agent-device tenant with the owner. For an operator's handover the principal is still the lease's owner, never the operator's.
  • Decided in the session: the scope is enforced by two allowlists, the dispatcher (every operation, every transport) and the HTTP path gate (every route), and by the agent-device front, because a new route or operation is then refused until someone adds it.
  • Decided in the session: a handover binds to the lease id and the lease's grantedAt, because a requester-chosen id can be granted again after lease.endedIdRetentionMs.
  • Decided in the session: liveness is read at every verify and every scoped call; a row is deleted only when its lease is known ended, never while the daemon cannot yet tell, because a gateway's lease index is empty until its workers report.
  • Decided in the session: handover verification is its own auth strategy, handover, asked first, because a strategy's via must equal its name and an unknown slk_ token is refused by the token strategy.
  • Decided in the session: tunnels are allowed, because a tunnel reaches only the lease's own device ports (an iOS simulator's listener is checked by its SIMULATOR_UDID).
  • Decided in the session: the agent needs no lease id: agent-device 0.21.41 through the proxy ignores --lease-id and makes up its own (run against a stub on 2026-11-27: connect proxy --lease-id lse_abc123, then open, sent leaseId: "669b4a9e18d9144c093269b9b94a0bb9"), and the credential already names the lease.
  • Decided in the session: one agent-device lease at a time per handed-over lease, because a lease holds one device and agent-device holds one device per session.
  • Decided in the session: --expires-in takes 1 minute to 3650 days through the one duration parser, and the operation takes expiresInMs so the daemon's clock sets the time.
  • Decided in the session: an expired token stays in token list until revoked, and is refused with its own message, so an operator sees what ran out.

Behaviours

Id Behaviour (invoker, action, what it sees) Seam Cases Task
B1 An operator runs token create with --expires-in; the answer and token list carry expiresAt simlock token create (CLI) and token.create (worker and gateway dispatchers) through a gateway → the same as a worker; none → no expiresAt; 7d → now + 7 d; 30s, 0, 3651d → I1 range refusal; -1h, 7days → I2 usage error; --role worker --expires-in 1d → I1 worker refusal #1904
B2 A caller with an expired token is refused everywhere a token is checked authenticateRequest and resolveHelloRole (src/auth) HTTP before expiry → identified with expiresAt; HTTP at or after → 401 I3; socket hello with an expired operator token → AdminAuthenticationFailedError; a token with no expiry → as today #1904
B3 A remote session, a screen stream and an event stream opened with an expiring token end at its expiry /v1/session upgrade, /v1/leases/{id}/stream, /v1/events/stream (HTTP app) session closes at expiresAt; stream ends at expiresAt; an expiry further off than one timer holds (2^31-1 ms, 24.8 days) → neither ends early; token with no expiry → unbounded, as today #1904
B4 A lease's owner makes a handover credential; the secret is shown once lease.handover (dispatcher), POST /v1/leases/{id}/handovers, simlock lease handover owner → 201 with I4's answer, S2 owner_id = the lease's owner; simlock lease handover over the local socket and with --url (/v1/session) → the same answer; operator on another's lease → 201, owner_id = the lease's owner; another agent → 403; unknown lease → 404 UNKNOWN_LEASE; a handover identity → 403 I6; two handovers of one lease → two working secrets; through a gateway → stored on the gateway #1905
B5 A handover identity calls an operation; only the allowlist on its own lease runs, on every transport runDispatch (src/daemon/dispatch.ts) on a worker and a gateway, over HTTP and over /v1/session lease.get, lease.renew, lease.release, device.rotate on L1 → run; the same on L2 → 403 I6; device.exec, lease.request, lease.cancel, lease.handover, an admin operation → 403 I6; lease.list on a worker and on a gateway → L1 only; identity.get → via: "handover"; over /v1/session the same answers as over HTTP #1905
B6 A handover identity calls an HTTP route; the path gate passes only its own lease's paths and the shared ones requireAuth's scope gate (src/http) GET /v1/leases, /v1/leases/L1 and every path under it → passed on (then B5 for operations); any path of L2 → 403 I6; /v1/identity, /v1/healthz, /v1/session → passed on; /v1/agent-device/* → 403 I6 until #1906 opens it with the front's checks (B10, B11); every other path → 403 I6 #1905
B7 A handover credential stops working the moment its lease ends the handover strategy with I7, on a worker and a gateway lease live → identified; released by the owner → 401 "Unknown bearer token"; released by the agent → same; expired by TTL → same; a lease granted later under the same chosen id → same (grantedAt differs); a remote session opened before the end → its next call is refused 401's words and the session closes 4003 #1905
B8 A handover dies with its owner's token the handover strategy owner token live → identified, expiresAt = the owner token's; owner token expired → 401 "Unknown bearer token"; owner token revoked → same, and the revoke deleted the owner's S2 rows and closed their sessions 4003; owner not a token (local socket, proxy person) → no owner check #1905
B9 Handover rows are removed only once their lease is known ended S2 deletes worker start: rows whose lease the loaded registry lacks → deleted; worker verify of an ended lease → deleted; gateway verify inside its start window with the lease unknown → refused, row kept; gateway verify after it with the lease unknown → deleted; live lease → kept #1905
B10 An agent with a handover credential runs agent-device open; the path gate now passes /v1/agent-device/*, and the front opens agent-device on L1's device and leases nothing agent-device front (src/agent-device/front), worker link and gateway relay link open → forwarded on L1's device with the CLI's own agent-device lease id, no lease.request, map entry under that id naming L1; L1 on a worker where agent-device is off → the front's existing not-available reply; a second open while that entry is live → refused I8; open after the entry ended → as the next row's end #1906
B11 Every front call with a handover credential is held to L1 agent-device front, worker and gateway a call naming the attached agent-device lease → forwarded with L1's tenant; naming another lease, the owner's L2 included → 403 I8; naming none (session list, devices) → L1's only, sent with L1's tenant instead of the principal's; heartbeat → renews L1 as today; the owner's other map entries are never marked ended by a scoped devices #1906
B12 agent-device close by the agent ends L1, and L1's end releases the agent-device lease front close and release paths, the host's lease end close → agent-device lease released, then lease.release of L1; then the credential → 401 (B7); close after an open with retainOnClose → both leases stay, as for a lease the front made (ADR 0070 §2); the owner's release → the host releases the attached agent-device lease by its own id and removes its session folders, and the agent's next call → 401 (B7) #1906
B13 After a restart, nothing of the owner's is adopted under a handover identity, and the agent opens again front adoption a scoped identity's first call after a worker or gateway restart → no lease adopted; open again → B10 on L1 while L1 lives; after a gateway restart the worker's agent-device lease on L1 may still be open, so the new attach releases it on the host first and S4 then holds only the new one #1906

Stored state

Id What and where Created, changed, deleted by Listed or swept by A restart mid-step leaves Schema step Task Used by
S1 tokens.expires_at INTEGER (nullable, epoch ms), in the daemon's state.db, owner tokens written by token.create when expiresInMs is given, in the same insert; never changed; deleted with the row by token.revoke token.list shows it as expiresAt; read by every token verify and by B8 nothing: one insert tokens +1 #1904 #1905
S2 lease_handovers table (id TEXT PK, hash TEXT UNIQUE, lease_id TEXT, lease_granted_at INTEGER, owner_id TEXT, created_at INTEGER), in state.db of both roles (stateOwners), its own schema owner in src/auth inserted by lease.handover, owner_id = the lease's owner; deleted per B9, and by token.revoke of owner_id B9's worker start sweep, run after the registry loads; no list operation an insert either landed or not; rows whose lease ended meanwhile go by B9 lease_handovers +1 #1905 #1906
S3 Front map entry for an attached lease (memory), src/agent-device/front/front-map.ts added by B10 under the CLI's agent-device lease id, with simlockLeaseId: L1 and the handover identity; ended and dropped as entries are today — lost at a restart; B13 none #1906 —
S4 The host's release scope for an attached lease, and its id map (memory), src/agent-device/host/lease-end.ts recorded at the attach's allocate (I9) under L1's worker lease id, with a map agent-device id → L1's worker lease id that every later call's serve, trackAllocate and trackRelease go through; read and dropped at L1's lease end, which releases by the agent-device id and removes its folders — lost at a restart, as today none #1906 —

Interfaces

Id What Shape and bounds Errors and limits Where Task Used by
I1 token.create input and tokenRecordSchema input gains expiresInMs?: integer, 60 000 to 315 360 000 000; record gains expiresAt?: number; bumps the protocol by one BAD_REQUEST "expiresInMs must be between 1 minute and 3650 days"; BAD_REQUEST "A worker join token cannot expire" src/contract/operations-admin.ts, config-schemas.ts #1904 #1905
I2 simlock token create --expires-in <duration>, SimlockAdminClient.createToken({expiresInMs}) duration through parseDurationMs (a bare number is milliseconds); output JSON as today, with expiresAt usage error "--expires-in takes a duration such as 30m, 12h or 7d" for text the parser refuses; I1's refusals as the daemon sends them src/cli/commands/token.ts, src/simlock-client #1904 —
I3 Token verify with an expiry an unexpired token's identity gains expiresAt = S1 HTTP 401 UNAUTHENTICATED "Token expired at "; hello → AdminAuthenticationFailedError as for an unknown credential src/auth/strategies/token, src/auth/index.ts, src/auth/token-store.ts #1904 #1905
I4 lease.handover operation, POST /v1/leases/{id}/handovers, simlock lease handover <lease-id>, SimlockClient.handoverLease(leaseId) input { leaseId: string }; output { secret: string, handover: { id: string, leaseId: string, createdAt: number } }; role agent, authorize = ownsLease; HTTP 201; secret slk_ + the token secret generator; id hov_<id>; bumps the protocol by one FORBIDDEN "Not authorized for lease.handover"; UNKNOWN_LEASE; a handover identity → I6 src/contract/operations-leases.ts, both dispatchers, src/http/lease-declarations.ts, src/cli/tree.ts:68, src/simlock-client #1905 #1906
I5 Handover identity and session Identity, DispatchSession and the session connection's identity gain scope?: { leaseId: string; handoverId: string; grantedAt: number }, each scoped call comparing grantedAt (decided in delivery, pending the maintainer); principal = S2 owner_id; via: "handover" (added to identity.get's via enum and to SessionIdentity.via, same bump as I4); role: "agent"; expiresAt = the owner token's, when it has one — src/auth/identity.ts, src/auth/strategies/handover/ (new, first in strategies/index.ts), src/daemon/dispatch.ts, src/http/dispatcher-session.ts, src/daemon/server.ts, server-connection.ts, server-requests.ts, src/contract/operations-fleet.ts:324 #1905 #1906
I6 Scope refusal — 403 FORBIDDEN "A handover credential cannot call " (an operation off the allowlist on its own lease); "A handover credential reaches only lease " (another lease id, or a path off the gate) checkAccess (src/daemon/dispatch.ts); the HTTP path gate #1905 #1906
I7 LiveLeases port, bound into auth after the mode branch liveLease(leaseId): { state: "live"; ownerId: string; grantedAt: number } | { state: "ended" } | { state: "unknown" }; a worker answers from its registry once loaded (unknown before); a gateway from its lease index (unknown for a missing id inside REBUILD_WINDOW_MS after its start, ended after); until bound, unknown; also given to runDispatch's lookups for B5 and B7 live with another grantedAt, ended, unknown → refused as I3's unknown token; ended (and another grantedAt) → row deleted src/auth/index.ts, src/daemon/main.ts:302, src/daemon/worker-composition.ts, gateway composition in src/daemon/main.ts, src/daemon/dispatch.ts #1905 —
I8 Front refusals for a handover identity agent-device replies as refusal() builds today "refused: lease is already open in agent-device; close it first" (second open); 403 "refused: lease is not one of yours" (as today, for any lease but the attached one) src/agent-device/front #1906 —
I9 Front link to the host for an attached lease the front sets header x-simlock-lease-id: <L1's worker lease id> on the attach's allocate (on a gateway the relay carries it to the worker); the front drops any copy the client sent; the host reads it in forward (src/agent-device/host/host.ts:134-158), with the RPC body's lease id, and sets S4 before proxy.handle; the bundled proxy forwards only its own header list, so it never reaches agent-device an L1 the link no longer holds → the front's existing "ended by simlock" reply src/agent-device/front/host-link.ts, relay-host-link.ts, src/agent-device/host/host.ts, lease-end.ts #1906 —

Existing code

Commit 4b39322d9.

Searches: tokenRecordSchema (8 hits), closeSessionsForToken (11), expiresAt in src outside proxy-jwt (20), ownsLease|authorizeOneLeaseCall (9), findOwnedLease (5), requireOwnRequest (4), runDispatch( (2), principal in src/agent-device/front (14), path: "/v1 (52), leaseEndParticipants (3), acceptSession (4), stateOwners (2), createAuth( (1), adoptable (6), ReleaseScopeRecord (5); agent-device 0.21.41 open run against a stub (Decisions).

Id Code (path:line) Today With this feature Handled by
X1 src/auth/token-store.ts:11-31 tokens schema v2, no expiry v3 adds S1 #1904, S1
X2 src/auth/token-store.ts:93-98 verify looks up by hash, no time check refuses past expires_at #1904 B2
X3 src/auth/strategies/token/index.ts:21-40, src/auth/strategies/index.ts identity: principal = token id, no expiresAt; strategies token, proxy adds expiresAt (#1904); a handover strategy goes first: a hash in S2 is its credential, any other secret not-mine (#1905) #1904, #1905
X4 src/auth/index.ts:103-108 resolveHelloRole operator token or admin secret → admin an expired operator token falls through to AdminAuthenticationFailedError; a handover secret is never admin #1904 B2, #1905
X5 src/ports/upgrade-router.ts:203-212, src/http/app.ts:143 a session with expiresAt closes at it fires for an expiring token and for a handover of one, with no change #1904 B3, #1905 B8
X6 src/stream/service.ts:117, src/http/app.ts:384, src/http/app-lease-request-routes.ts:103 streams end at the identity's expiresAt same #1904 B3
X7 src/daemon/main.ts:300-313 createAuth is built once, before the mode branch auth takes I7 by a bind call made after the registry loads (worker) or the index exists (gateway) #1905 I7
X8 src/daemon/main.ts:195-210 stateOwners tokensOwner in both roles S2's owner in both roles #1905 S2
X9 src/daemon/dispatch.ts:356-382 checkAccess, authorizeContext role check, then authorize; lookups ownerId, leaseRequesterId, pendingRequestOwner when session.scope is set: I7 liveness, then the operation allowlist and the lease id, before the role check #1905 B5, B7
X10 src/gateway/dispatcher.ts:321-327, src/daemon/dispatcher.ts:135 both call runDispatch both pass I7 in the lookups #1905 B5
X11 src/daemon/dispatcher-leases.ts:142-154, src/daemon/dispatcher-device-views.ts:12-16 worker lease.get/lease.list filter by principal a scoped session's list holds its lease only #1905 B5
X12 src/gateway/dispatcher.ts:576-579 #leaseList #ownedFleetLeases(session.principal) cut to the scope's lease #1905 B5
X13 src/http/dispatcher-session.ts:71-76 buildHttpSession copies principal, role, via copies scope #1905 I5
X14 src/daemon/server.ts:487-497 acceptSession, src/daemon/server-connection.ts:10-15, src/daemon/server-requests.ts:217-235 #session the session keeps name, via (token or proxy) and signOutUrl; each call's session is rebuilt from the connection the connection keeps scope and via: "handover", and #session hands them to each call; a call refused by B7's liveness closes the connection 4003 after its answer #1905 B5, B7
X15 src/http/app.ts:380-430 file routes, module lease routes, mounts; src/http/app-helpers.ts:59-62 requireOwnRequest resolve the lease through lease.get; stored requests by owner the path gate in requireAuth runs first; /v1/lease-requests* never reaches requireOwnRequest for a scoped identity #1905 B6
X16 src/daemon/server.ts:503-508, src/daemon/dispatcher-admin.ts:71, src/gateway/dispatcher.ts:442 revoke closes via: token sessions whose principal is the token also closes via: handover sessions of that principal and deletes S2 rows with that owner_id #1905 B8
X17 src/gateway/lease-index.ts:6-13,118-129; src/gateway/fleet-forwarding.ts:40-41 REBUILD_WINDOW_MS index in memory only, rebuilt from worker reports; an unknown id is unreachable for a minute after start backs I7's three states on a gateway #1905 B9
X18 src/agent-device/front/allocate.ts:103-104,200-256,349,385-396, src/agent-device/shared/rpc.ts:4 allocate needs a 32-hex lease id, sends lease.request with requester = lease id, reads the device from the link, writes the map entry a scoped identity's allocate keeps the CLI's 32-hex id for agent-device, sends no lease.request, reads L1's device facts from the link (as adoptable does: lease.get carries no address), and writes S3 #1906 B10
X19 src/agent-device/front/front.ts:325-350 readLeaseHeader, refuseForeignLease; src/agent-device/shared/tenant.ts:21-32 a foreign lease is refused on a worker only by the map's principal; tenant from principal and the header's lease id a scoped identity passes only for the attached entry; tenant from the principal and L1 #1906 B11
X20 src/agent-device/front/relay-host-link.ts:114-136 status, forward checks placed.ownerId === identity.principal a scoped identity is also held to L1's worker lease #1906 B11
X21 src/agent-device/front/token-devices.ts:18-29, devices-filter.ts:33-38 devices cut to the principal's live entries, and an entry missing from lease.list is marked ended for a scoped identity only the attached entry is read and marked #1906 B11
X22 src/agent-device/front/front.ts:401-418 adoptLeases, host-link.ts:99-115, relay-host-link.ts:142-160 adoptable adopts every front-made lease of the principal adopts nothing for a scoped identity #1906 B13
X23 src/agent-device/front/renewals.ts:22-33, heartbeat.ts:179-210,319 renewals and re-allocate read the map entry and use its lease id with simlock use the entry's simlockLeaseId toward simlock #1906 B11
X24 src/agent-device/front/ended.ts:66-99 releaseEndedLeases, closedLease; src/agent-device/front/release.ts:11-33 a close ends the simlock lease through the reply's endedLeases; a release ends it after agent-device for an attached entry, the simlock lease ended is simlockLeaseId #1906 B12
X25 src/agent-device/host/lease-end.ts:29-68,136-177,208-232 ReleaseScopeRecord, recordingFetch, nameCall, leaseEnded the scope is keyed by the lease id each RPC names, which is agent-device's and simlock's alike calls of an attached lease are keyed through S4's map to L1's worker lease id #1906 B12
X28 src/agent-device/front/front-map.ts:178-182 refresh, heartbeat.ts:162-175 stillHeld, boot.ts:20-28, context.ts:166-174 heldForAnother compare simlock's lease ids with the map key compare with the entry's simlockLeaseId for an attached entry #1906 B11
X29 src/daemon/server-requests.ts:24,207-214 PASSTHROUGH_OPERATIONS the socket and /v1/session hand only listed operations on; any other is UNKNOWN_REQUEST lease.handover is listed #1905 B4
X30 src/daemon/dispatcher-admin.ts:60-62, src/gateway/dispatcher.ts:432-435 token.create handlers pass role and label to the store also pass expiresInMs #1904 B1
X26 src/drivers/ios/device-tcp.ts:58,151-167 a tunnel connect reaches only listeners whose process names the lease's SIMULATOR_UDID why tunnels stay allowed #1905 B6
X27 website/src/content/docs/docs/using-devices/http-api.mdx:27, agent-device.mdx:64,94, ci.mdx:24-32, concepts/tokens-and-roles an agent token reaches the whole worker; one token per agent; connect proxy each task's docs describe its surface (documentation rule 9) #1904, #1905, #1906

Tasks

flowchart LR
  A["#1904 token expiry"] --> B["#1905 handover credential"] --> C["#1906 agent-device on a handed-over lease"]
  • #1904 feat(auth): an agent or operator token may carry an expiry — an operator can make a token that stops working at a set time. Risk: a token refused early or working late.
  • #1905 feat(auth): a lease owner hands one lease to an agent with a scoped credential — an owner hands one lease to an agent over HTTP, the remote CLI and MCP. Risk: an agent reaching the owner's other leases, or a credential outliving its lease.
  • #1906 feat(agent-device): agent-device opens on a handed-over lease — the agent drives the handed-over device through agent-device. Risk: open leasing a new device, or sessions left behind.

Completion conditions:

  • Handover on a worker and a gateway with agent-device, screenshot, file, stream, refusals: #1905 (HTTP, stream, files, refusals), #1906 (agent-device, slow lane).
  • Refused at once after the agent's close and the owner's release: #1905 (release), #1906 (close).
  • --expires-in 2m works then is refused, sessions and streams end, its handovers too: #1904, #1905 (handovers).
  • token create without --expires-in as today: #1904.

Open work in the same area: #1648 (iOS simulator jail, feature:spec) shares the goal of keeping a lease from the worker; no Depends on, since a handover already refuses exec. #1636 (upload once for many leases, feature:spec) touches the lease file routes the path gate passes; no Depends on, a new route under /v1/leases/{id} passes the gate as written. #412 (feature:spec, gateway reconciliation) reviews the adoption rules #1906 narrows; no Depends on.

Written by an agent.

主要语言
TypeScript
星标
730
派生
44
平均合并
16 小时 13 分钟
30 天内合并 PR
387

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

callstackincubator/simlock 的其他 Issue

查看 callstackincubator/simlock 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。