Skip to content

fix(security): apply ~/.apm/apm.yml executable grants to global install and uninstall - #3986

Merged
Daniel Meppiel (danielmeppiel) merged 7 commits into
mainfrom
danielmeppiel-user-scope-exec-trust
Nov 19, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 7 commits into
mainfrom
danielmeppiel-user-scope-exec-trust

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

Two defects in the #3902 executable-trust code on main.

1. User-scope approvals were ignored. At user scope the deploy root is $HOME, but the manifest and its executables grants live in $APM_HOME (~/.apm/apm.yml). Three callers resolved trust from $HOME/apm.yml instead, so a global install or uninstall never saw the user manifest's gate or pins. Only a legacy allowExecutables block got through, via the apm_package fallback. With an executables: block, unapproved hooks deployed.

Caller Before Evidence
apm install -g install/template.py:67 used ctx.source_root or ctx.project_root (= $HOME) fail-before at test line 69
global apm uninstall survivor rebuild commands/uninstall/engine.py:1387 got project_root = deploy_root = $HOME (commands/uninstall/cli.py:494, :139) fail-before at test line 82
HookIntegrator.reconcile_after_removal integration/hook_integrator.py:1991, same pattern with user_scope in hand same fix

The fix is core.scope.manifest_root(project_root, *, user_scope), which returns get_apm_home() at user scope and is passed into the existing resolvers. No new trust decider is added, and the G1-G3 guards are green.

2. Every normalized legacy plugin was parked. utils/content_hash.unpinned_apm_copy requires every file under a root .apm/ to be a byte copy of a pinned plugin file. Legacy-plugin normalization also writes its own receipt, .apm/.plugin-skill-sources.json, so admit_native_plugin parked every such plugin (for example obra/superpowers) with apm-owned-reference, and approval could not fix it. The fix exempts exactly that file, using the parser's constant. Any other non-copy under .apm/ still parks.

Found while integrating #3918 into #3290.

Issue and approved scope

Issue: Refs #3902

Human scope-approval comment: follow-up defects in #3902's merged implementation (#3918), split out of #3290 at the 0.37 captain's request so 0.37 does not depend on #3290.

Does this PR complete the issue, or what remains? It fixes these two defects only; #3902 is otherwise delivered.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

tests/integration/test_user_scope_exec_trust_lifecycle.py runs the real CLI in an isolated HOME. Two local hook packages are installed with executables: {allow: {}} in ~/.apm/apm.yml:

  • install -g: both are parked.
  • apm approve <beta>, then install -g: beta deploys, alpha stays parked.
  • uninstall -g beta: the survivor rebuild leaves alpha parked.

Commands and results (macOS arm64, host under load, so targeted only):

  • APM_E2E_TESTS=1 pytest tests/integration/test_user_scope_exec_trust_lifecycle.py: 1 passed.
  • Fail-before, with the template and uninstall fixes reverted: failed at line 69 (alpha deployed on install). With only the uninstall fix reverted: failed at line 82 (alpha deployed by the survivor rebuild).
  • pytest tests/unit/security/test_trust_fingerprint.py -k receipt: 1 passed. This is the regression test for (2), including that another unpinned .apm/ file still parks.
  • pytest -n 2 tests/unit/install/test_template_exec_trust.py tests/unit/security/test_trust_fingerprint.py tests/unit/security/test_trust_admission.py tests/unit/commands/test_approve_deny.py tests/unit/core/test_scope.py: 182 passed.
  • pytest -n 2 tests/unit/test_uninstall_reintegration.py tests/unit/test_surviving_deps_reintegration.py tests/unit/test_uninstall_engine_helpers.py tests/unit/test_uninstall_engine_phase3w5.py tests/unit/integration/test_hook_integrator*.py: 336 passed.
  • Lint mirror: ruff check and format (0.15.12), pylint R0801, lint-auth-signals.sh and lint-architecture-boundaries.sh all clean; hook_integrator.py is at 2099 lines.
  • tests/spec_conformance/mode_b_detector.sh: OK.
  • CI runs the full matrix.

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md: user-visible effect first, 25 words or fewer, ending with (#PR); breaking changes only under upgrade notes; no Highlights; see .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour. It makes the implementation honor the existing user-scope manifest grants.

Co-authored-by: Copilot App [email protected]

…3902)

At user scope the deploy root is $HOME, but the manifest and its
`executables` grants live in $APM_HOME (~/.apm). `apm install -g`
(install/template.py) and global uninstall survivor rebuild
(uninstall/engine.py, HookIntegrator.reconcile_after_removal) resolved trust
from $HOME/apm.yml, so the user manifest's approvals and gate were ignored and
unapproved hooks could deploy. core.scope.manifest_root() names the manifest
directory for the existing resolvers; no new decider.

Also exempt exactly the parser-owned `.apm/.plugin-skill-sources.json`
normalization receipt from unpinned_apm_copy: it is APM metadata, not a
plugin copy, and refusing it parked every normalized legacy plugin.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 19, 2026
Copilot AI balanced review requested due to automatic review settings November 19, 2026 19:30

Copilot AI 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.

🟡 Changes recommended

Critical gaps let survivor rebuilds miss HOME-based organization denials when APM_HOME is external and allow unhashed plugin receipt changes to alter hook execution without invalidating the pin.

2 open issues
What changed in this PR

This PR fixes two executable-trust defects following #3918: global operations reading grants from the wrong manifest directory, and normalized legacy plugins being rejected because of their generated receipt.

Changes:

  • Add a scope-aware manifest-root helper for install and uninstall trust resolution.
  • Exempt the parser-owned skill-source receipt from the unpinned-copy check.
  • Add lifecycle and receipt regression coverage, plus a changelog entry.
File Description
tests/​unit/​security/​test_trust_fingerprint.py Tests the receipt exception and rejection of other unpinned files.
tests/​integration/​test_user_scope_exec_trust_lifecycle.py Covers global install, approval, and uninstall survivor gating.
src/​apm_cli/​utils/​content_hash.py Exempts the normalization receipt from copy validation.
src/​apm_cli/​integration/​hook_integrator.py Uses the user manifest root during hook reconciliation.
src/​apm_cli/​install/​template.py Resolves install grants from the scope-aware manifest root.
src/​apm_cli/​core/​scope.py Adds the shared manifest-root helper.
src/​apm_cli/​commands/​uninstall/​engine.py Uses the scope-aware root when rebuilding survivors.
CHANGELOG.md Documents the global executable-approval fix.

Review effort: Balanced

Comment thread src/apm_cli/utils/content_hash.py Resolved
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 19, 2026
…ifest_root)

Same fix as #3986, which lands on main independently: user-scope executable
grants are read from ~/.apm/apm.yml for install and global uninstall, and the
normalization receipt is exempt from unpinned_apm_copy.

Co-authored-by: Copilot App <[email protected]>
…PM's canonical receipt

Review follow-ups on #3986:
- resolve_project_exec_allow_map gains manifest_dir: grants come from the
  user manifest while org policy is still discovered from the deploy root,
  so an external APM_HOME cannot drop HOME's Git-derived policy in survivor
  rebuilds (uninstall engine, HookIntegrator.reconcile_after_removal).
- The .apm/ receipt exemption now requires the exact canonical receipt that
  normalization writes for a legacy plugin (plugin_parser owns the check) and
  never applies to a live-loaded Agent Plugin root; publisher-controlled or
  extended receipt bytes still park the plugin.

Co-authored-by: Copilot App <[email protected]>
…MCP and LSP

Fold the lean review panel on #3986:
- McpAdmission.for_project and resolve_project_exec_allow_map take a
  required user_scope and read grants from the scope's manifest
  themselves, so the MCP and LSP user-scope paths (and every future
  caller) can no longer read $HOME/apm.yml. Org policy discovery stays
  anchored at the deploy root.
- Harden the normalization-receipt exemption: one shared serializer,
  bounded read, '.'/'..' names refused, each .apm/skills/<name>/ file
  must be a byte copy of the same path under its recorded source, and
  the skip re-checks path and bytes.
- Tests: behavioral req-sc-009 conformance test at user scope (install
  hooks and MCP admission) with a deploy-root decoy manifest; decoys in
  the unit and real-CLI tests; writer round-trip receipt test.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_with_followups

Closes the user-scope executable-grant bypass for global install/uninstall, MCP and LSP; all panel findings folded with mutation-proven tests. Ship once CI on 3c2f9e4 is green.

panel-mode=lean; personas=supply-chain-security-expert,python-architect,test-coverage-expert,apm-ceo; reviewed a0ae1106d, folds landed in 3c2f9e48d

cc Daniel Meppiel (@danielmeppiel) Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

The specialists agreed on the direction. The only finding rated required came from python-architect: the MCP and LSP user-scope paths still read grants from $HOME/apm.yml. That was a real trust-root defect on a secure-by-default surface, and it is fixed at the root. McpAdmission.for_project and resolve_project_exec_allow_map now take a required user_scope keyword and resolve the root through core.scope.manifest_root themselves. All 8 callers pass it. If a caller leaves it out, the result is a TypeError instead of a silently wrong root. The same fix removes the split-authority concern: the owner now chooses the grant root. Org policy discovery stays at the deploy root, so deny-wins still holds.

The receipt-provenance finding is folded too. Names . and .. are refused. Every file under .apm/skills/<name>/ must be a byte copy of the file at the same path under its recorded source. The skip re-checks both path and bytes, which closes the time-of-check race. Writer and validator now share one serializer, and the read is size-bounded. Mutation testing shows the byte-copy guard is the main control, with the .. guard as a second layer.

On test evidence: test_receipt_written_by_normalization_is_exempt sends a receipt produced by the real writer through the exemption. Decoy $HOME/apm.yml files are planted at the unit, spec-conformance and real-CLI levels. In the real-CLI test, reverting the template fix lets the decoy deploy ALPHA_HOOK, so the regression trap is proven. The new behavioral test tests/spec_conformance/test_user_scope_executable_gate_reqs.py binds req-sc-009, which now has 6 tests. It satisfies the Mode B spec gate without a waiver.

Dissent. There was no substantive disagreement; the architect's required rating for the MCP/LSP root stands. One documented limit remains: the receipt's declared flag only selects among pinned skills and is not re-derived from manifest admission.

Aligned with: Secure by default: user scope fails closed, grants come only from ~/.apm/apm.yml, a decoy $HOME/apm.yml is ignored, and receipts must be byte copies of their recorded sources. Governed by policy: org policy discovery stays anchored at the deploy root, and deny-wins is preserved across hooks, MCP and LSP. Portable by manifest: the manifest root has one owner (core.scope.manifest_root), so project and user scope resolve the same way across every executable surface.

Panel summary

Persona B R N Takeaway
Supply chain security expert 0 1 0 Closes the user-scope trust bypass; policy stays anchored at project_root and deny-wins holds. Receipt check verified format, not provenance (folded).
Python architect 1 2 0 manifest_root belongs in core/scope, but callers chose it; LSP/MCP user-scope paths read $HOME; receipt rule spread across modules (all folded).
Test coverage expert 0 2 0 Real-CLI regression test exists; added writer round-trip receipt test and $HOME/apm.yml decoys (folded).

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Top 2 follow-ups

  1. [Supply chain security expert] Derive the receipt's declared flag from the admitted plugin manifest instead of using it only to select among pinned skills. -- This moves the receipt from proving byte provenance to also proving declaration provenance, on a secure-by-default surface.
  2. [Python architect] Add a static boundary rule requiring an explicit user_scope at trust-owner call sites. -- The required keyword already enforces this at runtime; a static rule would catch new call sites before tests run.

Generated by autopilot-pr-merge-worker. This comment is AI-generated and may contain errors.

An in-process `apm audit --format json` call (test_audit_recorded_target_reqs)
routes the process-global console to stderr and nothing reset it, so
test_packed_hook_resolution_reqs read an empty stdout whenever shard
balancing placed it later in the same process. Adding a spec module
shifted the shard boundary and exposed it; reproduced with the CI shard 3
flags (6 failed) and fixed (219 passed).

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 14d828e into main Nov 19, 2026
38 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-user-scope-exec-trust branch November 19, 2026 21:23
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 19, 2026
…t caller

Brings in #3986 (user-scope executable grants from ~/.apm/apm.yml) at
14d828e. Conflicts in install/template.py and security/trust.py are
resolved to #3988's trust-owner signature: exec_trust_context_for_project
takes the scope's manifest FILE, derived through the scope owner as
project_manifest_path(manifest_root(root, user_scope=...)). #3986's
manifest_root stays for directory callers (resolve_project_exec_allow_map,
uninstall, hook integrator); policy stays anchored at the deploy root.

Folded at the owner:
- prepare_mcp_integration drops the apm_package.package_path getattr chain;
  McpAdmission.for_project(user_scope=...) now names the grants manifest.
- Audit replay (ReplayExecAllowMap) takes user_scope and reads
  APM_HOME/apm.yml under -g instead of deriving apm.yml from the deploy root;
  regression test proven by mutation-break.
- GUARD_EXECUTABLE_TRUST also refuses a registered caller whose body derives
  apm.yml from a root; standalone mutation test
  test_trust_owner_guard_rejects_root_derived_callers covers an unregistered
  #3986-style global-uninstall caller and a registered caller deriving
  apm.yml (mutation-break: dropping the new clause fails it).

apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 19, 2026
The conflict resolution took #3986's hook_integrator.py and dropped this
branch's dry_run parameter on reconcile_target_contraction, so every
native Claude install failed with an unexpected keyword argument when
services.py counted leftover loose hooks.

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 19, 2026
…pers in budget

- Restore reporting the apm-hooks.json sidecar beside the settings file in
  failed_paths (lost in the #3986 merge), so the native-transition refusal
  names both files.
- native_runtimes_of() reads a dependency's native runtimes as a frozenset
  for every writer, so non-dependency values (test doubles) never compare.
- Move retire_native_runtime_claims to install/mcp/native_runtimes.py so
  install/mcp/ownership.py stays within its 1000-line budget.

Co-authored-by: Copilot App <[email protected]>
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.

2 participants