Repository navigation
fix(approve): grant replacement source key for replaced dependencies - #3742
Conversation
…ey owner apm approve / deny / policy explain now resolve a dependency redirected by replace: by its original or selected-source name and write the selected source key the executable gate checks. The locked-row trust principal moves into security/executables.locked_dependency_approval_identity, which the approve scanner and the MCP/LSP views share, so an upstream grant never unlocks the replacement anywhere. Consolidates the three duplicated declaration lookups into one helper, extends the executable-trust guard, and adds an installed-CLI lifecycle test (local path and fork). Refs microsoft#3710 apm-spec-waiver: executable approval key routing for replaced dependencies, no spec contract change Co-authored-by: Mohammed Alkindi <[email protected]> Co-authored-by: Copilot App <[email protected]>
main's changelog rule (microsoft#3886) asks for one short line per change, ideally 25 words or fewer; the merged entry was about 40. Co-authored-by: Copilot App <[email protected]>
…tream Folds the lean panel on microsoft#3742: - security/executables.locked_dependency_approval now returns the whole trust principal (identity, version, original_identity), so approve.py no longer re-decides whether a row is replaced (python-architect FU). - The install-deployment-executable-trust-context guard forbids a parallel locked-row derivation in approve.py and drops brittle owner-body tokens; a new mutation test proves it (python-architect FU). - _find_declaration is typed and tiered: lockfile-derived names (approval key, replaced original identity) beat a package's self-declared apm.yml name, so a lookalike cannot capture approve/deny (supply-chain FU). - apm deny <original> on a replaced dependency also denies the original identity, so removing the replace: rule cannot revive an old grant (supply-chain FU); the lifecycle test gains a deny leg and the fork key tuple gets a unit test (test-coverage FU). Refs microsoft#3710 Co-authored-by: Copilot App <[email protected]>
Folds the delta test-coverage findings on microsoft#3742: apm deny <original> on a replaced dependency must remove an old upstream allow, and apm approve acme/hooky#1.0.0 must still resolve the replaced row. Both tests fail when the guarded line is removed. Documents the owner's legacy version override. Refs microsoft#3710 Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 1 | 0 | All three prior findings are resolved: the owner returns a frozen LockedApproval, the guard blocks a second derivation, and _find_declaration is typed and tiered. One leftover gap in the owner API. |
| Supply Chain Security Expert | 0 | 0 | 0 | Folds resolve both prior findings: lookup now prefers lockfile names, and deny also covers the upstream identity. Deferring the --user path grant is reasonable. No new risk; ship. |
| Test Coverage Expert | 0 | 2 | 0 | Folds close both prior gaps: the lifecycle test has a deny leg and the fork key tuple is pinned. Two new fold behaviors have no trap: deny popping the upstream allow, and the '#'-prefix tier. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships. Test Coverage Expert's two delta findings were folded in 1b2c3d9.
Top 4 follow-ups
- [Test Coverage Expert] Open a dedicated issue: apm deny plus reinstall sets exec_status denied but leaves already-deployed hooks in .claude/settings.json, for ANY package (seen on a plain non-replaced package). -- This is a real revocation gap on a secure-by-default promise: a user who denies a package expects its hooks to stop running. It predates this PR and affects every package, not just replaced ones, so it is outside the scope record. The new deny lifecycle leg found it, and that leg should become the regression test for the fix.
- [Supply Chain Security Expert] Decide a policy for
apm approve --userwhen the resolved grant key is a local path (for example ./local-hooky): refuse it, or keep replacement grants project-scoped. -- A path-keyed user-scope grant can unlock any project's dependency at the same relative path. Path-keyed local trust predates this PR for plain local dependencies. The scope record covers resolving replaced dependencies, not user-scope trust policy. - [Python Architect] Narrow the bare package_name prefix match for non-replaced dependencies (require a '#' boundary or refuse ambiguous matches, for example acme/hook vs acme/hooky). -- This lookup behavior predates the PR. The scope record covers resolving replaced dependencies only. The fold already ranks this match last so it cannot beat an exact or lockfile match, which limits the risk until a separate change tightens it.
- [Python Architect] Remove the caller-supplied version parameter from locked_dependency_approval so the owner alone decides the full trust key. -- Removing it changes the grant key for non-replaced dependencies (approve currently binds the package apm.yml version). The scope record excludes 'approval key format for non-replaced deps'. It fails closed and is documented as the legacy approve override, so it can ship as its own key-format change with a CHANGELOG migration line.
Recommendation
Merge once CI on 1b2c3d9 is green; it was 31/31 at 4d99780 and the lint chain is silent. Every in-scope finding from both passes is folded with mutation-break evidence, and the Done-when is covered by an installed-CLI lifecycle test for local and fork replacements, including the deny leg. Before or alongside the merge, open a dedicated issue for the deployed-hook revocation gap on deny plus reinstall; it affects every package. Track the other three deferrals as post-merge follow-ups.
Folded in this run
- (panel) Owner returns the whole trust principal (
LockedApproval); approve.py no longer re-decides 'replaced' -- resolved in d5f4321. - (panel) Trust guard forbids a parallel locked-row derivation in approve.py; brittle owner-body tokens dropped; mutation test added -- resolved in d5f4321.
- (panel)
_find_declarationtyped and tiered: lockfile key / original identity beat a self-declared apm.yml name -- resolved in d5f4321. - (panel)
apm deny <original>on a replaced dependency also denies the original identity; lifecycle deny leg; fork key-tuple unit test -- resolved in d5f4321. - (panel) Trap for deny dropping an upstream allow; trap for
apm approve acme/hooky#1.0.0on a replaced row -- resolved in 1b2c3d9. - (panel) CHANGELOG entry shortened to main's one-line rule (docs(changelog): make 0.36.0 onwards legible and concise #3886) after merging main -- resolved in adf234d.
Copilot signals reviewed
- review 5909401294 -- NOT-LEGIT: Copilot could not review (requester quota); no inline items.
Deferred (out-of-scope follow-ups)
These cross the stated scope of this PR. Each suggests a separate follow-up.
- (panel)
apm deny+ reinstall leaves already-deployed hooks in.claude/settings.json(exec_status isdenied), for any package -- scope boundary: pre-existing revocation gap for every package, not replaced-dependency key routing; suggested follow-up: new type/bug issue. - (panel)
apm approve --userwriting a local-path key to user scope -- scope boundary: pre-existing path-keyed user trust policy, not replaced-dependency resolution. - (panel) Narrow the bare
package_nameprefix lookup for non-replaced packages -- scope boundary: pre-existing lookup semantics for non-replaced deps; now ranked last. - (panel) Drop the caller-supplied version from
locked_dependency_approval-- scope boundary: changes the approval key for non-replaced dependencies, listed out of scope in the scope record.
Regression-trap evidence (mutation-break gate)
test_approve_original_identity_beats_lookalike_package_name-- deleted the lockfile-first tier; test FAILED as expected; guard restored.test_deny_replaced_dependency_by_original_identity-- deleted the upstream deny write; test FAILED as expected; guard restored.test_approve_parallel_replacement_derivation_is_rejected-- deleted the forbidden-token check; test FAILED as expected; guard restored.test_locked_fork_replacement_keys_name_the_fork-- deleted the version-stripped key; test FAILED as expected; guard restored.test_deny_replaced_dependency_drops_upstream_allow-- deleted the upstreamallow.pop; test FAILED as expected; guard restored.test_approve_replaced_dependency_by_versioned_original_name-- deleted_original_prefix; test FAILED as expected; guard restored.
Lint contract
ruff check and ruff format --check (ruff 0.15.12 per uv.lock) silent on src/ tests/ and the scripts paths; pylint R0801 10.00/10; scripts/lint-auth-signals.sh clean; scripts/lint-architecture-boundaries.sh exit 0.
CI
gh pr checks 3742: 31 pass, 3 skipping, 0 failing at 1b2c3d9 (after 0 CI fix iteration(s)).
Exact-head functional evidence: APM_BINARY_PATH=.venv/bin/apm pytest tests/integration/test_executable_approval_replacement_lifecycle.py -p no:xdist 2 passed; approve/deny + executables unit + LSP architecture tests 178 passed.
Mergeability status
| PR | head SHA | CEO stance | iters | folds | defers | Copilot rounds | CI | mergeable | mergeStateStatus | notes |
|---|---|---|---|---|---|---|---|---|---|---|
| #3742 | 1b2c3d9 |
ship_with_followups | 2 | 6 | 4 | 1 | green | MERGEABLE | BLOCKED | pending required review |
Convergence
2 outer iteration(s); 1 Copilot round(s). Final panel verdict: ship_with_followups.
Ready for maintainer review.
Full per-persona findings
Python Architect
- [recommended] locked_dependency_approval still takes a version from the caller, so approve.py can still decide part of the trust key for a row that was not replaced at
src/apm_cli/security/executables.py:551
approve.py passes the version from the package's own apm.yml while locked_dependency_approval_keys uses the lockfile version. Pre-existing and fails closed (a mismatch does not match), but the PR writes this parallel input into the owner's public signature. Deferred (see Deferred above).
Suggested: Drop the version parameter, or document it as a legacy override and forbid other callers.
Supply Chain Security Expert
No findings.
Test Coverage Expert
- [recommended] No test checks that apm deny on a replaced dep removes an existing upstream allow entry. at
tests/unit/commands/test_approve_deny.py:509
Deleting the upstream allow.pop in deny_cmd passes every test; a leftover upstream allow would come back into force if the deny entry is later edited away. Resolved in 1b2c3d9.
Suggested: Seed allow with acme/hooky and ./local-hooky, deny acme/hooky, assert allow empty.
Proof (missing at):tests/unit/commands/test_approve_deny.py-- proves: Denying the declared name of a replaced dependency removes an old upstream grant. [secure-by-default,governed-by-policy] - [recommended] No test covers the versioned-original lookup tier: apm approve/deny acme/hooky#1.0.0 on a replaced dep. at
tests/unit/commands/test_approve_deny.py:552
The docstring promises acme/hooky#1.0.0 finds a replaced acme/hooky; dropping _original_prefix would fail no test. Resolved in 1b2c3d9.
Suggested: Add a test approving acme/hooky#1.0.0 and asserting the ./local-hooky grant.
Proof (missing at):tests/unit/commands/test_approve_deny.py-- proves: Approving a replaced dependency by its versioned declared name targets the selected source. [secure-by-default,devx]
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.
d547a5b
into
microsoft:main
Description
With a
replace:rule, the executable gate keys consent by the selectedwith:source, butapm approve acme/hookywrote a grant for the original identity, so hooks stayed parked. This PR (contributed by Mohammed Alkindi (@MohammedAlkindi), reworked in place by a maintainer with credit) makesapm approve,apm denyandapm policy explainfind a replaced dependency by its original or selected-source name and write the key the gate checks.Root cause and owner: the locked-row trust principal is now one function,
security/executables.locked_dependency_approval, which returns the whole answer (LockedApproval: identity, version, original identity). A replaced row routes throughdependency_approval_key, the same owner the install gate uses. The approve scanner and the MCP/LSP views (locked_dependency_approval_keys) share it, so an upstream grant never unlocks a replacement anywhere. The three duplicated declaration lookups incommands/approve.pyare now one typed helper,_find_declaration, which tries lockfile-derived names before a package's self-declaredapm.ymlname. Theinstall-deployment-executable-trust-contextguard requires the new routing and forbids a parallel derivation inapprove.py; mutation tests reject both.User-visible:
apm approve acme/hookyon a dependency replaced by../local-hookywrites../local-hooky(for a fork,my-org/hooky-fork#patched). The nextapm installdeploys the hooks. An existingacme/hookygrant still does not unlock the replacement.apm deny acme/hookydenies both the selected source andacme/hooky, so removing thereplace:rule does not revive an old grant.Issue and approved scope
Issue: Fixes #3710
Human scope-approval comment: #3710 (comment)
Does this PR complete the issue, or what remains? It completes the issue. The reporter's scenario is covered by
tests/integration/test_executable_approval_replacement_lifecycle.pyfor a local path and a fork.Type of change
Testing
Validation evidence (main merged at 420f937; head 1b2c3d9):
executables: {},acme/hookyreplaced by../local-hooky): afterapm approve acme/hookythe grant wasacme/hooky#1.0.0and the nextapm installstill printed "1 package(s) have executable primitives parked". On this branch the grant is../local-hookyand the next install prints "1 hook(s) integrated -> .claude/settings.json".APM_BINARY_PATH=.venv/bin/apm pytest tests/integration/test_executable_approval_replacement_lifecycle.py -p no:xdist: 2 passed (local path and fork; approve, explain, install, then deny re-gates).pytest tests/unit/commands/test_approve_deny.py tests/unit/security/test_executables.py tests/integration/test_architecture_lsp_plugin.py -p no:xdist: 178 passed.uvx [email protected] checkandformat --checkon src/ tests/ and the scripts paths: passed.pylint R0801: 10.00/10.bash scripts/lint-auth-signals.sh: clean.bash scripts/lint-architecture-boundaries.sh: exit 0.Spec conformance (OpenAPM v0.1)
docs/src/content/docs/specs/openapm-v0.1.mdupdated(new/changed
<a id="req-XXX"></a>anchor + prose + Appendix Crow).
docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.ymlupdated.
@pytest.mark.req("req-XXX")test undertests/spec_conformance/added or extended.CONFORMANCE.{md,json}regenerated viauv run --extra dev python -m tests.spec_conformance.gen_statementand committed.