Repository navigation
fix(audit): name a runnable remedy for a failed dependency-allowlist check - #4596
Daniel Meppiel (danielmeppiel) merged 42 commits into
Conversation
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Remediation advice can produce unsafe shell commands and recommend removals that leave denied packages installed or violate required-package policy.
5 open issues
Render package selectors safely in remediation commands · New Use the current manifest to identify direct dependencies · New Verify uninstall removes every path to denied dependencies · New Validate uninstall selectors against current declarations · New Preserve required packages in uninstall recommendations · New
What changed in this PR
This PR addresses #4570 by adding catalog-owned remediation advice to failed apm audit --ci dependency-allowlist checks, including guidance for dependencies brought in transitively.
Changes:
- Adds an uninstall-or-admin remedy that names direct dependency entries and the policy source.
- Carries next-step advice through text output, structured-output stderr, and SARIF messages.
- Adds regression coverage and updates lifecycle evidence, documentation, and the changelog.
| File | Description |
|---|---|
tests/unit/policy/test_dependency_allowlist_next_step.py |
Tests dependency selection, advice rendering, and SARIF messages. |
tests/unit/core/test_remediation_w4_frozen_policy_catalog.py |
Links the catalog entry to lifecycle proof. |
tests/quality/generated_obligations.json |
Records E01 remediation coverage and removes its known-failure entry. |
tests/lifecycle/journeys/goldens/E01/04.txt |
Adds the expected remedy line. |
tests/lifecycle/journeys/enterprise/E01-org-policy-rollout.yaml |
Runs the remedy and checks subsequent audits pass. |
tests/fixtures/lifecycle_bug_ledger.json |
Records #4570 and its regression tests. |
src/apm_cli/policy/policy_checks.py |
Attaches advice and traces denied dependencies to direct roots. |
src/apm_cli/policy/models.py |
Adds next_step and appends it to SARIF messages. |
src/apm_cli/integration/mcp_config_view.py |
Exposes the existing direct-dependency tracer for reuse. |
src/apm_cli/core/remediation.py |
Defines and renders the allowlist remedy. |
src/apm_cli/commands/audit.py |
Passes the policy source and displays next-step advice. |
docs/src/content/docs/enterprise/enforce-in-ci.mdx |
Updates the audit example and troubleshooting guidance. |
CHANGELOG.md |
Documents the user-visible audit remediation change. |
Review effort: Balanced
Co-authored-by: Copilot App <[email protected]>
f9c760e to
915d1a5
Compare
Co-authored-by: Copilot App <[email protected]>
d00ec9b to
47bc8cd
Compare
…check (#4570) Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
apm-spec-waiver: audit remediation text only; no OpenAPM-observable manifest, lockfile, resolver or policy semantics change (#4570) Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
…4570) Review follow-up: select each entry through the uninstall selection owner as a shell-safe word, judge directness from the current apm.yml, prove through the orphan owner that the uninstall drops every denied dependency and that no survivor still reaches one, and never remove a required package; otherwise the advice is admin-only. Co-authored-by: Copilot App <[email protected]>
Rebased onto main 2de15af: the #4570 bug-ledger row moves to tests/fixtures/lifecycle_bug_ledger/bugs/4570.json (per-row ledger, #4583), and the two [Unreleased] bullets become one fragment (#4599). Co-authored-by: Copilot App <[email protected]>
47bc8cd to
7579c08
Compare
…cy-allowlist c Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved findings identify quadratic dependency selection and uninstall advice that can remove required replacements or leave denied transitive lock entries behind when no live module tree exists.
3 open issues
5 resolved since last review
Review effort: Balanced
…fuse an edited file (#4570) Review follow-up on #4725: the graph-only proof could advise 'apm uninstall <pkg>' for a package with an edited deployed file, which uninstall's deployment-evidence preflight refuses. Check the deletions through DeploymentEvidence (the owner uninstall uses) and fall back to the admin-only advice; regression test included. Co-authored-by: Copilot App <[email protected]>
The audit's dependency-allowlist next step moves beside the uninstall proof it uses, so policy_checks.py stays within its line budget after merging main. Behaviour is unchanged. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
… after merging main main's MCP survivor cleanup imported the helper's old private name from the uninstall engine; this branch moved it to local_survivors. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
A path-projection failure for a denied dependency’s symlinked checkout escapes exception handling, causing optional advice generation to abort the CI audit instead of reporting checks and falling back to admin-only advice.
1 open issue
2 resolved since last review
Review effort: Balanced
…_modules The install-path projection for the uninstall advice ran before the guarded orphan decisions, so a denied dependency whose checkout is a symlink outside apm_modules raised PathTraversalError and aborted `apm audit --ci`. The projection now sits inside the same guard: the check is reported and the advice falls back to the org admin. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The uninstall command repeats all denied-dependency selectors in every SARIF result, causing quadratic report-size and serialization-memory growth for large allowlist failures.
1 open issue
1 resolved since last review
Review effort: Balanced
The remedy names every denied selector, and SARIF appended it to each per-dependency result, so report size grew quadratically with the number of denied dependencies. It now goes once per failed check, on the check's last result; a single-dependency failure renders as before. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…wner The cell patched shrink_path_split on uninstall/cli.py, where this branch no longer computes deletion candidates (selection_shrink owns them). It now patches the owner's collaborator and asserts the shared local-bundle path never becomes a candidate. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…p to trace The advice walk maps a denied dependency to its declared roots through a recursive tracer; a chain deeper than the interpreter's recursion limit (possible when dependencies.max_depth is raised) raised RecursionError and aborted the audit. That walk now falls back to admin-only advice, like every other unprovable uninstall. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because a critical containment-validation gap can produce an uninstall recommendation that is refused, leaving the allowlist failure unresolved.
No open issues 🎉
1 resolved since last review
Review effort: Balanced

Description
TL;DR — When
apm audit --cifails thedependency-allowlistcheck, it now prints one runnable next step in text mode, on stderr for-f sarif|json, and in each SARIF result message. The step comes from a new remediation catalog entry:apm uninstallfor theapm.ymlentries that bring in the denied dependencies, or ask the org admin to allow them, naming the policy source. Following it makes the nextapm audit --ci --policy orgpass. This change touches only remediation text. Check outcomes, exit codes and policy semantics stay the same.Closes #4570
Problem. Lifecycle journey E01 step 4 (org policy switched to
enforcement: block, fresh CI runner) printed only this:The output had no
apm ...command to run and did not say which policy denied the dependency. Journey cellJ|E01|4|O8(invariant I3, remediation truth) was a strict known failure. The denied dependency is transitive (brought in bymicrosoft/apm-sample-package), soapm uninstall <denied ref>would fail with "not found in apm.yml". A runnable remedy has to name the direct entry.Now:
Important
Dependency order: lands after #4001, which adds an '[i] Policy: -- enforcement=...' line to audit --ci text output and regenerates E01/03. If #4001 lands first, rebase and regenerate E01 goldens (regen_goldens.py E01).
Issue and approved scope
Issue: Closes #4570
Human scope-approval comment: #4570 (comment) (
apm-scope:v1, Decision: approve, review contact Daniel Meppiel (@danielmeppiel))This PR completes the issue. All "Done when" items are covered: the journey cell passes and fails on base, the golden was regenerated with
regen_goldens.py, a unit test pins the catalog entry and its rendering for one and several dependencies, other checks' remedies are unchanged, and there is one Fixed line.Implementation
src/apm_cli/core/remediation.pyDEPENDENCY_NOT_ALLOWED(apm uninstall {packages}, in the W4 frozen-policy block) anddependency_not_allowed_advice(), which renders the sentence for one or several dependencies, with the admin alternative and policy source. All advice text stays in the catalog owner.src/apm_cli/policy/policy_checks.py_with_allowlist_next_step()runs only inrun_policy_checks, the audit wrapper, so the install gate is unchanged. It renders the catalog advice.run_policy_checksgainspolicy_source=(redacted with_redact_policy_ref).src/apm_cli/policy/allowlist_remedy.py(new; ownerremediation-advice)apm uninstall <entries>only when it can prove all of the following; otherwise the advice is admin-only:1. Each entry has a shell-safe selector that
select_manifest_dependencymaps to exactly that apm.yml declaration.2. Directness comes from the current apm.yml; transitive packages map to their direct roots via
DirectDependencyIndex.3. The orphan owner (
decide_orphan_removal,UNINSTALLandINSPECT) shows the uninstall drops every denied package and no surviving package still reaches one.4. No removal drops a package listed in
dependencies.require.src/apm_cli/integration/mcp_config_view.py_DirectDependencyIndexis renamed to publicDirectDependencyIndex, so the existing lock-parent tracer is reused, not duplicated.src/apm_cli/policy/models.pyCheckResult.next_step(rendered sentence). SARIF appends it to each result message. JSON already serializesremediations.src/apm_cli/commands/audit.pyfetch_result.source._render_ci_results(Rich table and plain fallback) and_render_ci_failures_to_stderrprintcheck.next_stepfor failed checks. The command layer composes no advice strings.remediate+rerun, and its known cell is removed. GoldenE01/04.txtis regenerated andgenerated_obligations.jsonis rewritten withpython -m tests.lifecycle.witnesses --write. Also: catalog proof-level entry, bug-ledger row,enforce-in-ci.mdxexample and fix table, and CHANGELOG.Trade-offs
next_stepfield instead of renderingremediationsfor every check. Checks such aslockfile-existsalready put their remedy inmessage, so renderingremediationsgenerically would print those remedies twice. The new field is opt-in, which keeps other checks' remedies unchanged (as the scope requires).apm uninstallonly acceptsapm.ymlentries or direct lock keys). It follows thedeclared_byprecedent for transitive MCP servers.apm uninstallthat would leave the audit red.apm uninstall a b cnaming each entry, instead of "first plus a count".apm uninstalltakesPACKAGES..., so naming every entry keeps a single command that clears everything.CheckResultcarries no next step, so the E01 step 3 docs output still matches.Type of change
Testing
Scenario evidence
apm audit --ci --policy org(text and SARIF) greentests/lifecycle/journeys/test_journeys.py::test_journey[E01](cellJ|E01|4|O8)tests/unit/policy/test_dependency_allowlist_next_step.py::test_one_denied_dependency_names_it_and_the_policy_sourceapm.ymlentry once...::test_several_denied_dependencies_name_each_entry_that_brings_them_in...::test_unproven_uninstall_falls_back_to_the_admin(3 cases)...::test_sarif_carries_the_next_step_and_other_checks_are_unchangedValidation commands and results
How to test
pytest "tests/lifecycle/journeys/test_journeys.py::test_journey[E01]"withAPM_BINARY_PATHset to the in-treeapm.pytest tests/unit/policy/test_dependency_allowlist_next_step.py.tests/lifecycle/journeys/goldens/E01/04.txt. It adds exactly one line, the next step.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 [email protected]