iOS sandbox: a reverse tunnel opens its port to the lease's own simulator while it runs
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- ios, swift, typescript
- 领域
- mobile-dev, networking, security
调研方向
Read ADR 0103 sections 3a and 6, then trace the named entry points in drivers/ios/device-tcp.ts, drivers/ios/jail-grants.ts, and drivers/ios/jail/main.swift. Start with the listed B9 and B10 unit test seams, then cover the recovery and real simulator cases in e2e/slow-ios-sandbox.test.ts. Done means the specified behavior cases pass, the protocol version bump check passes, and the slow lane verifies grant, release, isolation, and reboot behavior.
由索引模型根据 Issue 内容生成。
描述
Part of #1648.
Scope
On a sandboxed worker a lease's reverse on a listed port opens that port to its own simulator while the simulator runs, with no reboot, and closes it again; other ports are refused with TUNNEL_PORT_NOT_ALLOWED. A tunnel connection is handed on only from the lease's own simulator, forward tunnels included. Grants come back after a recovery boot or a boot simlock did not make; a daemon start releases the port grants a crash left, so a lease reopens its reverse after a restart. An app cannot kill its simulator's launchd_sim, and after launchctl reboot agent-device boots it sandboxed.
If it goes wrong, Metro on a sandboxed worker cannot reach its dev server, or one lease reaches another lease's tunnel.
Technical spec
Commit b037ae2a0.
Rows
- Behaviours: B9, B10, B11, B16, B17
- Interfaces: I16, I9, I10, I12, I13
- Existing code: X4, X12, X13, X14, X20, X21, X22
Facts
none
Modules touched
drivers/ios (device-tcp.ts, index.ts, new jail-grants.ts, jail/main.swift issue, jail/Jail.swift grants watcher), ports (tcp-stream.ts, tcp-listener.ts, their Node adapters and fakes, filesystem.ts readSmallRegularFile), contract (errors.ts, protocol.ts), core (src/core/device-tcp.ts:7 DeviceTcpError code union gains TUNNEL_PORT_NOT_ALLOWED; src/tunnel/sessions.ts:457 passes it on), drivers/ios index.ts (IosSimctlDriver hands the grants writer to device-tcp.ts), src/drivers/ios/AGENTS.md (the tunnel rule on SIMULATOR_UDID), website (reference/errors.mdx, the tunnels page), e2e/slow-ios-sandbox.test.ts. Searches: rg "TUNNEL_PORT_IN_USE|holdsUdid|onConnection|TcpStream" src.
Rules in play
- ADR 0103 (Accepted — not yet implemented): the sections named on each line below; the feature's rows hold the shapes.
- ADR 0103 §3a, §6: tokens issued only by the worker with
simlock-jail, bound to the rootlaunchd_sim; self-issue denied; peer check by the process tree. - ADR 0064: a tunnel reaches simulator ports; the sandboxed check narrows who may listen.
- Contract: a new error code bumps
DAEMON_PROTOCOL_VERSIONby one in this PR. - Documentation rule 9:
errors.mdxand the tunnels page.
Tests
Seams: src/drivers/ios/device-tcp.test.ts:100 setup with scripted lsof and ps and a fake TcpStream with a peer; createDriver with a scripted grants file; the slow-lane file T2 adds.
- B9: On a sandboxed worker
reverse <port>on a listed port hassimlock-jail issue generic(I16) make a token bound to the rootlaunchd_sim, appends agrantline, waits for the acknowledgement, then opens;closeappends therelease; an unlisted port is refusedTUNNEL_PORT_NOT_ALLOWEDbefore anything listens; no acknowledgement within 2 s, or an acknowledgement file that is not a small regular file, closes the listeners and answersTUNNEL_FAILED: listed port; unlisted port; empty list; acknowledgement late; acknowledgement file a pipe or a link (read refused,TUNNEL_FAILED, no hang); port in use (TUNNEL_PORT_IN_USEfirst); close;issuefails; without the sandbox: no grant - B10: On a sandboxed worker a connection to a
reverselistener is handed on only when the process that opened it (found by its local port) descends from the lease's rootlaunchd_sim; a forward tunnel connects only to a listener whose process descends from it; otherwise the connection is closed: app of the lease; app of another simulator; worker process; peer exited beforelsof;lsoffails; process with a forgedSIMULATOR_UDID; a decoylaunchd_simof another simulator naming this lease's folder (not the root, refused); forward listener of another simulator with the lease'sSIMULATOR_UDID; without the sandbox: as today - B11: Inside a sandboxed simulator the jail library in the root
launchd_simconsumes each newgrantline of its grants file and releases on eachreleaseline, writing the last line's number to the acknowledgement file; a process of the simulator cannot issue acom.simlock.grant itself, cannot use a token it read from the grants file, cannot signal the rootlaunchd_simor start another one, and consumes every line whatever its result, so an old line's failed consume stops nothing: grant opens the port for a running app; release closes it; generic self-issue refused; file self-issue refused; a token read from the grants file and consumed by an app does nothing; an app's SIGKILL, SIGTERM and SIGSTOP of the rootlaunchd_simrefused; an app'skill(-1, SIGKILL)leaves the rootlaunchd_simrunning; an app's exec oflaunchd_simrefused; an ad-hoc signed program namedcom.apple.xpc.launchdstays killable; an app'slaunchctl rebootshuts the simulator down and agent-device's next command boots it sandboxed (B18, B17); a token line bound to an olderlaunchd_simis skipped - B16: At startup on a sandboxed worker, the iOS driver appends a
releaseline for every port grant left in a leased simulator's grants file, and numbers new lines after the file's last one; after a recovery boot it issues the grant of eachreversetunnel of that lease still open: two port grants left: two releases; none left; recovery with one openreverse: one new grant - B17: On a sandboxed worker, when
listManagedfinds a leased simulator's rootlaunchd_simwith another pid than the one its last driver boot recorded and the check passes, the driver records the new pid in place of the old (X4) and issues again the grants of that lease's openreversetunnels, as after a recovery boot (B16); the lease-folder grant follows the new pid by itself (B12); found at the health monitor's next tick (src/leasing/lease-health-monitor.ts:113, everyhealth.probeIntervalMs): same pid: nothing; new pid, check passes, one openreverse: one grant bound to the new pid; the next tick with the same new pid: nothing; new pid, check fails: B15; new pid, no open tunnel: no line
Done when
- Every unit case of B9, B10, B16, B17 passes.
.agents/scripts/protocol-bump-check.mjspasses with the bump.- Slow lane (real simulator):
e2e/slow-ios-sandbox.test.tsruns B11's cases: a grant opens a port for a running app and a release closes it, self-issued and copied tokens do nothing, the kill routes are refused, and after an app'slaunchctl rebootagent-device's next command boots the simulator sandboxed.
Out of scope
The lease-folder grant (T5).
Depends on
- #2043 because: the profile's port pairs and the root lookup (I2, X14)
- #1153 because: both bump
DAEMON_PROTOCOL_VERSION(src/contract/protocol.ts) - #1154 because: both bump
DAEMON_PROTOCOL_VERSION(src/contract/protocol.ts) - #1155 because: both bump
DAEMON_PROTOCOL_VERSION(src/contract/protocol.ts) - #1904 because: both bump
DAEMON_PROTOCOL_VERSION(src/contract/protocol.ts) - #1905 because: both bump
DAEMON_PROTOCOL_VERSION(src/contract/protocol.ts) - #1907 because: both bump
DAEMON_PROTOCOL_VERSION(src/contract/protocol.ts) - #2005 because: both bump
DAEMON_PROTOCOL_VERSION(src/contract/protocol.ts) - #2006 because: both bump
DAEMON_PROTOCOL_VERSION(src/contract/protocol.ts)
Written by an agent.
- 主要语言
- TypeScript
- 星标
- 730
- 派生
- 44
- 平均合并
- 15 小时 28 分钟
- 30 天内合并 PR
- 387
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
callstackincubator/simlock 的其他 Issue
-
bug:new
难度 2/5 1-3 小时 新手友好度 73/100
callstackincubator/simlock#2088 ·
维护者通常 1 天内回复
-
bug:new
难度 2/5 1-3 小时 新手友好度 64/100
callstackincubator/simlock#2080 · 1 条评论 ·
维护者通常 1 天内回复
-
task:ready
难度 4/5 3-5 天 新手友好度 52/100
callstackincubator/simlock#2079 ·
维护者通常 1 天内回复
-
platform:ios task:ready
难度 5/5 一周以上 新手友好度 18/100
callstackincubator/simlock#2078 ·
维护者通常 1 天内回复
-
iOS copy: keep the app database at the copy's own UDID可能已有人在做 @V3RON 今天认领。 未关闭platform:ios task:ready
callstackincubator/simlock#2077 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 callstackincubator/simlock 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
melgarafael/DeskcommCRM#5614 · 1 条评论 ·
维护者通常 1 天内回复
-
documentation
难度 1/5 1 小时以内 新手友好度 76/100
slackapi/slack-health-score#253 ·
维护者通常 1 天内回复
-
feature needs triage site
难度 2/5 1-3 小时 新手友好度 64/100
owid/owid-grapher#8019 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
simstudioai/sim#10710 ·
维护者通常 1 天内回复
-
via-triage
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复