Skip to content

Install and self-update on Macs without Xcode or the Command Line Tools - #1325

Closed
tolgaergin wants to merge 5 commits into
mainfrom
fix/macos-notarization-without-xcode
Closed

tolgaergin wants to merge 5 commits into
mainfrom
fix/macos-notarization-without-xcode

Conversation

@tolgaergin

@tolgaergin tolgaergin commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On a Mac with only the Command Line Tools, lpm self-update refused every macOS standalone update:

✗ Self-update refused
  reason macOS notarization-ticket validation failed with status exit status: 1: xcode-select: error: tool 'stapler' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
  • Self-update (0.76.0–0.88.0) runs /usr/bin/stapler. That is an xcrun shim that refuses to run without Xcode, even when the Command Line Tools ship their own stapler.
  • install.sh runs xcrun stapler. That works with recent Command Line Tools, but fails on a Mac with no developer tools at all.
  • Why no test caught it: every GitHub-hosted macOS runner has Xcode, the unit tests used a fake stapler, and the installer tests used a fake xcrun.

What stapler validate checked, and what replaces it

stapler validate looks up Apple's ticket record for the app's SHA-256 code-directory hash, 2/2/<cdhash> in Apple's public ticket database on CloudKit. It accepts the stapled ticket while that record stands, as long as the stapled ticket is a ticket for the same code. It need not be byte-identical: LPM Vault.app's record was replaced by a second notarization 58 s after the first, its stapled ticket differs from the record in 245 bytes, and stapler accepts it. The council compared every built-in alternative on the real v0.88.0 bundle and on tampered copies:

Check on real v0.88.0 genuine ticket deleted garbage ticket another release's ticket ad-hoc re-signed
stapler validate (Xcode) ✅ ❌ ❌ ❌ ❌
codesign -R=notarized, --check-notarization, spctl, syspolicy_check ✅ ✅ (except syspolicy_check) ✅ ✅ ❌
Apple's ticket record plus the stapled ticket's code (this PR) ✅ ❌ ❌ ❌ ❌

No built-in assessor proves which bytes are stapled, because syspolicyd answers from its cache or online. So both the installer and self-update now do what stapler does, with tools that ship with macOS. The HTTPS lookup runs in-process in Rust, and with curl, plutil, PlistBuddy, base64, cmp and od in install.sh.

Apple's record for the code must exist and not be deleted. The stapled ticket must then be Apple's current ticket, or another ticket that carries Apple's s8ch magic and lists the same code-directory hash. The latter covers the case where Apple notarized the same code again.

Requiring a byte-for-byte match would have been stricter than stapler. A release whose code Apple ticketed again would then be permanently uninstallable, since immutable releases can't take a new staple.

The gap versus stapler, accepted when this PR was reviewed: a stapled ticket that differs from the record isn't signature-checked by our code. Its bytes come from the Sigstore-verified archive, and Gatekeeper's online assessment and the notarized requirement still run.

  • Missing or revoked record, or a stapled ticket for other code: fails at once.
  • Unanswered lookup: retried over about two minutes as before. This covers 5xx, 429, THROTTLED and similar record errors, an unreadable answer, and a dropped connection.
  • Other refusals: fail at once and name the refusal.

Added on top of that:

  • Pinned code requirement: codesign --verify --strict now requires a Developer ID Application signature by 823S8YKMRW over dev.lpm.cli, and notarized, so Apple's own code-signing machinery confirms the identity and that Apple notarized this code. syspolicyd may answer notarized from the stapled ticket, its cache or Apple's service, so this does not prove the stapled bytes; the record comparison does.
  • Profile decoding: security cms -D failed for accounts without a default keychain. The provisioning profile is now decoded with Security.framework's CMSDecoder in self-update and with openssl smime in install.sh. The profile is a sealed resource, so decoding it is enough.
  • Validation environment: self-update runs its validation tools with only the system PATH, so DEVELOPER_DIR and other variables can't change their behavior.

Gatekeeper (spctl --assess) and every other check are unchanged. The policy is the same as before, and stricter where noted. The only new exposure is that the CloudKit lookup endpoint is undocumented, though stapler and Gatekeeper's own online check use it. If Apple changes it, the check fails closed, and the new daily job reports it.

install.sh's lookup follows the same rules as self-update's:

  • ~/.curlrc can't change the outcome. Redirects are refused and the status is read from the response headers, so location or fail there make no difference, while its proxy settings still apply.
  • The answer is parsed defensively. At most 64 KiB is read, each field is extracted on its own so a JSON null elsewhere can't hide the ticket, and every field must have its JSON type.
  • Character classes are spelled out, so a locale that collates a-f together with A-E can't widen them.
  • Test hooks only take a real loopback URL: the exact host and an all-digit port. A user-info @ used to let a lookalike URL reach another host.

Regression gates

  • No developer-tool shims (unit test): the macOS validation tools are a closed MacOSTool enum, and a test fails if any of them is an xcrun shim, i.e. a hard link of /usr/bin/git or /usr/bin/xcodebuild.
  • Same check for the installer: tests/install-sh/run.sh applies it to every tool install.sh runs, by absolute path or on PATH. It also fails if install.sh mentions xcrun, stapler or xcode-select.
  • Required on every PR: the macOS CI build checks, which feed the required "macOS workspace checks", now run tests/install-sh/run.sh. Its macOS cases include the shim check and the ticket-lookup cases.
  • New workflow macos-without-developer-tools.yml, job macOS with developer tools {none, command-line-tools}. It runs on PRs that touch these paths, daily at 09:41 UTC and on dispatch. It removes Xcode (and the Command Line Tools for none) from a macos-15 runner, verifies they're gone, then runs against real signed releases:
    1. the updater's real-release tests, including swapped and garbage tickets;
    2. a fresh install through install.sh;
    3. an in-place upgrade of a real affected v0.85.0 install, preserving settings. It first asserts that v0.85.0's own updater fails there, which proves the tools are gone;
    4. the latest stable release's own updater taking the newest nightly. This is expected to fail while the latest stable release is 0.88.0 or older, and must pass once a fixed release is latest;
    5. this build, stamped 0.0.1, self-updating to the latest signed stable and nightly releases, preserving settings.
  • Release candidates: the macOS installer smoke for each candidate now installs the exact staged candidate with no developer tools, on arm64 and Intel.
  • Recovery notes: npm/release/upgrade-recovery.md, which goes into every release's notes, now covers these releases. Users of 0.76.0–0.88.0 without Xcode rerun the installer once.

Verification so far

  • Bug-first tests: before the fix, the shim test failed on /usr/bin/stapler. The real-archive test failed with the user's exact message under DEVELOPER_DIR=/Library/Developer/CommandLineTools. After the fix, both pass, under that setting and with an empty developer directory.

  • Fixed install.sh against the real GitHub v0.88.0 release: installed with a temporary HOME (no keychain), an empty DEVELOPER_DIR and the stock PATH.

  • Fixed build (debug, stamped 0.0.1) on this Mac, in a throwaway account home: self-updated to the real v0.88.0 and to v0.89.0-nightly.20261124.284.bc3608e. Each installed app satisfied the Developer ID + notarized requirement.

  • Local checks:

    • cargo test -p lpm-cli --bin lpm-rs self_update: 242 passed.
    • cargo clippy -p lpm-cli --all-targets -D warnings: clean.
    • cargo fmt --check: clean.
    • sh tests/install-sh/run.sh: 41 passed.
    • node --test npm/release/tests/*.test.mjs: 213 passed.
    • scripts/ci/test-macos-developer-tools.sh: passed on macOS and on Debian.
  • CI, run 45517569258 on the first commit, both legs: the developer tools were removed and verified gone. This build's real-release tests and a fresh install.sh install of the real latest release passed. The affected-install step then failed on a test bug: v0.85.0's lpm config started a background update check that held the update lock. Fixed in round 1.

  • Linux (OrbStack, Debian 12 arm64, non-root):

    • the installer harness passes under dash;
    • a fresh install of v0.88.0 works;
    • an in-place upgrade from v0.85.0 keeps settings byte-identical and adds no duplicate PATH line;
    • v0.85.0's own updater updates to v0.88.0 and then to the latest nightly.
  • Council round 1 (Fable 5.2, Opus 5.5, Astra 6.2, Sol 6.2, Gemini 4 Neon): all findings fixed in the second commit, test-first. Round 2 reviews that commit.

  • Linux, this branch's build: in OrbStack, stamped 0.0.1, it self-updated to the real signed v0.88.0 and the latest nightly.

  • Council rounds 2 and 3: all findings fixed test-first. Each guard is mutation-tested: removing it fails the harness or the Rust tests. The first CI runs of the new workflow caught two problems, both now fixed: the shared unauthenticated GitHub API limit, and macOS 15's plutil, which can't write JSON holding a null. So the installer now extracts single values only, which behaves the same on every version.

Still open: CI on the final head, Windows (Parallels VM) checks, and the full workspace gate (left to CI: locally it would take the disk below the 20 GB floor).

Recovery for users

The installer fix takes effect when this merges, because https://cli.lpm.dev/install redirects to main. Updaters in 0.76.0–0.88.0 can't be changed, so their users without Xcode rerun the installer once after the next release. From that release on, lpm self-update works without developer tools.

🤖 Generated with Claude Code

tolgaergin and others added 3 commits November 25, 2026 00:21
lpm self-update ran /usr/bin/stapler and install.sh ran `xcrun stapler`.
Both are xcrun shims: stapler needs Xcode, so self-update refused every
update on a Mac with only the Command Line Tools, and both failed on a Mac
with neither. GitHub's macOS runners have Xcode, so no test saw it.

Both now confirm the notarization ticket the way `stapler validate` does,
with tools every Mac ships with: they look up Apple's ticket record for the
app's SHA-256 code-directory hash over HTTPS and require it to equal the
stapled ticket byte for byte. A missing, revoked or different ticket fails
at once; an unanswered lookup is retried for about two minutes as before.
The code-signature check now also requires LPM's Developer ID identity and
`notarized`, which verifies the stapled ticket's Apple signature offline on
a Mac that hasn't seen this code. Gatekeeper's assessment is unchanged.

The provisioning profile is decoded in process (self-update) or with
openssl (install.sh) instead of `security cms -D`, which needs a default
keychain. Self-update runs its validation tools with only the system PATH,
so variables such as DEVELOPER_DIR can't change what they do.

Tests:
- macOS validation may run only programs that ship with macOS; a test fails
  for any xcrun shim, and install.sh's harness checks its tools the same way
- the ticket lookup's answers, retries and refusals, in Rust and install.sh
- real signed releases, including swapped and garbage tickets
- a new CI job removes Xcode, or Xcode and the Command Line Tools, from a
  macOS runner, then installs and upgrades through install.sh, checks an
  affected v0.85.0 install, and self-updates this build to the latest
  signed stable and nightly releases; it also runs daily
- the release candidate's installer smoke runs without developer tools

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ates

From the council's first review round:

- install.sh's lookup no longer lets ~/.curlrc decide: it refuses
  redirects and reads the status from the response headers, so `location`
  or `fail` there can't change the outcome, while its proxy settings still
  apply. It reads at most 64 KiB, extracts each field on its own so a JSON
  null elsewhere in the answer can't hide the ticket, requires every field
  to have its JSON type, caps an echoed error code at 40 characters, and
  retries HTTP 408. Character classes are spelled out, so locales that
  collate a-f with A-E can't widen them. Self-update now also retries 408,
  takes a null `deleted` as absent and reads the body through
  lpm_http::read_body_capped.
- Test endpoints must be the exact loopback host with an all-digit port;
  a user-info `@` let a lookalike URL reach another host.
- The fake codesign accepts only the pinned requirement, and parity tests
  hold the requirement, transient errors and size limit to install.sh's.
  New tests cover an extra record, an empty or undecodable ticket, nulls,
  an oversized answer, malformed fields and code-directory hashes, and an
  oversized or corrupt provisioning profile. A real-network test confirms
  Apple's record matches a release's own ticket and no other.
- The developer-tools-free job moves to its own workflow, so only it runs
  daily. Its v0.85.0 configuration step no longer starts a background
  update check that held the update lock; expected versions come from
  where install.sh and lpm self-update look; the restore step reselects
  the developer directory selected before; the Command Line Tools check
  requires the stapler shim's own refusal.
- The macOS CI build checks now run the installer harness, so its macOS
  cases, the no-shim check among them, gate every pull request.
- Comments no longer claim `notarized` proves the stapled ticket offline:
  the system may answer it from its cache or Apple's service.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From the council's second review round:

- Every field's type is checked on the root element of its extracted
  value, so a string or boolean wrapped in an array or object no longer
  passes, and all fields are checked before any decides, as self-update's
  parser does. `records` must be an array holding exactly one object:
  plutil can't tell a missing second element from a null one, so the
  serialized array is compared with its first record. A ticket must be
  standard padded base64, which base64 -D alone doesn't enforce.
- A 200 whose transfer failed is retried as "an incomplete answer" instead
  of being parsed, a status line without a reason phrase or with a CR is
  read correctly, and an interim 1xx status is retried.
- Tests: container-typed, numeric and non-JSON fields, a null or object
  `records`, undecodable base64, a truncated answer, and a client that
  must hang up on an endless answer, so dropping the 64 KiB cap fails.
  The requirement parity test reads install.sh's bundle and team values.
- The workflow runs the live ticket-database test and fails unless all
  four signed-release tests ran, retries a fresh install that GitHub's
  shared unauthenticated limit refused, reads the expected versions after
  each update, and has its own cache key. The developer-tools helper keeps
  cache directories with spaces intact.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tolgaergin
tolgaergin marked this pull request as ready for review November 25, 2026 01:11
tolgaergin and others added 2 commits November 25, 2026 01:38
From the council's third review round, and the new workflow's first runs:

- plutil on macOS 15 can't write JSON holding a null, so the round-2 check
  that compared the serialized `records` with its first record failed
  there for any null in the answer, and a genuine answer with one would
  have failed every install. install.sh now extracts single values only,
  as XML, which a null elsewhere doesn't touch on any version; a second
  record or an empty `records` still means another record. Shapes only a
  non-Apple server could send, such as `[record, null]`, are read by
  their record, the same on every version; the exact ticket still
  decides.
- `fields` and `signedTicket` must be objects when present, a present
  `signedTicket` must hold a string value, and a string across lines is
  judged as a string.
- Tests pin each guard: base64 outside the standard padded alphabet, a
  malformed field beside NOT_FOUND, an answer of exactly 65,536 and of
  65,537 bytes, an interim-only 100, a status line without a reason
  phrase, a confirmed ticket with a ~/.curlrc (whose CURL_HOME the harness
  pins), and a Rust oversized answer that would otherwise be a valid
  ticket, with each retry's detail asserted.
- The workflow names the fresh install's version, since the shared
  unauthenticated GitHub limit refused all three tries on a runner, and
  accepts v0.85.0's quoted release-age value. Each updater check compares
  the version the updater reports choosing with the dist-tag before or
  after the update. The developer-tools helper skips an empty per-user
  temporary directory instead of stopping under set -e.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ler does

`stapler validate` does not compare the stapled ticket with Apple's record
byte for byte: LPM Vault.app's record was replaced by a second notarization
58 s after the first, its stapled ticket differs from the record in 245 of
1884 bytes, and stapler accepts it. Requiring equality would have made a
release whose code Apple ticketed again uninstallable and un-updatable for
good, since immutable releases can't take a new staple.

Both install.sh and self-update now accept the stapled ticket when it is
Apple's current one for the code, or a ticket that carries Apple's `s8ch`
magic and lists the same code-directory hash. Apple's record must still
exist and not be deleted. A stapled ticket for other code, or a file
without the magic, fails at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tolgaergin

Copy link
Copy Markdown
Contributor Author

Superseded by #1329. This PR checked notarization tickets against Apple's ticket service. The updater would have depended on an undocumented Apple web API for good, and its shell parser already answered differently on macOS 15 and macOS 27. #1329 checks releases only with tools that ship with macOS and calls no Apple service. Checking for revoked notarizations moves to the release side.

@tolgaergin tolgaergin closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant