diff --git a/docs/internal/agent-rules/toolchain.md b/docs/internal/agent-rules/toolchain.md index 74cd1418a..51d46e589 100644 --- a/docs/internal/agent-rules/toolchain.md +++ b/docs/internal/agent-rules/toolchain.md @@ -176,6 +176,41 @@ hand on a machine with a simulator, where bytes it wrote into Annex-B and counts each tag, and `ffprobe out.264` says whether they decode. +## The simulator jail + +The same script builds `src/drivers/ios/jail/` (Swift, ours, no upstream) into +`dist/jail/`: `libsimlock-jail.dylib` for the iOS Simulator and `simlock-jail` +for the Mac, with `profile.sb` copied beside them. Each binary is compiled by +`swiftc` once per CPU (arm64 and x86_64) and joined by `lipo`; one that did not +build, or lost a slice, is left out with a warning, and the profile ships only +beside both. Nothing in the driver uses them yet: the three files are the +whole sandbox, and booting a simulator under it is done by hand. + +All of it rests on private Apple interfaces (`src/drivers/ios/jail/private.h`, +the profile language, the `SIMCTL_CHILD_` environment of `simctl boot`), so a +new macOS, Xcode or iOS runtime needs a check by hand: + +1. `simlock-jail compile profile.sb NAME=VALUE ...` with the values + `profile.sb` lists at its top, every path a real path. +2. `simctl boot` (never `bootstatus -b`, which drops the environment) with + `SIMCTL_CHILD_DYLD_INSERT_LIBRARIES` naming the library, + `SIMCTL_CHILD_SIMLOCK_JAIL_PROFILE` the compiled profile and + `SIMCTL_CHILD_SIMLOCK_JAIL_TOKEN` the same token the profile was given. +3. `simlock-jail check` with the pid of that simulator's `launchd_sim` and of + its children exits 0, Settings opens, and an app installed from a folder + inside the simulator's own folder cannot list the worker's home. + +That was done on macOS 26.6 with Xcode 27.2 and the iOS 27.2 runtime, on Apple +silicon, with an XCTest run and an agent-device session inside the jail. The +x86_64 library slice has not run in a simulator. The unit lane covers only +what the script does with the tools' results (`src/build-capture.test.ts`). + +What the jail changes for whoever boots under it: `simctl install`, +`addmedia` and Xcode's test-runner install read their source inside the +simulator, so it must be in a folder the profile allows; `simctl spawn` of a +program of the Mac's is refused; a loopback port is reachable only when it +was named at compile time. + ## Slow lane Tests that start real simulators or emulators. Run them only through diff --git a/scripts/build-capture.mjs b/scripts/build-capture.mjs index 2a5587168..9dfa4f774 100644 --- a/scripts/build-capture.mjs +++ b/scripts/build-capture.mjs @@ -5,13 +5,15 @@ // program of vendor/screen-capture/ is built with its own `swift build --product` and copied to // dist/bin/ — one failing does not skip the other, and the daemon reports the streams it lost. // Anywhere else the Swift build is skipped with a note, and the daemon reports iOS streams as -// unavailable. +// unavailable. On the same Mac the simulator jail of src/drivers/ios/jail/ is built too: its +// library for the iOS Simulator and its `simlock-jail` program for the Mac, into dist/jail/ beside +// the profile the program compiles. // Each artifact ships with its upstream's NOTICE.md and LICENSES/ in dist/vendor//, because the // package publishes dist/ and Apache-2.0 §4(a) asks that whoever gets a binary gets its license too. import { spawnSync } from "node:child_process"; import { createHash } from "node:crypto"; import { chmodSync, copyFileSync, cpSync, existsSync, mkdirSync, readFileSync } from "node:fs"; -import { dirname, join } from "node:path"; +import { basename, dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; const root = join(dirname(fileURLToPath(import.meta.url)), ".."); @@ -106,5 +108,76 @@ function buildIosCapture() { if (copied.length > 0) copyNotices("screen-capture"); } +// why: SwiftPM builds for the Mac only, and the jail library is loaded inside simulator processes, +// so each artifact is compiled by `swiftc` against the SDK it runs on, one slice per CPU, and +// `lipo` joins the slices. Both CPUs, because an Intel Mac is a worker too and its simulators +// run x86_64 code. +function buildUniversalSwift({ output, what, sdk, triple, source, flags }) { + const jail = join(root, "src/drivers/ios/jail"); + const scratch = join(root, "node_modules/.cache/simlock-jail"); + const slices = []; + for (const arch of ["arm64", "x86_64"]) { + const slice = join(scratch, arch, basename(output)); + mkdirSync(dirname(slice), { recursive: true }); + const args = [ + "--sdk", + sdk, + "swiftc", + "-O", + "-module-name", + "SimlockJail", + "-target", + triple(arch), + ]; + args.push("-import-objc-header", join(jail, "private.h"), ...flags, join(jail, source)); + const compiled = spawnSync("xcrun", [...args, "-o", slice], { stdio: "inherit" }); + if (compiled.status === 0) slices.push(slice); + } + mkdirSync(dirname(output), { recursive: true }); + const joined = + slices.length === 2 && + spawnSync("xcrun", ["lipo", "-create", ...slices, "-output", output], { stdio: "inherit" }) + .status === 0; + if (!joined) { + console.warn( + `build-capture: could not build ${basename(output)} (is Xcode installed and selected?); ${what} will be unavailable`, + ); + return false; + } + chmodSync(output, 0o755); + return true; +} + +function buildSimulatorJail() { + if (process.platform !== "darwin") { + console.log("build-capture: not macOS, skipping the simulator jail"); + return; + } + // why: iOS 16 is the oldest runtime the iOS driver leases, and macOS 14 the oldest Mac the + // capture programs run on. + const library = buildUniversalSwift({ + output: join(dist, "jail/libsimlock-jail.dylib"), + what: "the simulator jail", + sdk: "iphonesimulator", + triple: (arch) => `${arch}-apple-ios16.0-simulator`, + source: "Jail.swift", + flags: ["-parse-as-library", "-emit-library"], + }); + const program = buildUniversalSwift({ + output: join(dist, "jail/simlock-jail"), + what: "the simulator jail's profile compiler", + sdk: "macosx", + triple: (arch) => `${arch}-apple-macos14.0`, + source: "main.swift", + flags: ["-lsandbox"], + }); + // why: the profile is compiled per simulator on the worker, so it ships as text; it is of no + // use without both of the others. + if (library && program) { + copyFileSync(join(root, "src/drivers/ios/jail/profile.sb"), join(dist, "jail/profile.sb")); + } +} + copyScrcpyServer(); buildIosCapture(); +buildSimulatorJail(); diff --git a/src/build-capture.test.ts b/src/build-capture.test.ts index 4d9ffcdf7..0e79cba71 100644 --- a/src/build-capture.test.ts +++ b/src/build-capture.test.ts @@ -8,6 +8,7 @@ import { mkdtempSync, readFileSync, rmSync, + statSync, writeFileSync, } from "node:fs"; import { tmpdir } from "node:os"; @@ -30,6 +31,8 @@ function scratchRepo(server: string, digest: string): string { mkdirSync(join(root, "scripts")); mkdirSync(join(root, "vendor", "scrcpy"), { recursive: true }); cpSync(SCRIPT, join(root, "scripts", "build-capture.mjs")); + mkdirSync(join(root, "src", "drivers", "ios", "jail"), { recursive: true }); + writeFileSync(join(root, "src", "drivers", "ios", "jail", "profile.sb"), "the jail's profile"); writeFileSync(join(root, "vendor", "scrcpy", "scrcpy-server-v5.0.1"), server); writeFileSync( join(root, "vendor", "scrcpy", "SHA256SUMS.txt"), @@ -85,6 +88,40 @@ function fakeSwift(repo: string): string { return bin; } +// why: an `xcrun` that writes what `swiftc` and `lipo` would, so the claim about the slices is +// checked without Xcode: a slice holds its target and SDK, and `lipo` joins the slices it is given. +// It fails the outputs and the targets named in SIMLOCK_FAKE_XCRUN_FAIL, so a test can lose one +// artifact or one slice. +function fakeXcrun(repo: string): string { + const bin = join(repo, "fake-xcrun"); + mkdirSync(bin, { recursive: true }); + writeFileSync( + join(bin, "xcrun"), + [ + "#!/bin/sh", + 'sdk=""; target=""; out=""; tool=""; slices=""', + 'while [ "$#" -gt 0 ]; do', + ' case "$1" in', + ' --sdk) shift; sdk="$1" ;;', + ' -target) shift; target="$1" ;;', + ' -o|-output) shift; out="$1" ;;', + ' swiftc|lipo) tool="$1" ;;', + ' */arm64/*|*/x86_64/*) slices="$slices $1" ;;', + " esac", + " shift", + "done", + 'name="$(/usr/bin/basename "$out")"', + 'case ",$SIMLOCK_FAKE_XCRUN_FAIL," in *",$name,"*) exit 1 ;; esac', + 'if [ -n "$target" ]; then', + ' case ",$SIMLOCK_FAKE_XCRUN_FAIL," in *",$target,"*) exit 1 ;; esac', + "fi", + 'if [ "$tool" = swiftc ]; then echo "$target on $sdk" > "$out"; else /bin/cat $slices > "$out"; fi', + ].join("\n"), + ); + chmodSync(join(bin, "xcrun"), 0o755); + return bin; +} + function sha256(text: string): string { return createHash("sha256").update(text).digest("hex"); } @@ -165,4 +202,51 @@ describe("scripts/build-capture.mjs", () => { expect(existsSync(join(shipped, "NOTICE.md"))).toBe(true); }, ); + + it.skipIf(process.platform !== "darwin")( + "builds the simulator jail's library for the iOS Simulator and its `simlock-jail` program for the Mac, each from an arm64 and an x86_64 slice, ships the profile only beside both, and ships neither a lone slice nor a program that did not build", + () => { + const repo = scratchRepo("the real server", sha256("the real server")); + const run = (path: string, fail = "") => + spawnSync(process.execPath, [join(repo, "scripts", "build-capture.mjs")], { + encoding: "utf8", + env: { ...process.env, PATH: path, SIMLOCK_FAKE_XCRUN_FAIL: fail }, + }); + const library = join(repo, "dist", "jail", "libsimlock-jail.dylib"); + const compiler = join(repo, "dist", "jail", "simlock-jail"); + const profile = join(repo, "dist", "jail", "profile.sb"); + + run(""); + expect(existsSync(library)).toBe(false); + expect(existsSync(compiler)).toBe(false); + expect(existsSync(profile)).toBe(false); + + run(fakeXcrun(repo)); + expect(readFileSync(library, "utf8")).toBe( + "arm64-apple-ios16.0-simulator on iphonesimulator\nx86_64-apple-ios16.0-simulator on iphonesimulator\n", + ); + expect(readFileSync(compiler, "utf8")).toBe( + "arm64-apple-macos14.0 on macosx\nx86_64-apple-macos14.0 on macosx\n", + ); + expect(statSync(compiler).mode & 0o777).toBe(0o755); + expect(readFileSync(profile, "utf8")).toBe("the jail's profile"); + + rmSync(join(repo, "dist"), { force: true, recursive: true }); + const libraryFailed = run(fakeXcrun(repo), "libsimlock-jail.dylib"); + expect(existsSync(library)).toBe(false); + expect(existsSync(compiler)).toBe(true); + expect(existsSync(profile)).toBe(false); + expect(libraryFailed.stdout + libraryFailed.stderr).toMatch( + /the simulator jail will be unavailable/iu, + ); + + rmSync(join(repo, "dist"), { force: true, recursive: true }); + const intelSliceFailed = run(fakeXcrun(repo), "x86_64-apple-macos14.0"); + expect(existsSync(library)).toBe(true); + expect(existsSync(compiler)).toBe(false); + expect(intelSliceFailed.stdout + intelSliceFailed.stderr).toMatch( + /the simulator jail's profile compiler will be unavailable/iu, + ); + }, + ); }); diff --git a/src/drivers/ios/jail/Jail.swift b/src/drivers/ios/jail/Jail.swift new file mode 100644 index 000000000..0dc033bf3 --- /dev/null +++ b/src/drivers/ios/jail/Jail.swift @@ -0,0 +1,63 @@ +// why: this library is loaded into `launchd_sim` (DYLD_INSERT_LIBRARIES on `simctl boot`) and, with +// the environment `launchd_sim` passes on, into every process of that simulator. Nothing in the +// driver boots a simulator with it yet. +import Darwin + +// why: a stock simulator has no sandbox, so there every advisory check answers "allowed" and "is +// this process sandboxed?" answers no. iOS daemons ask before they talk to each other (SpringBoard +// stops when a lookup check says no) and `log` refuses to run sandboxed, so they get the stock +// answer. Only honest processes are helped: the kernel and the host's launchd still refuse. +@_cdecl("simlock_jail_allowed") func jailAllowed() -> Int32 { 0 } + +// why: `launchd_sim` makes its socket folders in /private/var/tmp, which every simulator of the +// worker shares. A per-simulator token in the name lets a profile allow this simulator's folders +// and no other's. The name keeps its length, because the caller owns the buffer. +@_cdecl("simlock_jail_mkdtemp") +func jailMkdtemp(_ template: UnsafeMutablePointer?) -> UnsafeMutablePointer? { + let prefix = "/private/var/tmp/com.apple.launchd." + let length = prefix.utf8.count + if let template, let token = getenv("SIMLOCK_JAIL_TOKEN"), strlen(token) == 6, + strncmp(template, prefix, length) == 0, strcmp(template + length, "XXXXXXXXXX") == 0 + { + memcpy(template + length, token, 6) + } + return mkdtemp(template) +} + +typealias Check = @convention(c) () -> Int32 +typealias SelfCheck = @convention(c) (pid_t, UnsafePointer?, Int32) -> Int32 +typealias MakeTemp = @convention(c) (UnsafeMutablePointer?) -> UnsafeMutablePointer? + +// why: dyld reads this section as (replacement, original) pairs and redirects every other image's +// calls; calls made from this library still reach the original. +@used @section("__DATA,__interpose") +let interposeCheck: (Check, SelfCheck) = (jailAllowed, sandbox_check) +@used @section("__DATA,__interpose") +let interposeCheckByToken: (Check, Check) = (jailAllowed, sandbox_check_by_audit_token) +@used @section("__DATA,__interpose") +let interposeCheckById: (Check, Check) = (jailAllowed, sandbox_check_by_uniqueid) +@used @section("__DATA,__interpose") +let interposeMakeTemp: (MakeTemp, MakeTemp) = (jailMkdtemp, mkdtemp) + +// why: dyld runs this before the process's own code. `launchd_sim` is not sandboxed yet, so it +// applies the compiled profile there; the kernel gives the same sandbox to every child, which is +// why a process that is already sandboxed does nothing. A simulator that cannot be jailed must not +// run, so every failure ends the process. +@used @section("__DATA,__mod_init_func") +let enterJail: @convention(c) () -> Void = { + guard let path = getenv("SIMLOCK_JAIL_PROFILE") else { return } + if sandbox_check(getpid(), nil, 0) == 1 { return } + let file = open(path, O_RDONLY) + guard file >= 0 else { _exit(78) } + var bytes = [UInt8](repeating: 0, count: 1 << 20) + let count = read(file, &bytes, bytes.count) + close(file) + guard count > 0 else { _exit(78) } + let applied = bytes.withUnsafeBufferPointer { buffer in + var profile = simlock_jail_profile( + data: buffer.baseAddress, size: count, container: nil, container_len: 0) + return __sandbox_ms("Sandbox", 0, &profile) + } + guard applied == 0 else { _exit(78) } + _sandbox_enter_notify_libxpc() +} diff --git a/src/drivers/ios/jail/main.swift b/src/drivers/ios/jail/main.swift new file mode 100644 index 000000000..788815375 --- /dev/null +++ b/src/drivers/ios/jail/main.swift @@ -0,0 +1,66 @@ +// why: the host half of the simulator jail, `simlock-jail`: +// compile [NAME=VALUE ...] a simulator runtime carries no profile +// compiler, so the profile is compiled on the Mac and the jail library applies the bytes +// check [ ...] exits 0 only when every process is sandboxed, so whoever booted a +// simulator can refuse one whose jail did not take +import Darwin + +func fail(_ code: Int32, _ message: String) -> Never { + fputs("simlock-jail: \(message)\n", stderr) + exit(code) +} + +func compile(_ arguments: [String]) { + guard arguments.count >= 2 else { usage() } + // why: libsandbox looks a relative name up among its built-in profiles, not in the working folder. + guard let source = realpath(arguments[0], nil) else { fail(66, "cannot read \(arguments[0])") } + guard let parameters = sandbox_create_params() else { fail(70, "cannot create parameters") } + for pair in arguments.dropFirst(2) { + guard let equals = pair.firstIndex(of: "="), equals != pair.startIndex else { + fail(64, "\(pair) is not NAME=VALUE") + } + let name = String(pair[..? + guard let profile = sandbox_compile_file(source, parameters, &message) else { + fail(65, message.map { String(cString: $0) } ?? "unknown error") + } + guard let output = fopen(arguments[1], "wb") else { fail(73, "cannot write \(arguments[1])") } + let written = fwrite(profile.pointee.data, 1, profile.pointee.size, output) + guard fclose(output) == 0, written == profile.pointee.size else { + fail(73, "cannot write \(arguments[1])") + } +} + +func check(_ arguments: [String]) { + guard !arguments.isEmpty else { usage() } + var free: [String] = [] + for argument in arguments { + guard let pid = pid_t(argument), pid > 0 else { fail(64, "\(argument) is not a process id") } + if sandbox_check(pid, nil, 0) != 1 { free.append(argument) } + } + if !free.isEmpty { fail(1, "not sandboxed: \(free.joined(separator: " "))") } +} + +func usage() -> Never { + fputs( + """ + usage: simlock-jail compile [NAME=VALUE ...] + simlock-jail check [ ...] + + """, stderr) + exit(64) +} + +let arguments = Array(CommandLine.arguments.dropFirst()) +switch arguments.first { +case "compile": compile(Array(arguments.dropFirst())) +case "check": check(Array(arguments.dropFirst())) +default: usage() +} diff --git a/src/drivers/ios/jail/private.h b/src/drivers/ios/jail/private.h new file mode 100644 index 000000000..b5dc844fd --- /dev/null +++ b/src/drivers/ios/jail/private.h @@ -0,0 +1,35 @@ +// why: Swift reaches C through a header, and none of these is in an SDK header: they are private +// libsystem and libsandbox interfaces, so a macOS or Xcode release can change them. +#include +#include + +// why: the real function is variadic, which Swift cannot call; the jail only asks "is this process +// sandboxed?", the form that takes no further argument. The library asks it of itself, and +// `simlock-jail check` of the simulator's processes. +int sandbox_check(pid_t pid, const char *operation, int type); +// why: only their addresses are used, as interposing targets, so the arguments are left out. +int sandbox_check_by_audit_token(void); +int sandbox_check_by_uniqueid(void); + +// why: the layout the "Sandbox" policy's call 0 reads; found by disassembling macOS 26.6's +// sandbox_apply_container, since nothing documents it. +struct simlock_jail_profile { + const unsigned char *data; + size_t size; + char *container; + size_t container_len; +}; +int __sandbox_ms(const char *policy, int call, void *arg); +void _sandbox_enter_notify_libxpc(void); + +// why: libsandbox's own result type; `simlock-jail compile` reads `data` and `size` only. The +// parameters are what a profile reads with `(param "NAME")`. +struct sandbox_profile { + char *builtin; + unsigned char *data; + size_t size; +}; +typedef struct sandbox_params sandbox_params_t; +sandbox_params_t *sandbox_create_params(void); +int sandbox_set_param(sandbox_params_t *params, const char *name, const char *value); +struct sandbox_profile *sandbox_compile_file(const char *path, sandbox_params_t *params, char **error); diff --git a/src/drivers/ios/jail/profile.sb b/src/drivers/ios/jail/profile.sb new file mode 100644 index 000000000..db4fc44fb --- /dev/null +++ b/src/drivers/ios/jail/profile.sb @@ -0,0 +1,136 @@ +;; why: the rules one jailed iOS simulator runs under. Everything is refused unless a rule below +;; allows it, so a simulator reaches its own folders, the iOS runtime and the internet, and neither +;; the worker's files nor another simulator. `simlock-jail compile` turns this file into the bytes +;; the jail library applies, and takes the values as NAME=VALUE: +;; +;; UDID the simulator's UDID +;; TOKEN the six characters the library puts in this simulator's socket folders +;; DEVICE the simulator's own folder in its device set +;; RUNTIME the runtime root of its iOS runtime +;; LIBRARY the jail library itself, which every process of the simulator loads +;; HOME the home folder of the user the worker runs as +;; XCODE the selected Xcode's Contents folder +;; PORT optional: one port on the worker's loopback the simulator may connect to +;; +;; why: every path is the real one (/private/var, never /var): the kernel compares what a symlink +;; points at. A value that is missing stops the compile, so a simulator never boots under a +;; profile with a hole where a path should be. +(version 1) +(deny default) + +(define (value name) (or (param name) (error (string-append name " is not set")))) +(define (in name suffix) (string-append (value name) suffix)) +(define logs (in "HOME" (string-append "/Library/Logs/CoreSimulator/" (value "UDID")))) +(define launchd-state (string-append "/private/var/tmp/com.apple.CoreSimulator.SimDevice." (value "UDID"))) +;; why: `launchd_sim` makes its socket folders in a folder all simulators share; the library +;; starts their names with TOKEN, which is what lets one simulator's be told from another's. +(define (socket-folders tail) + (regex (string-append "^/private/var/tmp/com\\.apple\\.launchd\\." (regex-quote (value "TOKEN")) "[^/]+" tail))) + +;; ---------- processes: only this simulator's own tree +(allow process-fork) +(allow process-exec* + (subpath (value "RUNTIME")) + (subpath (value "DEVICE")) + (subpath "/Library/Developer/PrivateFrameworks/CoreSimulator.framework") + ;; why: agent-device starts this helper of the worker's inside the simulator. + (subpath (in "HOME" "/.agent-device/snapshot-source"))) +(allow signal (target same-sandbox)) +(allow process-info* (target self)) +(allow process-info* (target same-sandbox)) +(allow system-sched (target same-sandbox)) +(allow process-codesigning process-iopolicy* mach-task-name mach-task-exception-port-set + system-suspend-resume system-memorystatus-control) + +;; ---------- host services: none +;; why: there is no mach-lookup rule on purpose. CoreSimulator hands every simulator the host's +;; bootstrap port, and with no rule the host's launchd refuses each lookup made through it. +;; Lookups inside the simulator go to `launchd_sim`, which does not ask the sandbox. + +;; ---------- what the runtime needs from the kernel (seen in a census of a booting simulator) +(allow sysctl-read) +(allow syscall-unix syscall-mach syscall-mig system-fcntl system-mac-syscall sandbox-check) +(allow ipc-posix-shm* ipc-posix-sem*) +(allow iokit-open-user-client (iokit-user-client-class "RootDomainUserClient")) +(allow iokit-get-properties) +(allow system-socket system-fsctl socket-ioctl) +;; why: iOS daemons hand sandbox extensions to each other, and no rule here can be widened by one. +(allow file-issue-extension mach-issue-extension generic-issue-extension iokit-issue-extension + consume-extension) + +;; ---------- network: the internet, the leased loopback port, and unix sockets by list +(allow network-outbound) +(deny network-outbound (subpath "/")) +(allow network-outbound + (literal "/private/var/run/mDNSResponder") + (literal "/private/var/run/syslog") + (literal "/private/var/run/.sim_diagnosticd_socket") + (subpath (value "DEVICE")) + (subpath launchd-state)) +;; why: the loopback rules stay last among the outbound rules: a path rule written after them +;; cancels the port's exception. The sandbox counts the worker's own LAN address as loopback too. +(deny network-outbound (remote ip "localhost:*")) +(if (param "PORT") + (allow network-outbound (remote tcp (string-append "localhost:" (param "PORT"))))) +(allow network-bind network-inbound (local ip "*:*")) +(allow network-bind network-inbound + (subpath (value "DEVICE")) + (subpath launchd-state) + (socket-folders "/")) + +;; ---------- files, read-only: the iOS runtime and the parts of the host it is built on +(allow file-read* file-map-executable file-test-existence file-lock + (subpath (value "RUNTIME")) + (subpath "/System/Library") + (subpath "/System/iOSSupport") + (subpath "/System/Cryptexes") + (subpath "/System/Volumes/Preboot/Cryptexes") + (subpath "/usr/lib") + (subpath "/usr/share") + (subpath "/Library/Developer/CoreSimulator") + (subpath "/Library/Developer/PrivateFrameworks/CoreSimulator.framework") + (subpath "/private/var/db/timezone") + (literal "/private/etc/passwd") + (literal "/private/etc/group") + (literal "/private/etc/localtime") + (literal "/Library/Preferences/com.apple.networkd.plist") + (literal "/dev/null") (literal "/dev/zero") (literal "/dev/random") (literal "/dev/urandom") + (literal "/dev/dtracehelper") + (literal (value "LIBRARY"))) +;; why: what the worker shares with every lease and holds no lease's data: agent-device's test +;; runner and helper, and the parts of Xcode a test run loads into the simulator. +(allow file-read* file-map-executable file-test-existence file-lock + (subpath (in "HOME" "/.agent-device/apple-runner/derived")) + (subpath (in "HOME" "/.agent-device/snapshot-source")) + (subpath (in "XCODE" "/Developer/Platforms/iPhoneSimulator.platform")) + (subpath (in "XCODE" "/Developer/Platforms/iPhoneOS.platform")) + (subpath (in "XCODE" "/SharedFrameworks"))) +(allow file-read-data (literal "/")) +;; why: a path is walked name by name, so the names on the way to an allowed folder can be seen; +;; nothing beside or below them can. +(allow file-read-metadata file-test-existence + (literal "/") (literal "/private") (literal "/private/var") (literal "/private/var/run") + (literal "/private/var/db") (literal "/private/var/tmp") (literal "/private/etc") + (literal "/private/tmp") (literal "/etc") (literal "/var") (literal "/tmp") (literal "/dev") + (literal "/usr") (literal "/System") (literal "/System/Volumes") (literal "/System/Volumes/Data") + (literal "/System/Volumes/Preboot") (literal "/Library") (literal "/Library/Preferences") + (literal "/Library/Developer") (literal "/Library/Developer/PrivateFrameworks") + (path-ancestors (value "RUNTIME")) + (path-ancestors (value "DEVICE")) + (path-ancestors (value "LIBRARY")) + (path-ancestors logs) + (path-ancestors (in "HOME" "/.agent-device/apple-runner/derived")) + (path-ancestors (in "XCODE" "/Developer/Platforms/iPhoneSimulator.platform"))) + +;; ---------- files, read-write: this simulator only +(allow file-read* file-write* file-map-executable file-ioctl file-test-existence file-lock + file-clone file-link + (subpath (value "DEVICE")) + (subpath logs) + (subpath launchd-state) + (socket-folders "(/|$)")) +(allow file-write-data file-ioctl + (literal "/dev/null") (literal "/dev/zero") (literal "/dev/dtracehelper")) +;; why: Xcode and `simctl launch --console-pty` attach an app to a pseudo-terminal whose name is +;; not known before the boot, so every one of the worker's user can be opened. +(allow file-read* file-write-data file-ioctl (regex #"^/dev/ttys[0-9]+$")) diff --git a/turbo.json b/turbo.json index 28bdc8ccf..f964e1d48 100644 --- a/turbo.json +++ b/turbo.json @@ -14,7 +14,14 @@ "package.json", "pnpm-lock.yaml" ], - "outputs": ["dist/**", "!dist/ui/**", "!dist/vendor/**", "!dist/bin/**", "!dist/e2e/**"], + "outputs": [ + "dist/**", + "!dist/ui/**", + "!dist/vendor/**", + "!dist/bin/**", + "!dist/jail/**", + "!dist/e2e/**" + ], "outputLogs": "new-only" }, "//#build:ui:run": { @@ -33,8 +40,13 @@ "outputLogs": "new-only" }, "//#build:capture:run": { - "inputs": ["vendor/**", "!vendor/screen-capture/.build/**", "scripts/build-capture.mjs"], - "outputs": ["dist/vendor/**", "dist/bin/**"], + "inputs": [ + "vendor/**", + "!vendor/screen-capture/.build/**", + "src/drivers/ios/jail/**", + "scripts/build-capture.mjs" + ], + "outputs": ["dist/vendor/**", "dist/bin/**", "dist/jail/**"], "env": ["DEVELOPER_DIR"], "outputLogs": "new-only" },