iOS sandbox: a reverse tunnel opens its port to the lease's own simulator while it runs

Đang mở
#2,045 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
ios, swift, typescript

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

task:ready

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 root launchd_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_VERSION by one in this PR.
  • Documentation rule 9: errors.mdx and 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 has simlock-jail issue generic (I16) make a token bound to the root launchd_sim, appends a grant line, waits for the acknowledgement, then opens; close appends the release; an unlisted port is refused TUNNEL_PORT_NOT_ALLOWED before anything listens; no acknowledgement within 2 s, or an acknowledgement file that is not a small regular file, closes the listeners and answers TUNNEL_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_USE first); close; issue fails; without the sandbox: no grant
  • B10: On a sandboxed worker a connection to a reverse listener is handed on only when the process that opened it (found by its local port) descends from the lease's root launchd_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 before lsof; lsof fails; process with a forged SIMULATOR_UDID; a decoy launchd_sim of another simulator naming this lease's folder (not the root, refused); forward listener of another simulator with the lease's SIMULATOR_UDID; without the sandbox: as today
  • B11: Inside a sandboxed simulator the jail library in the root launchd_sim consumes each new grant line of its grants file and releases on each release line, writing the last line's number to the acknowledgement file; a process of the simulator cannot issue a com.simlock. grant itself, cannot use a token it read from the grants file, cannot signal the root launchd_sim or 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 root launchd_sim refused; an app's kill(-1, SIGKILL) leaves the root launchd_sim running; an app's exec of launchd_sim refused; an ad-hoc signed program named com.apple.xpc.launchd stays killable; an app's launchctl reboot shuts the simulator down and agent-device's next command boots it sandboxed (B18, B17); a token line bound to an older launchd_sim is skipped
  • B16: At startup on a sandboxed worker, the iOS driver appends a release line 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 each reverse tunnel of that lease still open: two port grants left: two releases; none left; recovery with one open reverse: one new grant
  • B17: On a sandboxed worker, when listManaged finds a leased simulator's root launchd_sim with 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 open reverse tunnels, 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, every health.probeIntervalMs): same pid: nothing; new pid, check passes, one open reverse: 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.mjs passes with the bump.
  • Slow lane (real simulator): e2e/slow-ios-sandbox.test.ts runs 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's launchctl reboot agent-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.

Ngôn ngữ chính
TypeScript
Star
730
Fork
44
Merge trung bình
15 giờ 28 phút
Pull request đã merge (30 ngày)
387

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của callstackincubator/simlock

Tất cả issue của callstackincubator/simlock

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.