Repository navigation
fix(security): apply ~/.apm/apm.yml executable grants to global install and uninstall - #3986
Conversation
…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]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 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
…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]>
Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| 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
- [Supply chain security expert] Derive the receipt's
declaredflag 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. - [Python architect] Add a static boundary rule requiring an explicit
user_scopeat 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]>
…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]>
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]>
…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]>

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 itsexecutablesgrants live in$APM_HOME(~/.apm/apm.yml). Three callers resolved trust from$HOME/apm.ymlinstead, so a global install or uninstall never saw the user manifest's gate or pins. Only a legacyallowExecutablesblock got through, via theapm_packagefallback. With anexecutables:block, unapproved hooks deployed.apm install -ginstall/template.py:67usedctx.source_root or ctx.project_root(=$HOME)apm uninstallsurvivor rebuildcommands/uninstall/engine.py:1387gotproject_root=deploy_root=$HOME(commands/uninstall/cli.py:494,:139)HookIntegrator.reconcile_after_removalintegration/hook_integrator.py:1991, same pattern withuser_scopein handThe fix is
core.scope.manifest_root(project_root, *, user_scope), which returnsget_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_copyrequires 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, soadmit_native_pluginparked every such plugin (for exampleobra/superpowers) withapm-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
Testing
tests/integration/test_user_scope_exec_trust_lifecycle.pyruns the real CLI in an isolated HOME. Two local hook packages are installed withexecutables: {allow: {}}in~/.apm/apm.yml:install -g: both are parked.apm approve <beta>, theninstall -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.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-auth-signals.shandlint-architecture-boundaries.shall clean;hook_integrator.pyis at 2099 lines.tests/spec_conformance/mode_b_detector.sh: OK.Changelog
## [Unreleased]inCHANGELOG.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.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regeneratedCo-authored-by: Copilot App [email protected]