Repository navigation
fix(approve): correct the remediation after apm deny - #3979
Daniel Meppiel (danielmeppiel) wants to merge 2 commits into
Conversation
- install --frozen names the executables gate for a denied server instead of 'no longer declared' or 'not approved'. - apm approve <pkg> lifts a deny in the store it writes, --all and --recommended skip denied packages, and a deny in another layer makes approve exit 1 naming that layer instead of reporting success. - apm deny --user and apm approve --user work outside a project and read the packages apm install -g installed. Closes #3957 apm-spec-waiver: CLI remediation wording and approve/deny store handling; no OpenAPM-observable manifest, lockfile or resolution behaviour changes. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Deny detection and key matching can incorrectly skip approvals or remove another artifact’s deny, while outside-project recovery hints recommend an install command that fails.
3 open issues
What changed in this PR
This PR addresses #3957 by correcting deny-related remediation across executable approvals, frozen installs, and user-scoped commands.
Changes:
- Distinguishes denied MCP servers from missing declarations in frozen-install diagnostics.
- Adds same-store deny clearing for named approvals, bulk-skip handling, and reporting of remaining denies.
- Enables
--userapproval and denial outside projects, with lifecycle tests and updated documentation.
| File | Description |
|---|---|
tests/integration/test_deny_remediation_lifecycle.py |
Adds lifecycle coverage for the three remediation flows. |
src/apm_cli/integration/mcp_config_view.py |
Adds deny-specific consent diagnostics. |
src/apm_cli/install/service.py |
Uses omission evidence in frozen-install messages. |
src/apm_cli/commands/approve.py |
Updates deny clearing, bulk approval, and outside-project handling. |
packages/apm-guide/.apm/skills/apm-usage/commands.md |
Updates command guidance for the revised behavior. |
docs/src/content/docs/reference/cli/install.md |
Documents denied-server frozen diagnostics. |
docs/src/content/docs/reference/cli/deny.md |
Documents user scope and lifting denies. |
docs/src/content/docs/reference/cli/approve.md |
Explains approval after denial and outside-project support. |
docs/src/content/docs/reference/baseline-checks.md |
Documents deny-specific audit diagnostics. |
CHANGELOG.md |
Records the user-visible remediation changes. |
Review effort: Balanced
| if user_scope: | ||
| from ..core.scope import InstallScope, get_manifest_path | ||
|
|
||
| return get_manifest_path(InstallScope.USER) |
| denied = _same_store_denies(deny, decl) | ||
| if denied and bulk: |
| keys = {decl.package_key, _identity(decl)} | ||
| return [key for key in deny if key in keys or _strip_version(key) in keys] |
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 1 | 2 | 2 | Good fix, but _same_store_denies forks the deny-key matching that _map_denies owns, and that can loop the remediation. |
| Test Coverage Expert | 0 | 2 | 2 | All 3 scope parts have lifecycle tests; gaps: spelling-variant denies loop, --recommended/org hint untested, no unit tier. |
| Devx Ux Expert | 0 | 3 | 2 | Printed fix commands can loop or do nothing (deny spelling mismatch, uninstalled packages); exit 1 hides that the store was written. |
| Doc Writer | 0 | 2 | 1 | Stale claims are gone; approve.md omits the project-deny layer and that exit 1 still writes the store. |
| Supply Chain Security Expert | 0 | 2 | 1 | No bypass found; lifting a deny should require an exact lockfile identity and match spellings like the gate. |
| Cli Logging Expert | 0 | 2 | 3 | Messages are clear and ASCII; a still-denied approve hides its write and ends on a green line; frozen wording inconsistent. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 5 follow-ups
- [Python Architect] (blocking-severity) Replace the exact/strip_version check in _same_store_denies with a shared matcher next to _map_denies in security/executables.py using canonical_exec_identity; skip glob and content-bound keys; add a mixed-case, URL-spelled deny regression test. -- Four personas found it; approve otherwise prints the command the user just ran, breaking scope item (2).
- [Test Coverage Expert] Add CliRunner unit tests: deny spelling variants lifted, --recommended/--all skip denied, org deny exits 1 naming the org layer, --user hint wording, the package_name lookalike case, and a still-denied approve that records and exits 1. -- Unit-tier evidence is missing on a governed-by-policy surface.
- [Supply Chain Security Expert] Lift a same-store deny only when the argument matches a lockfile-derived identity; for a package_name-only match keep the deny and print
apm approve <identity>. -- A lookalike package must not choose which deny is lifted. - [Devx Ux Expert] Make the still-denied path honest: "Recorded approval in ; is still denied () here: ", count recorded vs still denied, print [x] lines last, exit 1; document all three layers. -- An unexplained apm.yml diff after exit 1 is the real UX failure.
- [Devx Ux Expert] A named package that is not installed but matches a same-store deny: exit 1, name the deny, say to install first. -- Today it warns and exits 0, which is "without effect".
Architecture
classDiagram
direction LR
class approve_py {
<<CommandModule>>
+approve_cmd()
+deny_cmd()
-_find_manifest(user_scope) Path
-_record_and_save(..., bulk)
-_same_store_denies(deny, decl) list
-_still_denied(manifest, decls) list
-_lift_deny_hint(layer, identity) str
}
class executables_py {
<<CanonicalOwner>>
+resolve_exec_decision(ctx, key, type) ExecDecision
+canonical_exec_identity(key) str
-_map_denies(map, key, type) bool
-_strip_version(key) str
}
class trust_py {
<<CanonicalOwner>>
+package_type_verdicts() dict
+REASON_DENIED
}
class CurrentMcpConfigView {
+omissions dict
+consent_problems() dict
}
class InstallService {
-_frozen_mcp_reasons() list
}
approve_py ..> executables_py : deny matching
approve_py ..> trust_py : _verdicts
trust_py ..> executables_py : resolve_exec_decision
CurrentMcpConfigView ..> trust_py : REASON_DENIED
InstallService ..> CurrentMcpConfigView : omissions
class approve_py:::touched
class CurrentMcpConfigView:::touched
class InstallService:::touched
classDef touched fill:#fff3b0,stroke:#d47600
flowchart TD
A["apm approve [--user] pkg / --all / --recommended"] --> B["_find_manifest(user_scope)"]
B -->|cwd apm.yml| C["project apm.yml"]
B -->|missing and --user| D["APM_HOME/apm.yml"]
C --> E["_load_store allow, deny"]
D --> E
E --> F["_record_and_save(..., bulk)"]
F --> G{"_same_store_denies"}
G -->|denied and bulk| H["Skipped: denied"]
G -->|named| I["_record_declaration + pop same-store deny"]
I --> L["_save_store"]
L --> M["_still_denied via trust ctx"]
M -->|TRUST_DENIED| O["still denied (layer): hint; exit 1"]
M -->|admitted| P["Approved; exit 0"]
T["apm install --frozen"] --> Y["consent_problems: gate now parks it (denied)"]
Recommendation
The core fix is right and has no security regression. Before merge, fold the shared canonical deny-key matcher (the blocking item), the unit-tier tests, the lockfile-identity requirement for lifting a deny, the honest "recorded but still denied" output and docs, and exit 1 for a denied package that is not installed. All of these are within #3957's scope. Track the trust.py wording consolidation, CommandLogger migration and --user org-deny visibility separately.
Full per-persona findings
Python Architect
- [blocking] _same_store_denies adds a second deny-key matcher that disagrees with _map_denies/canonical_exec_identity, so a deny can survive apm approve and the hint loops at
src/apm_cli/commands/approve.py:807 - [recommended] The still-denied check runs after _save_store, so exit 1 still leaves a persisted allow and a lifted same-store deny at
src/apm_cli/commands/approve.py:769 - [recommended] Deny remediation text is spread over several sites; route it through one helper in security/trust.py at
src/apm_cli/commands/approve.py:834 - [nit] install/service.py inspects raw omission evidence instead of asking CurrentMcpConfigView at
src/apm_cli/install/service.py:647 - [nit] _still_denied keeps only layers[0] and filters successes with id() plus zip at
src/apm_cli/commands/approve.py:815
Cli Logging Expert
- [recommended] Still-denied approve prints [x] before [+] and the Updated line; silent about the write when all are still denied at
src/apm_cli/commands/approve.py:774 - [recommended] Frozen 'now left out ()' shows a raw reason token and no fix at
src/apm_cli/install/service.py:651 - [nit] Skipped-denied line fits _rich_warning better than _rich_info at
src/apm_cli/commands/approve.py:748 - [nit] Org-layer hint reads awkwardly at
src/apm_cli/commands/approve.py:841 - [nit] New lines bypass CommandLogger at
src/apm_cli/commands/approve.py:771
Devx Ux Expert
- [recommended] Still-denied hint can loop: approve only clears exact-spelling denies at
src/apm_cli/commands/approve.py:807 - [recommended] apm approve cannot lift a deny on a not-installed package: warns and exits 0 at
src/apm_cli/commands/approve.py:531 - [recommended] Exit 1 hides that the store was changed at
src/apm_cli/commands/approve.py:775 - [nit] Org-deny hint lacks a command at
src/apm_cli/commands/approve.py:834 - [nit] Bulk approve exits 0 with no summary when everything skipped
Supply Chain Security Expert
- [recommended] A named approve can lift a deny for a package matched only by the name in its own apm.yml at
src/apm_cli/commands/approve.py:745 - [recommended] _same_store_denies matching is narrower than the gate; some denies can never be lifted (fails closed) at
src/apm_cli/commands/approve.py:807 - [nit] --user outside a project probably cannot see an org deny in _still_denied at
src/apm_cli/commands/approve.py:272
Doc Writer
- [recommended] approve.md omits the project-deny layer and that the approval is saved before exit 1 at
docs/src/content/docs/reference/cli/approve.md:156 - [recommended] "Naming a package lifts its deny" fails for differently spelled deny keys at
src/apm_cli/commands/approve.py:807 - [nit] CHANGELOG line does not name the commands --user applies to at
CHANGELOG.md:45
Test Coverage Expert
- [recommended] No test for deny keys stored under URL, host-qualified, or different-case spellings at
src/apm_cli/commands/approve.py:807
Proof (missing at):tests/unit/commands/test_approve_deny.py - [recommended] No test for the --recommended skip, the org-deny hint, or --user hint wording at
src/apm_cli/commands/approve.py:747
Proof (missing at):tests/unit/commands/test_approve_deny.py - [nit] No test for the service.py 'now left out ()' branch at
src/apm_cli/install/service.py:651 - [nit] Approval-saved-on-exit-1 and replace: original_identity deny survival are not asserted at
tests/integration/test_deny_remediation_lifecycle.py:85
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.
* fix(lockfile): stamp the running APM on every substantive lock write (#3962) Harvested from #3977. Co-authored-by: Copilot App <[email protected]> * fix(bundle): warn when a bundle's lockfile was written by a newer APM (#3963) Harvested from #3978. Co-authored-by: Copilot App <[email protected]> * fix(marketplace): origin-check every marketplace resolution entry point (#3959) Harvested from #3976; the positional install reads the lock lazily. Co-authored-by: Copilot App <[email protected]> * fix(install): preview object-form marketplace dependencies in --dry-run (#3960) Harvested from #3973. Co-authored-by: Copilot App <[email protected]> * fix(prune): keep object-form marketplace dependencies (#3960) Harvested from #3974. Co-authored-by: Copilot App <[email protected]> * fix(install): retire a local bundle's MCP servers when a reinstall drops them (#3956) Harvested from #3975. Co-authored-by: Copilot App <[email protected]> * fix(update,audit): honour the current executables decision after apm deny (#3958) Harvested from #3981. Co-authored-by: Copilot App <[email protected]> * fix(approve): correct the remediation after apm deny; approve clears a same-store deny (#3957) Harvested from #3979. Co-authored-by: Copilot App <[email protected]> * fix(approve): match package names exactly and refuse ambiguous names A partial name could grant or deny execution for another package. Co-authored-by: Copilot App <[email protected]> * fix(pack): never ship APM-managed root .mcp.json servers (#3966) Harvested from #3971. Co-authored-by: Copilot App <[email protected]> * fix(install): the trust owner reads the scope manifest, so -g honours executables: (#3954) exec_trust_context_for_project takes the manifest file instead of deriving apm.yml from a caller-chosen root; -g resolves APM_HOME/apm.yml through core.scope.get_manifest_path. A closed-world guard registers every caller. Supersedes #3969 and keeps its lifecycle test. Co-authored-by: Copilot App <[email protected]> * fix(deps): deps update and lock --update revalidate marketplaces (#3961) Every caller of the shared install entry now runs inside a registered catalog-freshness envelope; the guard is closed-world. Co-authored-by: Copilot App <[email protected]> * fix(lifecycle): lifecycle test --execute fires through the script gate APM_NO_SCRIPTS, org executables.deny_all and project script trust now apply; LifecycleScriptRunner is built only by build_runner_from_context, guarded closed-world by the new lifecycle-script-firing-gate owner. Co-authored-by: Copilot App <[email protected]> * test(approve): exact and unambiguous approve/deny matching Co-authored-by: Copilot App <[email protected]> * fix(pack): root .mcp.json reads exclude APM-managed servers by default (#3966) The only opt-out is a dependency's own authored .mcp.json; a closed-world guard refuses any other. Co-authored-by: Copilot App <[email protected]> * test(architecture): a bundle reinstall must reconcile its owned MCP servers (#3956) Co-authored-by: Copilot App <[email protected]> * test(architecture): guard object-form lock-row mapping and exact approve matching Co-authored-by: Copilot App <[email protected]> * fix(update): read packages as replay does; skip the policy fetch when the gate was never on (#3958) Harvested from #3981 (b4cface, cb015e6); the trust read uses the scope manifest. Co-authored-by: Copilot App <[email protected]> * fix(install): -g MCP admission reads trust from APM_HOME/apm.yml (#3954) Harvested from #3969 (5c2cab2). Co-authored-by: Copilot App <[email protected]> * fix(targets): apm targets honours targets: in apm.yml (#3792) Reads the manifest restriction through the same owner install uses. Co-authored-by: Copilot App <[email protected]> * fix(cli): user-facing text names current keys, targets and marketplaces - compile's no-output hint names targets:, not the deprecated target: - pack's mismatch hint no longer suggests the deprecated pack --target - skip messages name executables.allow instead of allowExecutables - origin and freshness errors say marketplace, not catalog - generated apm.yml headers and unknown-target errors stop listing vscode - config docs show default_client: copilot Co-authored-by: Copilot App <[email protected]> * docs(changelog): 0.37 owner hardening entries; ruff fixes apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> * docs(changelog): reference #3988 apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> * fix(update): converge the mixed-type reconcile; pin probe boundaries Harvested from #3981 (6cd7b3a, delta panel fold). Only a denied row with mixed per-type verdicts reconciles, so common partial approvals keep the no-change short-circuit; the probe catches only unreadable-package errors instead of every exception. Tests pin when the probe fetches policy, mixed detection on a two-type package, and every unavailable policy outcome. Test calls pass the scope manifest path, per #3988's trust-owner signature. Refs #3958 apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: danielmeppiel <[email protected]> Co-authored-by: Copilot App <[email protected]> * test: align tests with the 0.37 contracts this PR introduces CI on 913336a was red on tests that encoded the pre-#3983 contracts: - lifecycle test --execute now fires through the script gate, so the firing test trusts the project first and the old bypass trap now asserts untrusted scripts are withheld (mutation-break: restoring an ungated LifecycleScriptRunner fails it); - codex native admission names executables.allow, not allowExecutables; - a real LockFile.write stamps the running CLI (#3962), so the heal eligibility fixture pins the stamp it means to write; - pack no longer ships servers apm install renders from apm.yml (#3966), so the bundle MCP retire test authors its server in .mcp.json. Addresses merge-worker CI triage on #3988. apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> * fix(uninstall): origin-check marketplace rows from the batch index require_locked_catalog_origin rescanned lockfile.dependencies for every package, breaking the uninstall single-traversal guarantee. The batch index now also keys rows case-insensitively, and the registry fallback checks each matched row through require_locked_row_origin before any catalog I/O. Adds a rebound-alias regression test (mutation-break: dropping the check lets the catalog be reached) and moves the origin entry-point guard and its mutation case to the new call. Refs #3959 apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> * fix(pack): warn when root .mcp.json servers APM manages are left out A Claude plugin silently lost the MCP servers apm install renders from apm.yml. Pack now names them and the remedy; the CHANGELOG moves the #3966 line to upgrade notes with that migration, pack.md and apm-usage say the same, and the unrelated #3931 line this PR dropped is restored. Addresses panel follow-ups (supply-chain, doc-writer) on #3988. apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> * fix: fold Copilot review on trust and origin owners - install x@alias reads a legacy apm.lock for the origin check, through the read-only lockfile resolver, so a rebound alias fails closed before migration (Copilot on commands/install.py:220); - the update probe reuses POLICY_RESOLUTION_FAILURE_OUTCOMES, so an incomplete policy chain also forces the guarded install path (Copilot on commands/update.py:148); - apm approve clears a same-store deny stored under any spelling the deny ladder matches (URL, host, case), via canonical_exec_identity (Copilot on commands/approve.py:817). Each fix has a regression test proven by mutation-break. Refs #3957, #3958, #3959 apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> * fix(targets): singular target: all lists the install set as active restriction() folds singular `target: all` to None (auto-detect), but install expands it to the stable install set, so apm targets showed every target inactive. Expand it through target_catalog.expand_all("install"). Regression test proven by mutation-break. Addresses Copilot on commands/targets.py:32. Refs #3792 apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> * perf: share one marketplace index across dry-run and prune lookups locked_marketplace_row and locked_marketplace_form were called per declaration without an index, so LockFile.get_dependency rebuilt the marketplace index each time (O(M*N)). Both callers now build it once, as the reachability walk already does. Addresses Copilot on install/dry_run_plan.py:33 and install/orphans.py:46. Refs #3960 apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> * test(architecture): track the shared marketplace index in mutation cases The object-form mutation cases match the exact call text, which now passes the shared marketplace index. Co-authored-by: Copilot App <[email protected]> * fix(pack): ship apm.yml MCP declarations; only root claims hide root entries Red team qa-prA-5 and qa-prA-6 on #3988, both regressions against main: - A Claude bundle and plugin.json dropped the producer's own apm.yml MCP servers: they were read only from the rendered root .mcp.json, which pack now withholds. collect_mcp_servers projects the root manifest's self-defined declarations from apm.yml values (never the rendered copy), through the existing credential stripping, so output is byte-identical before and after apm install. The pack warning remains only for APM-managed servers apm.yml does not define (a dependency's). - apm_managed_mcp_names unioned lock claims from every runtime, so a Cursor-only claim on `docs` hid an authored root `docs` from Claude and Codex. Only claims whose runtime writes root .mcp.json count, read through the factory (ClientFactory.project_destination_is_root_mcp_json, side-effect free); unknown runtimes and unplaced aggregate names stay managed (conservative). The new unit tests fail on e9d6c9d and pass here; the bundle-retire lifecycle test is back to its apm.yml declaration; test_pack_mcp_ownership asserts byte identity, no header or secret values and no reference to the rendered file; the pack guard requires both owner rules, with a standalone mutation test. CHANGELOG, pack.md and apm-usage updated. apm-spec-waiver: consistency fixes route callers through existing owners; no new or changed normative requirement Co-authored-by: Copilot App <[email protected]> --------- Co-authored-by: danielmeppiel <[email protected]> Co-authored-by: Copilot App <[email protected]>
…a same-store deny (microsoft#3957) Harvested from microsoft#3979. Co-authored-by: Copilot App <[email protected]>

Description
Fixes the remediation users get after
apm deny. Before this PR it was wrong on every surface:--frozenwording. A denied server the lock still admits now fails withadmitted in apm.lock.yaml but the executables gate now parks it (denied); see 'apm policy explain <pkg>' .... Before, it said "no longer declared in apm.yml", and with feat(security): portable, content-pinned approval for dependency executables (#3902) #3918 it said "not approved". A lock-only name that carries gate omission evidence now printsis now left out (<reason>), never "no longer declared".apm approveafter a deny. Naming a package lifts its deny in the store being written (Cleared deny for <pkg>), the mirror ofapm denydropping the matching allow.--alland--recommendedskip denied packages instead of lifting them. If a deny in another layer (--useror org) still blocks the package, approve exits 1, names that layer, and says how to lift it. It never prints "Approved" without effect.--useroutside a project.apm deny --userandapm approve --userno longer fail with "No apm.yml found". Outside a project they read the packagesapm install -ginstalled (APM_HOME) and write only$APM_HOME/config.json.Docs for approve, deny, install, baseline-checks and the apm-usage skill are updated.
Issue and approved scope
Issue: Fixes #3957
Human scope-approval comment: the newest (superseding) apm-scope:v1 record on #3957 (Review contact: Daniel Meppiel (@danielmeppiel)).
Does this PR complete the issue, or what remains? It completes all three parts. Deny semantics are otherwise unchanged.
Type of change
Testing
Validation evidence:
tests/integration/test_deny_remediation_lifecycle.pyhas three tests, one per scope part.test_frozen_names_the_gate_and_approve_lifts_a_project_denypassed locally.still denied (user-deny) ... apm approve --user ./pkgs/tools, anddeny --useroutside a project exits 0 and writesconfig.json.deny --userfails with "No apm.yml found".pytest tests/unit/commands/test_approve_deny.py tests/unit/integration/test_mcp_config_view.py tests/unit/integration/test_frozen_mcp_evidence.py tests/spec_conformance/test_portable_mcp_approval_reqs.py tests/unit/security -n 8: 400 passed.ruff check/ruff format --check(ruff 0.15.12, as pinned inuv.lock): clean.Changelog
## [Unreleased]inCHANGELOG.md.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regenerated