Skip to content

Fix macOS TCC attribution for terminal children via login(1) - #7003

Merged
nwparker merged 1 commit into
stablyai:mainfrom
nwparker:nwparker/tcc-access-to-other-apps-data-prompt-re-appears
Jul 4, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
nwparker:nwparker/tcc-access-to-other-apps-data-prompt-re-appears

Conversation

@nwparker

@nwparker nwparker commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #6996

Summary

  • Launch macOS terminal shells through /usr/bin/login so each terminal child carries its own TCC identity instead of collapsing into Orca's bundle identifier.
  • Pure TypeScript, macOS-only. No native node-pty patch and no private Apple API.
  • Best-effort and reversible: a no-op off macOS, when already wrapped, or when the login binary/username is unavailable, plus an ORCA_DISABLE_MACOS_LOGIN_SHELL kill switch.

The bug

On macOS, when Orca spawns a shell directly and that shell runs a separately signed CLI (e.g. the 1Password op CLI), macOS attributes the CLI's "access other apps' data" request (kTCCServiceSystemPolicyAppData) to com.stablyai.orca and logs DB Action:None — it never persists the grant, so the prompt reappears on every invocation. The issue's tccd log shows op's identity collapsed into Orca's (Sub:{com.stablyai.orca} with binary_path=.../op).

The fix

Wrap the macOS PTY shell spawn in /usr/bin/login -flpq <user> /usr/bin/env SHELL=<shell> <shell> <args…>, the same spawn shape used by native macOS terminals. This lets tccd resolve each terminal child's own code identity and persist the decision. Flags:

  • -f skip auth (we are the logged-in user relaunching as ourselves)
  • -l keep the current cwd (node-pty already set it) and skip the login dash-argv0 marker
  • -p preserve Orca's environment, including its ZDOTDIR/rcfile shell integration
  • -q suppress the login banner so wrapped terminals look unchanged

SHELL preservation: even under -p, login(1) overwrites SHELL with the account shell from the user database — verified empirically: spawning /bin/zsh through plain login -flpq yields SHELL=<account shell> even when the spawn env carries SHELL=/bin/zsh. Orca terminals deliberately export the shell they actually run (fallback shells, custom shells), so the wrapper interposes /usr/bin/env SHELL=<shell> between login and the shell. The interposition is a same-process exec chain (login → env → shell, one pid after login's fork), so it does not disturb login's TCC attribution, and it also restores $0 to the full shell path exactly as direct spawn did. It is skipped only if the shell path itself contains = (which env(1) would misparse) — plain login wrapping still applies there.

The underlying shell keeps its own args (zsh's -l, bash's --rcfile), so login-shell behavior is unchanged. Applied at both PTY spawn boundaries — the daemon (pty-subprocess.ts) and the in-process LocalPtyProvider (local-pty-utils.ts), including the fallback-shell chain. The short-lived daemon health probe is intentionally left unwrapped.

Why not the previous approach

The earlier revision patched node-pty's native posix_spawn to call the private responsibility_spawnattrs_setdisclaim (disclaim). That makes each PTY child its own TCC-responsible process — but Orca's default child is the login shell /bin/zsh, an Apple platform binary, and macOS silently denies protected-folder access to platform-binary responsible processes (no prompt; ungrantable EPERM in ~/Documents, ~/Desktop, ~/Downloads for the session and its descendants). It also relied on a private API loaded via dlsym. The login(1) approach avoids both: no private API, no native patch, and it does not strip the shell's inherited protected-folder access.

Verification

  • Unit + integration tests: wrapShellSpawnForMacosTccAttribution (platform gating, idempotency, missing-login/username fallbacks, env kill switch, SHELL interposition incl. the =-in-path and missing-env edge cases); spawnShellWithFallback routing primary and fallback shells through the wrapper with the fallback-corrected env; an IPC-level test asserting the full wrapped argv (login -flpq <user> /usr/bin/env SHELL=… <shell> -l) through the real pty:spawn handler; the daemon macOS spawn test pinning the interposed argv.
  • Full main test suite green locally (23k+ tests), plus typecheck:node, oxlint, oxfmt.
  • Real-PTY smoke (node-pty): direct spawn vs plain login vs login+env, proving the SHELL rewrite exists and the interposition fixes it, with cwd/ZDOTDIR/rcfile intact, no banner, and correct $0 — including the divergent case (spawned shell ≠ account shell).
  • End-to-end in a dev build (isolated user data): a fresh terminal's process tree is Orca → /usr/bin/login -flpq <user> /usr/bin/env SHELL=<shell> <shell> --rcfile …; inside the terminal echo $SHELL prints the spawned shell, $PWD is the worktree (not $HOME), the prompt/rcfile chain loads, no "Last login" banner, and commands run normally.

Not verifiable in CI / on an unaffected machine

TCC grant persistence depends on interactive, per-machine privacy state and only reproduces on an affected machine (this one does not exhibit the identity collapse). This PR is validated to spawn terminals correctly through login; the symptom fix should be confirmed on a machine that reproduces #6996:

  1. Run a build with this change, open a terminal, and confirm the process tree shows /usr/bin/login -flpq … above the shell (ps -o pid,ppid,command -ax | grep 'login -flpq').
  2. Run op vault list (or the affected CLI) twice; the second run should not re-prompt.
  3. Optionally watch attribution: log stream --predicate 'subsystem == "com.apple.TCC"' should show the CLI's own identity (accessing={com.1password.op}) and a DB write instead of Sub:{com.stablyai.orca} with DB Action:None.
  4. If anything misbehaves, ORCA_DISABLE_MACOS_LOGIN_SHELL=1 restores the previous direct spawn.

@ghost

ghost commented Jul 1, 2026 •

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 3 individual chapters for you:

Title
1 Implement macOS TCC attribution wrapper
2 Integrate wrapper into LocalPtyProvider
3 Integrate wrapper into PTY daemon
Open in Stage

Chapters generated by Stage for commit bd9187588de9f53d8ee4eab42989b32f71c0d115 on Jul 1, 2026 11:13pm UTC.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: dae19238-1229-42d1-b9e2-dbec0fae7987

📥 Commits

Reviewing files that changed from the base of the PR and between 27066757c595554acdeac8cb026434ec2ca71899 and 819f5f2.

📒 Files selected for processing (7)
  • src/main/daemon/pty-subprocess.test.ts
  • src/main/daemon/pty-subprocess.ts
  • src/main/ipc/pty.test.ts
  • src/main/providers/local-pty-utils.test.ts
  • src/main/providers/local-pty-utils.ts
  • src/main/providers/macos-tcc-login-shell.test.ts
  • src/main/providers/macos-tcc-login-shell.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/main/providers/local-pty-utils.test.ts
  • src/main/providers/local-pty-utils.ts
  • src/main/daemon/pty-subprocess.test.ts
  • src/main/daemon/pty-subprocess.ts
  • src/main/providers/macos-tcc-login-shell.ts
  • src/main/ipc/pty.test.ts
  • src/main/providers/macos-tcc-login-shell.test.ts

📝 Walkthrough

Walkthrough

This change adds wrapShellSpawnForMacosTccAttribution, which rewrites eligible macOS shell spawns through /usr/bin/login and optionally /usr/bin/env with SHELL reassertion. The wrapper is applied in daemon and local PTY spawn paths, including fallback shell selection. Related tests were updated to cover the wrapper, the integrated spawn paths, and the macOS-specific environment handling in the IPC PTY suite.

Changes

Compact metadata

  • Estimated code review effort: Medium
  • Lines changed: approximately +284/-13 across 6 files

Related issues: None specified
Related PRs: None specified

Suggested labels: macos, pty, testing
Suggested reviewers: None specified

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: wrapping macOS terminal children through login(1) for TCC attribution.
Description check ✅ Passed The description is detailed and covers the fix, verification, risks, and rollback, though it should still use the template's explicit section headings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
config/patches/[email protected] (1)

169-173: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Widen the helper definitions to include OpenBSD.
pty_format_spawn_error() is used from the shared PtyFork path, and pty_disclaim_spawn_responsibility() is called from the OpenBSD-compiled pty_posix_spawn() flow, but both helpers are still guarded by #if defined(__APPLE__). That leaves OpenBSD without matching definitions and breaks the build there.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3308c7c6-e189-4077-a743-788dba9eb501

📥 Commits

Reviewing files that changed from the base of the PR and between 07bbd44 and 6a1231a45598ae9c790c4a6d1e7696ec0bc7d6b7.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • config/patches/[email protected]
  • config/scripts/node-pty-macos-responsibility-patch.test.mjs

@nwparker
nwparker force-pushed the nwparker/tcc-access-to-other-apps-data-prompt-re-appears branch from 6a1231a to bd91875 Compare July 1, 2026 23:12
@nwparker nwparker changed the title Fix macOS TCC attribution for PTY children Fix macOS TCC attribution for terminal children via login(1) Jul 1, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/providers/macos-tcc-login-shell.ts (1)

50-52: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Optional: consider caching the existsSync check.

existsSync(MACOS_LOGIN_PATH) runs a synchronous fs stat on every shell spawn. Since /usr/bin/login is a static system path unlikely to change during process lifetime, this could be memoized to avoid a blocking syscall on each terminal open. Given shell spawns are infrequent (not a hot loop), this is a minor optimization, not a fix.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a340e6ca-5a24-4ccd-b418-515af7742e9d

📥 Commits

Reviewing files that changed from the base of the PR and between 6a1231a45598ae9c790c4a6d1e7696ec0bc7d6b7 and bd9187588de9f53d8ee4eab42989b32f71c0d115.

📒 Files selected for processing (6)
  • src/main/daemon/pty-subprocess.test.ts
  • src/main/daemon/pty-subprocess.ts
  • src/main/providers/local-pty-utils.test.ts
  • src/main/providers/local-pty-utils.ts
  • src/main/providers/macos-tcc-login-shell.test.ts
  • src/main/providers/macos-tcc-login-shell.ts

@nwparker
nwparker force-pushed the nwparker/tcc-access-to-other-apps-data-prompt-re-appears branch from bd91875 to 2706675 Compare July 3, 2026 18:32

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/providers/macos-tcc-login-shell.ts (1)

19-48: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Doc comment is long relative to the "short why-comment" guideline.

The rationale here is valuable, but as per coding guidelines, comments explaining non-obvious behavior should be "Keep comments short — one or two lines, capturing only the non-obvious reason." This ~30-line block covers multiple concerns (TCC rationale, flag semantics, SHELL interposition, no-op conditions). Consider trimming to the essential "why" and moving the deep design rationale to a linked doc/ADR or the PR/issue description.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e276c145-1cb2-4f75-8bdc-ddb0e178d3e1

📥 Commits

Reviewing files that changed from the base of the PR and between bd9187588de9f53d8ee4eab42989b32f71c0d115 and 27066757c595554acdeac8cb026434ec2ca71899.

📒 Files selected for processing (7)
  • src/main/daemon/pty-subprocess.test.ts
  • src/main/daemon/pty-subprocess.ts
  • src/main/ipc/pty.test.ts
  • src/main/providers/local-pty-utils.test.ts
  • src/main/providers/local-pty-utils.ts
  • src/main/providers/macos-tcc-login-shell.test.ts
  • src/main/providers/macos-tcc-login-shell.ts
✅ Files skipped from review due to trivial changes (1)
  • src/main/daemon/pty-subprocess.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/providers/local-pty-utils.test.ts
  • src/main/daemon/pty-subprocess.ts
  • src/main/providers/local-pty-utils.ts

macOS was attributing a spawned CLI's "access other apps' data" request
(kTCCServiceSystemPolicyAppData) to Orca's bundle identifier and never
persisting the grant, so signed CLIs like the 1Password op CLI re-prompted
on every launch (stablyai#6996).

Launch macOS PTY shells through `/usr/bin/login -flpq`, the same spawn shape
native terminals use, so tccd resolves each terminal child's own code
identity and remembers the decision. The wrapper preserves cwd (-l), Orca's
env including its ZDOTDIR shell integration (-p), and suppresses the login
banner (-q); the underlying shell keeps its own args so login-shell behavior
is unchanged.

Because login(1) overwrites SHELL with the account shell from the user
database even under -p, the wrapper interposes `/usr/bin/env SHELL=<shell>`
between login and the shell, re-asserting the SHELL value Orca terminals
deliberately export (fallback shells, custom shells). The interposition is a
same-process exec, so it does not disturb login's TCC attribution.

The wrapper is a no-op off macOS, when already wrapped, or when the login
binary or username is unavailable, and can be disabled with
ORCA_DISABLE_MACOS_LOGIN_SHELL.

This replaces the earlier node-pty native disclaim patch, which used a
private Apple API and would have made platform-binary login shells (/bin/zsh)
their own TCC-responsible process, a configuration macOS silently denies
protected-folder access to.

Closes stablyai#6996

Co-authored-by: Orca <[email protected]>
@nwparker
nwparker force-pushed the nwparker/tcc-access-to-other-apps-data-prompt-re-appears branch from 2706675 to 819f5f2 Compare July 3, 2026 20:22
@nwparker
nwparker merged commit 77a223a into stablyai:main Jul 4, 2026
1 check failed
nwparker added a commit that referenced this pull request Jul 4, 2026
…guard gate validators (#7321)

Quality pass on main-process/build PRs merged 2026-07-03:

- ios-emulator-backend: resolve the serve-sim executable via a lazily-cached getter
  instead of eagerly in the constructor. The bridge is built before the main window
  is shown, so the one-time recursive copy + xattr subprocess (first launch after each
  version bump) no longer blocks macOS startup for a feature that may go unused (#7174).
- index: collapse the two near-identical `{webContentsId, until}` reload flags
  (expectedRendererReload / recoveryReloadInFlight) into one `createWebContentsTimedFlag`
  primitive; behavior preserved, including consume-on-read for the recovery reload (#7290).
- check-reliability-gates: coerce gate.commands/testFiles/platforms/providers with an
  `asArray` helper before `.includes`, so a hand-edited manifest with a missing/mistyped
  field reports a validation failure instead of throwing an uncaught TypeError; extract
  `hasCompleteRedGreenEvidence` for the duplicated status check (#7295).
- claude-pty: derive FABLE_WEEKLY_LABEL_RE from WEEKLY_RE.source so a future weekly-
  wording change stays in one place and can't reopen the parsing gap it just closed.
- macos-tcc-login-shell: trim the 30-line flag-by-flag JSDoc to the two non-obvious whys
  (TCC identity, env(1) SHELL re-assertion) per the repo comment guidance (#7003).

Typecheck, oxlint, oxfmt, `check:reliability-gates`, and touched unit suites all pass.
brennanb2025 added a commit that referenced this pull request Jul 22, 2026
A conclusive PAM rejection was cached for the process lifetime, so one false
verdict (the probe runs over pipes, not a PTY) disabled the login(1) TCC
attribution wrapper for a daemon that survives app quits and updates for
weeks — reintroducing the every-invocation AppData prompts #7003 fixed.
Rejections now re-verify after 30 minutes; accepted verdicts still cache
for the process lifetime.

Refs #9756
brennanb2025 added a commit that referenced this pull request Jul 24, 2026
* fix(terminal): re-verify cached macOS login-preflight rejections

A conclusive PAM rejection was cached for the process lifetime, so one false
verdict (the probe runs over pipes, not a PTY) disabled the login(1) TCC
attribution wrapper for a daemon that survives app quits and updates for
weeks — reintroducing the every-invocation AppData prompts #7003 fixed.
Rejections now re-verify after 30 minutes; accepted verdicts still cache
for the process lifetime.

Refs #9756

* fix(daemon): replace hosts with stale login preflight cache

Protocol 26 shipped the process-lifetime PAM rejection cache. Preserve its live sessions as a legacy generation, but route fresh terminals through protocol 27 so updating actually loads the expiring-cache fix.

Refs #9756

* fix(terminal): validate rejected login probes under a PTY
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…guard gate validators (stablyai#7321)

Quality pass on main-process/build PRs merged 2026-07-03:

- ios-emulator-backend: resolve the serve-sim executable via a lazily-cached getter
  instead of eagerly in the constructor. The bridge is built before the main window
  is shown, so the one-time recursive copy + xattr subprocess (first launch after each
  version bump) no longer blocks macOS startup for a feature that may go unused (stablyai#7174).
- index: collapse the two near-identical `{webContentsId, until}` reload flags
  (expectedRendererReload / recoveryReloadInFlight) into one `createWebContentsTimedFlag`
  primitive; behavior preserved, including consume-on-read for the recovery reload (stablyai#7290).
- check-reliability-gates: coerce gate.commands/testFiles/platforms/providers with an
  `asArray` helper before `.includes`, so a hand-edited manifest with a missing/mistyped
  field reports a validation failure instead of throwing an uncaught TypeError; extract
  `hasCompleteRedGreenEvidence` for the duplicated status check (stablyai#7295).
- claude-pty: derive FABLE_WEEKLY_LABEL_RE from WEEKLY_RE.source so a future weekly-
  wording change stays in one place and can't reopen the parsing gap it just closed.
- macos-tcc-login-shell: trim the 30-line flag-by-flag JSDoc to the two non-obvious whys
  (TCC identity, env(1) SHELL re-assertion) per the repo comment guidance (stablyai#7003).

Typecheck, oxlint, oxfmt, `check:reliability-gates`, and touched unit suites all pass.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…blyai#9973)

* fix(terminal): re-verify cached macOS login-preflight rejections

A conclusive PAM rejection was cached for the process lifetime, so one false
verdict (the probe runs over pipes, not a PTY) disabled the login(1) TCC
attribution wrapper for a daemon that survives app quits and updates for
weeks — reintroducing the every-invocation AppData prompts stablyai#7003 fixed.
Rejections now re-verify after 30 minutes; accepted verdicts still cache
for the process lifetime.

Refs stablyai#9756

* fix(daemon): replace hosts with stale login preflight cache

Protocol 26 shipped the process-lifetime PAM rejection cache. Preserve its live sessions as a legacy generation, but route fresh terminals through protocol 27 so updating actually loads the expiring-cache fix.

Refs stablyai#9756

* fix(terminal): validate rejected login probes under a PTY
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.

TCC 'access to other apps' data' prompt re-appears on every subprocess launch (e.g. 1Password op CLI) instead of being remembered

1 participant