Skip to content

fix(audit): name a runnable remedy for a failed dependency-allowlist check - #4596

Merged
Daniel Meppiel (danielmeppiel) merged 42 commits into
mainfrom
danielmeppiel-p1-4570-audit-allowlist-remedy
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 42 commits into
mainfrom
danielmeppiel-p1-4570-audit-allowlist-remedy

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Description

TL;DR — When apm audit --ci fails the dependency-allowlist check, 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 uninstall for the apm.yml entries that bring in the denied dependencies, or ask the org admin to allow them, naming the policy source. Following it makes the next apm audit --ci --policy org pass. 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:

[x] dependency-allowlist: 1 dependency(ies) not in allow list
    - github.com/github/awesome-copilot/skills/review-and-refactor: not in allowed sources
[x] 1 of 16 check(s) failed

The output had no apm ... command to run and did not say which policy denied the dependency. Journey cell J|E01|4|O8 (invariant I3, remediation truth) was a strict known failure. The denied dependency is transitive (brought in by microsoft/apm-sample-package), so apm uninstall <denied ref> would fail with "not found in apm.yml". A runnable remedy has to name the direct entry.

Now:

[x] dependency-allowlist: 1 dependency(ies) not in allow list
    - github.com/github/awesome-copilot/skills/review-and-refactor: not in allowed sources
    Run 'apm uninstall microsoft/apm-sample-package' to remove the dependency outside the org allow list, or ask your org admin to allow it (policy source: org:contoso/.github).
[x] 1 of 16 check(s) failed

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

File Change
src/apm_cli/core/remediation.py New entry DEPENDENCY_NOT_ALLOWED (apm uninstall {packages}, in the W4 frozen-policy block) and dependency_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 in run_policy_checks, the audit wrapper, so the install gate is unchanged. It renders the catalog advice. run_policy_checks gains policy_source= (redacted with _redact_policy_ref).
src/apm_cli/policy/allowlist_remedy.py (new; owner remediation-advice) Offers 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_dependency maps 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, UNINSTALL and INSPECT) 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 _DirectDependencyIndex is renamed to public DirectDependencyIndex, so the existing lock-parent tracer is reused, not duplicated.
src/apm_cli/policy/models.py CheckResult.next_step (rendered sentence). SARIF appends it to each result message. JSON already serializes remediations.
src/apm_cli/commands/audit.py Passes fetch_result.source. _render_ci_results (Rich table and plain fallback) and _render_ci_failures_to_stderr print check.next_step for failed checks. The command layer composes no advice strings.
tests / docs Journey E01 step 4 gains remediate + rerun, and its known cell is removed. Golden E01/04.txt is regenerated and generated_obligations.json is rewritten with python -m tests.lifecycle.witnesses --write. Also: catalog proof-level entry, bug-ledger row, enforce-in-ci.mdx example and fix table, and CHANGELOG.

Trade-offs

  • A separate next_step field instead of rendering remediations for every check. Checks such as lockfile-exists already put their remedy in message, so rendering remediations generically would print those remedies twice. The new field is opt-in, which keeps other checks' remedies unchanged (as the scope requires).
  • Transitive dependencies name the direct entry instead of the denied ref. This keeps the command runnable (apm uninstall only accepts apm.yml entries or direct lock keys). It follows the declared_by precedent for transitive MCP servers.
  • Fail toward the admin step. When the uninstall cannot be proven to clear the failure (shared or diamond dependency, stale lock depth, required package, ambiguous or unsafe selector, incomplete reachability walk), the advice names only the org admin and the policy source. It never prints an apm uninstall that would leave the audit red.
  • Several denied dependencies produce one apm uninstall a b c naming each entry, instead of "first plus a count". apm uninstall takes PACKAGES..., so naming every entry keeps a single command that clears everything.
  • Warn mode is unchanged. Its downgraded CheckResult carries no next step, so the E01 step 3 docs output still matches.

Type of change

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

Testing

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

Scenario evidence

Scenario (user promise) Principle Proof
A red allowlist audit prints a runnable remedy, and running it turns the next apm audit --ci --policy org (text and SARIF) green I3 remediation truth tests/lifecycle/journeys/test_journeys.py::test_journey[E01] (cell J|E01|4|O8)
One denied dependency: catalog entry, rendered stderr line and JSON remediation pinned single owner of advice tests/unit/policy/test_dependency_allowlist_next_step.py::test_one_denied_dependency_names_it_and_the_policy_source
Several denied dependencies, including a transitive one, name each apm.yml entry once runnable remedy ...::test_several_denied_dependencies_name_each_entry_that_brings_them_in
An unproven uninstall falls back to admin-only advice: the removal would drop a required package, a surviving package still reaches the denied one, or a denied package is declared while its lock row is still transitive review threads: required package, shared dependency, stale lock depth ...::test_unproven_uninstall_falls_back_to_the_admin (3 cases)
SARIF carries the step; another failed check's SARIF and stderr lines are unchanged text and SARIF agree ...::test_sarif_carries_the_next_step_and_other_checks_are_unchanged
Validation commands and results
# failing-before: updated journey run against base src/ (git checkout HEAD~1 -- src/)
env -u GIT_EXEC_PATH PATH=/usr/bin:/bin:$PATH APM_BINARY_PATH=$PWD/.venv/bin/apm \
  .venv/bin/python -m pytest "tests/lifecycle/journeys/test_journeys.py::test_journey[E01]" -n 0 -p no:cacheprovider -q
E   O8: advice 'apm uninstall microsoft/apm-sample-package' is not printed
1 failed in 56.67s

# passing-after (same command on this branch)
1 passed in 80.06s

# golden regenerated with repo tooling
.venv/bin/python tests/lifecycle/journeys/regen_goldens.py E01
1 passed, 28 deselected in 81.22s
+    Run 'apm uninstall microsoft/apm-sample-package' to remove the dependency outside the org allow list, or ask your org admin to allow it (policy source: org:contoso/.github).
[+] 1 golden(s) written

# neighbours
.venv/bin/python -m pytest tests/unit/policy tests/unit/core tests/unit/commands/test_audit_error_handling.py \
  tests/unit/test_audit*.py tests/unit/*/test_audit*.py tests/quality/test_lifecycle_bug_ledger.py \
  tests/quality/test_promise_obligations.py tests/quality/test_generated_obligations.py -q
4280 passed (ledger nodeid fixed and test_lifecycle_bug_ledger.py rerun: 2 passed)

# lint contract (after merging current main)
uvx [email protected] check / format --check (src tests scripts...)   -> All checks passed / 2992 files already formatted
python -m pylint --disable=all --enable=R0801 ...                -> 10.00/10
bash scripts/lint-auth-signals.sh                                 -> [+] auth-signal lint clean
python scripts/check_complexity_ratchet.py --base-ref <main>      -> [+] complexity ratchet clean
python -m tests.quality.taxonomy --changed                        -> [+] tm006: 2 changed test module(s) carry their marker and promise
python scripts/lint_architecture_boundaries.py --root .           -> rc=0

How to test

  • pytest "tests/lifecycle/journeys/test_journeys.py::test_journey[E01]" with APM_BINARY_PATH set to the in-tree apm.
  • pytest tests/unit/policy/test_dependency_allowlist_next_step.py.
  • Check tests/lifecycle/journeys/goldens/E01/04.txt. It adds exactly one line, the next step.

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 (audit remediation text only).

Co-authored-by: Copilot [email protected]

Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) marked this pull request as ready for review November 21, 2026 11:22
Copilot AI balanced review requested due to automatic review settings November 21, 2026 11:22

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

Remediation advice can produce unsafe shell commands and recommend removals that leave denied packages installed or violate required-package policy.

5 open issues
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

Comment thread src/apm_cli/core/remediation.py Resolved
Comment thread src/apm_cli/policy/policy_checks.py Resolved
Comment thread src/apm_cli/policy/policy_checks.py Resolved
Comment thread src/apm_cli/policy/policy_checks.py Resolved
Comment thread src/apm_cli/policy/policy_checks.py Resolved
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the danielmeppiel-p1-4570-audit-allowlist-remedy branch from f9c760e to 915d1a5 Compare November 21, 2026 11:49
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the danielmeppiel-p1-4570-audit-allowlist-remedy branch from d00ec9b to 47bc8cd Compare November 21, 2026 13:10
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]>
…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]>

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

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

Comment thread src/apm_cli/policy/allowlist_remedy.py Resolved
Comment thread src/apm_cli/policy/allowlist_remedy.py Resolved
Comment thread src/apm_cli/policy/policy_checks.py Resolved
…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]>

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.

🟢 Approval recommended

No active review issues remain for the dependency-allowlist remediation changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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]>

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

Active findings show uninstall advice can select the wrong host or overlook a final-symlink cleanup refusal, causing uninstall to fail and leave the allowlist violation unresolved.

2 open issues

Review effort: Balanced

Comment thread src/apm_cli/policy/allowlist_remedy.py Resolved
Comment thread src/apm_cli/policy/allowlist_remedy.py Resolved
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

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

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

Comment thread src/apm_cli/policy/allowlist_remedy.py Resolved
…_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]>

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

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

Comment thread src/apm_cli/policy/models.py Resolved
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]>

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.

🟢 Approval recommended

No active review issues block approval of the dependency-allowlist guidance change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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]>

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

The uncaught recursive advice walk can raise RecursionError on deep dependency chains, aborting the audit before it emits a check report instead of falling back to admin-only advice.

1 open issue

Review effort: Balanced

Comment thread src/apm_cli/policy/allowlist_remedy.py Resolved
…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]>

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.

🔵 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

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.

[BUG] apm audit --ci: a failed dependency-allowlist check prints no runnable next step

2 participants