Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/_build-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ jobs:
[ "$rc" -eq 0 ] || exit "$rc"

# Spec 31 §5/§8.4: sign (Developer ID Application, hardened
# runtime, the ci/runtime.entitlements pair) + notarize the macOS
# runtime, the ci/runtime.entitlements set) + notarize the macOS
# runtime exe IN-LEG, before the symbol-provenance check and the
# boot smoke — every downstream gate, and the publish stage's
# .sha256 sidecar, anchors the exact SIGNED bytes (sign-then-hash
Expand All @@ -426,8 +426,10 @@ jobs:
# armed + a missing secret is a fast named failure). The exe is
# left quarantine-marked: the boot smoke — the jit_llvm legs
# exercise CPython's JIT — then runs under Gatekeeper's exact
# download path, proving the allow-jit/disable-library-validation
# pair on the signed exe.
# download path, proving the entitlement set on the signed exe
# (the enumeration lives in ci/runtime.entitlements, asserted
# by key name in ci/macos-sign-notarize-runtime.sh — never
# re-spelled here).
- name: Sign + notarize the runtime exe (macos, spec 31)
if: matrix.os == 'macos'
shell: bash
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ incarnations:
child skips the boot and runs the interpreter, whose libc IO the shim
now serves from the VFS.

The macOS entitlement plane of that re-exec (tebako#1117): the
hardened runtime strips `DYLD_INSERT_LIBRARIES` at launch unless the
exe carries `com.apple.security.cs.allow-dyld-environment-variables`
— so `ci/runtime.entitlements` carries it, and
`ci/macos-sign-notarize-runtime.sh` asserts it embedded by key name
(no runner can police the class at exec time: macOS 15's dyld
tolerates the omission; macOS 14 strips — the tebako-runtime-r#5
class, whose python symptom is `No module named 'encodings'`). The
mechanism determination, and why the omission never fired while every
published python runtime shipped unsigned, is recorded in
`docs/build-chain.md`.

`PYTHONHOME` is set env-first — `TEBAKO_MOUNT_ROOT` when set-and-
nonempty, else `tebako_mount_point()` (the ruby factory's era-2 rbconfig
pattern: the driver's ffi mount point is fixed before the windows
Expand Down
26 changes: 20 additions & 6 deletions ci/macos-sign-notarize-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

# ci/macos-sign-notarize-runtime.sh — spec 31 §5/§8.4: sign the freshly
# built macOS runtime exe (Developer ID Application, hardened runtime,
# the ci/runtime.entitlements pair) and notarize it, in-leg, BEFORE the
# the ci/runtime.entitlements set) and notarize it, in-leg, BEFORE the
# symbol-provenance check and the boot smoke — every downstream gate, and
# the publish stage's .sha256 sidecar, then anchors the exact SIGNED
# bytes (sign-then-hash is mandatory).
Expand Down Expand Up @@ -89,18 +89,32 @@ HASH=$(security find-identity -v -p codesigning "$KC" | awk '/Developer ID Appli
[ -n "$HASH" ] || { echo "::error::no Developer ID Application identity in the p12"; exit 1; }
echo "signing identity cert: ${HASH:0:10}…"

step "codesign (hardened runtime + the spec 31 §3 pair)"
step "codesign (hardened runtime + the spec 31 §3 set)"
codesign --force --options runtime --timestamp --keychain "$KC" \
--entitlements ci/runtime.entitlements --sign "$HASH" "$exe"
codesign --verify --strict --verbose=1 "$exe"
codesign -dvv "$exe" 2>&1 | grep -q "TeamIdentifier=$APPLE_TEAM_ID" \
|| { echo "::error::TeamIdentifier is not $APPLE_TEAM_ID — signed by an unexpected identity"; exit 1; }
# macOS 15 emits the embedded plist single-line — count <true/> values,
# never key lines.
# macOS 15 emits the embedded plist single-line — count <true/> values
# AND grep each key by name (a count alone passes a wrong-keyed
# profile). The name check is the load-bearing half: no CI runner can
# police a MISSING allow-dyld-environment-variables at exec time (the
# macos-15 runners' dyld tolerates the omission and serves the shim
# anyway; macOS 14 strips DYLD_INSERT_LIBRARIES without it and the
# unpatched interpreter dies shimless on the encodings import —
# the tebako-runtime-r#5 class, tebako#1117), so the profile is
# asserted statically here, where the bytes are still in-leg.
codesign -d --entitlements :- "$exe" > "$work/embedded.xml" 2>/dev/null || true
TRUES=$(grep -o '<true/>' "$work/embedded.xml" | wc -l | tr -d ' ')
[ "$TRUES" = "2" ] || { cat "$work/embedded.xml"; echo "::error::entitlement pair not embedded (got $TRUES <true/>)"; exit 1; }
echo "entitlements embedded: disable-library-validation + allow-jit"
[ "$TRUES" = "3" ] || { cat "$work/embedded.xml"; echo "::error::entitlement set not embedded (got $TRUES <true/>)"; exit 1; }
for key in allow-dyld-environment-variables disable-library-validation allow-jit; do
grep -q "com.apple.security.cs.$key" "$work/embedded.xml" || {
cat "$work/embedded.xml"
echo "::error::entitlement $key missing from the embedded profile — the tebako-runtime-r#5 class: the runner cannot be trusted to catch it at exec time (tebako#1117)"
exit 1
}
done
echo "entitlements embedded: allow-dyld-environment-variables + disable-library-validation + allow-jit"

step "notarize (App Store Connect API key)"
printf '%s' "$APPLE_ASC_KEY_P8" > "$work/AuthKey.p8"
Expand Down
40 changes: 36 additions & 4 deletions ci/runtime.entitlements
Original file line number Diff line number Diff line change
@@ -1,24 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
Spec 31 §3/§5: the macOS runtime signing profile (fixed pair, pinned
Spec 31 §3/§5: the macOS runtime signing profile (fixed set, pinned
here until spec 31 §2's manifest derivation lands).

allow-dyld-environment-variables — THE LOAD-BEARING GRANT
(tebako#1117; the tebako-runtime-r#5 precedent). The spec 22
tier-1 visibility design re-execs the exe with the driver-armed
DYLD_INSERT_LIBRARIES (build/resources/tebako_python_main.c's
second incarnation — the in-image libtfs_preload.dylib is the
UNPATCHED CPython interpreter's only VFS visibility). The
hardened runtime strips every DYLD_* variable at launch unless
this grant is present; the re-exec'd incarnation then runs
shimless, the mount root (/__tfs__) does not exist on the host
filesystem, and the interpreter dies "ModuleNotFoundError: No
module named 'encodings'" — python's exact analog of R's
"unable to open the base package" (tebako-runtime-r#5). Proven
on darwin-23 (macOS 14.1.1 arm64) against the published
pair's own class: the same exe adhoc-signed with the hardened
runtime and the two-key profile dies on the encodings import;
re-signed adding ONLY this grant, the boot serves stdlib imports
and a libc open() of an in-image path. Every published python runtime
to date ships UNSIGNED (APPLE_SIGNING_ENABLED has never been
armed in this repo), and dyld strips the insertion only for
hardened-runtime targets — the only reason the omission never
fired (tebako#1117's "works on darwin-23" cell). The macos-15
runners TOLERATE a missing grant (their dyld keeps the
variables), so no CI runner can police this class at exec time:
ci/macos-sign-notarize-runtime.sh asserts the embedded profile
statically, by key name — this grant must be embedded BEFORE
the signing gate ever arms, which is why it lands while the
legs still ship unsigned.
disable-library-validation — EVERY runtime slice: a hardened-runtime
process by default refuses unsigned dylibs, and the driver
materializes in-image native extensions (.so) to the host for
dlopen; they carry no Developer ID signature of their own (§1.4).
This grant governs only WHICH dylibs may load — it says nothing
about WHETHER dyld honors the environment; only the grant above
does (the pair is not redundant).
allow-jit — CPython JIT builds (the matrix's jit_llvm legs) map
executable memory at runtime (MAP_JIT on arm64). Harmless on a
python built without a JIT: the entitlement is a grant, never a
requirement.

Keep the two <true/> values on their own lines: the embedding check
in ci/macos-sign-notarize-runtime.sh counts them (macOS 15 emits the
embedded plist single-line, so it greps for <true/>, not key names).
Keep each <true/> on its own line: the embedding check in
ci/macos-sign-notarize-runtime.sh counts them AND greps each key
name (macOS 15 emits the embedded plist single-line).
-->
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
Expand Down
72 changes: 72 additions & 0 deletions docs/build-chain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# The build chain — architecture and invariants

The staged build (fetch/verify → configure/make → driver link →
env-image pack → sidecars) lives in `tools/build_runtime`; the README's
"The unpatched interpreter: preload shim + re-exec" section owns the
visibility mechanism. This file records the cross-cutting planes that
mechanism depends on, with their evidence. First plane: the macOS
signing profile.

## The macOS signing profile and the dyld stripping plane (tebako#1117)

The audit question (tebako#1117, opened from the tebako-runtime-r#5
incident): does the runtime exe (a) re-exec with
`DYLD_INSERT_LIBRARIES` armed AND (b) need the shim for core IO
visibility? For this factory both answers are YES, by construction:

- **(a) the re-exec exists.** `build/resources/tebako_python_main.c`
(the fs TU) boots the driver in-process, then re-execs the exe with
the driver-armed env — `DYLD_INSERT_LIBRARIES` naming the
materialized in-image `libtfs_preload.dylib` on macOS (README's
two-incarnation composition).
- **(b) the shim is the only visibility.** CPython is unpatched (the
tamatebako/python zero-patch contract): every interpreter read of the
mounted tree — the encodings import, the stdlib, site-packages — is
plain libc IO that only the shim serves. Ruby's patched-IO exemption
does not exist here.

So the profile (`ci/runtime.entitlements`) MUST carry
`com.apple.security.cs.allow-dyld-environment-variables`: on a
hardened-runtime exe without the grant, dyld strips the variable at
the re-exec (macOS 14 — silently, by design), the second incarnation
runs shimless, and the boot dies
`ModuleNotFoundError: No module named 'encodings'` — the exact
tebako-runtime-r#5 class ("unable to open the base package"), one
interpreter over.

### Why the omission never fired before this audit (the fragile part)

Every python runtime published to date ships **unsigned**
(`APPLE_SIGNING_ENABLED` has never been armed in this repo — verified
on the published v0.3.5 `macos-arm64` exe: `flags=0x20002
(adhoc,linker-signed)`, no TeamIdentifier). dyld strips
`DYLD_INSERT_LIBRARIES` only for hardened-runtime targets, so an
adhoc exe keeps the insertion on every macOS generation and the boot
works — that, and nothing else, is why the pydata payload's demo ran
green on darwin-23 (native extensions reading in-image data). It is
the "DYLD not stripped for this profile shape" answer tebako#1117
names as fragile: the day the signing gate arms, the same bytes take
the hardened runtime and the R#5 class fires on macOS 14. The grant
therefore lands **while the legs still ship unsigned** — ahead of the
gate, exactly where the shape needs it.

### The evidence (darwin-23 = macOS 14.1.1, 23B81, arm64)

| Probe | Result |
|---|---|
| Published v0.2.7 pair (the store's sha256-verified bytes), `TEBAKO_RUNTIME_IMAGE=… exe -c 'import json,zlib,ssl; open(<in-image path>)'` | green — stdlib imports + 14132-byte libc read of an in-image path (the pydata-demo-era shape: unsigned ⇒ insertion honored) |
| Published v0.3.5 `macos-arm64` exe, `codesign -d` | adhoc linker-signed, no hardened runtime, no entitlements — the signing gate was never armed |
| The same-class exe adhoc-signed `--options runtime` with the OLD two-key profile, same probe | **dies** — `ModuleNotFoundError: No module named 'encodings'` (the stripping, reproduced) |
| The same exe re-signed adding ONLY `allow-dyld-environment-variables` | green — stdlib + the libc in-image read served |

### The policing (why a static assertion, not a runner)

The macos-15 runners' dyld TOLERATES a missing dyld-env grant (their
dyld keeps the variables), so no CI runner can police this class at
exec time — the boot smoke's shim-service scenarios (`boot`'s stdlib
imports off the mount) stay green there either way.
`ci/macos-sign-notarize-runtime.sh` therefore asserts the embedded
profile statically — three `<true/>` values AND each key by name —
in-leg, where the bytes still are. A macOS-14 exec canary (the R
factory's publish-leg shape) is the named follow-up for this repo's
acceptance workflow.
Loading