Skip to content

feat(policy): judge local bundles against dependencies.allow by their recorded packages - #4677

Closed
Daniel Meppiel (danielmeppiel) wants to merge 5 commits into
mainfrom
danielmeppiel-p1-4646-bundle-allow-policy
Closed

Daniel Meppiel (danielmeppiel) wants to merge 5 commits into
mainfrom
danielmeppiel-p1-4646-bundle-allow-policy

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

TL;DR. Under an org dependencies.allow list (refusal with enforcement: block; warn reports), apm install <bundle> now judges a local bundle by the packages its embedded apm.lock.yaml records — never by the author-chosen bundle name _local/<name> — and refuses, before any write, a bundle that records no packages. dependencies.deny keeps matching both the bundle name and its packages. With no allow list, bundle installs are unchanged.

Fixes #4646

Note

Dependency order: none. Builds on the local bundle dependency policy (#4645, merged); rebased onto main.

Design decision (scope authority)

Regent v3 ruling, 2026-11-21 18:30, relayed by the 0.38 program manager:

(1) dependencies.allow matches ONLY the packages in the bundle's embedded lockfile, with the same matcher as remote dependencies; it NEVER matches the author-chosen bundle name _local/<name>. (2) Under an allow list, a bundle with NO embedded packages is DENIED (fail closed; passing it would be a policy bypass). (3) dependencies.deny keeps matching both the bundle name and the embedded packages. No allow list => unchanged behaviour.

Problem (WHY)

  • Before this PR, apm install <bundle> never consulted dependencies.allow: an org that allow-lists its sources could still receive any content through a local bundle.
  • The bundle name is chosen by its author, so matching allow on it would let any bundle pass by naming itself after an allowed package.
  • A bundle that records no packages gives the allow list nothing to match; admitting it would be a bypass.

Approach (WHAT) and implementation (HOW)

File Change
policy/models.py New LocalBundleSubjects(names, packages): the bundle name(s) as _local/<name> and the packages its lockfile records.
install/bundle_admission.py bundle_policy_subjects returns LocalBundleSubjects; admit_bundle passes it on. Same owner and call path as #4645 (admit_bundle → run_policy_preflight → policy_checks).
policy/policy_checks.py _check_dependency_allowlist judges bundle.packages (same matcher as remote deps) and adds a fail-closed subject when a bundle records none; _check_dependency_denylist gets names + packages. Shared iteration factored into _declared_then_bundled.
policy/install_preflight.py Signature/docstring accept LocalBundleSubjects.
core/remediation.py New bundle-packages-unrecorded entry: Run 'apm install <package>' to install the content from a package the allow list names.
Docs enterprise/apm-policy.mdx, reference/policy-schema.md, reference/cli/install.md, apm-usage/governance.md.
Tests Owner-level component tests, one installed-CLI lifecycle test, an allow-list policy variant in the lifecycle world.

apm unpack and apm pack are unchanged (pack stays deny-only per #4645).

Trade-offs

  • Name never matches allow (rejected: name-or-packages). The author picks the name, so allowing on it is a bypass.
  • Empty bundle fails closed under an allow list (rejected: pass-through). Breaks content-only bundles in allow-listed orgs; the remedy is to install the content from an allowed package.
  • Refusal hint for embedded packages is the generic policy-admin line (no apm.yml edit applies), matching fix(bundle): align local bundle and pack gate coverage #4645's deny output.

Benefits

  1. An allow list now covers local bundle installs; a disallowed embedded package is refused with exit 1 and no file written.
  2. Renaming a bundle after an allowed package does not get it past the allow list.
  3. No behaviour change for orgs without an allow list.

Issue and approved scope

Issue: Fixes #4646

Human scope-approval comment: pending — an apm-scope record has been requested from Intake. Scope authority meanwhile is the Regent v3 ruling quoted above.

Does this PR complete the issue? Yes: decision documented, behaviour implemented, allow-listed and not-allow-listed bundles tested.

Type of change

  • Bug fix
  • New feature (upgrade note: content-only bundles are refused under a blocking allow list)
  • Documentation
  • Maintenance / refactor

Testing

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

Scenario evidence

Scenario Test Principle
Allow-listed bundle installs test_bundle_whose_packages_the_allow_list_names_is_admitted; lifecycle step install <allowed bundle> exit 0, lockfile records it Govern
Not-allow-listed embedded package refused before any write test_bundle_package_outside_the_allow_list_is_refused; lifecycle mixed bundle exit 1, state unchanged Govern / I7
Empty bundle refused under an allow list (empty and absent lockfile) test_bundle_recording_no_package_is_refused_under_an_allow_list; lifecycle p-exec bundle exit 1, state unchanged Govern / fail closed
Bundle named like an allowed package embedding a disallowed one refused test_bundle_named_like_an_allowed_package_is_judged_by_its_packages; lifecycle bundle named p-skill embedding p-exec Govern
Deny still matches the bundle name test_deny_still_matches_the_bundle_name_under_an_allow_list; #4645 test_denied_local_bundle_is_refused_before_any_write still green Govern
No allow list: unchanged test_bundle_recording_no_package_is_admitted_without_an_allow_list Compatibility
Printed remedy runs lifecycle runs apm install <allowed package> after the empty-bundle refusal, exit 0 Hints executed

Lifecycle test: tests/integration/test_org_dependency_allow_local_bundle_lifecycle.py (installed CLI, policy ON, snapshot oracle).
Failing-before: with src/ reverted to the pre-change code, the lifecycle test fails at the empty-bundle step (exit=0, assert 0 == 1); passing after.

Validation commands and results
bash host_guard.sh .venv/bin/python -m pytest tests/unit/install/test_bundle_policy_subjects.py tests/unit/bundle/test_pack_policy.py -q -n 0
  -> 12 passed
bash host_guard.sh .venv/bin/python -m pytest tests/unit/policy tests/unit/core/test_remediation_catalog_commands.py tests/unit/core/test_remediation_block_proofs.py tests/unit/install/test_policy_gate_phase.py tests/unit/install/test_dry_run_policy_noise.py tests/unit/test_unpacker.py tests/unit/install/test_bundle_policy_subjects.py -q -n 2
  -> 1 failed (bundle-packages-unrecorded had no proof level), fixed in test_remediation_w2_bundle_catalog.py
bash host_guard.sh .venv/bin/python -m pytest tests/unit/core/test_remediation_block_proofs.py tests/unit/core/test_remediation_w2_bundle_catalog.py tests/unit/core/test_remediation_catalog_commands.py -q -n 0
  -> 1043 passed
APM_E2E_TESTS=1 APM_BINARY_PATH=$PWD/.venv/bin/apm pytest tests/integration/test_org_dependency_allow_local_bundle_lifecycle.py -n 0
  -> 1 passed (88.7s); with src reverted to #4645 head -> 1 failed (exit=0 on empty bundle)
APM_E2E_TESTS=1 APM_BINARY_PATH=$PWD/.venv/bin/apm pytest "tests/lifecycle/world/test_world.py::test_policy_variant_is_served_and_recorded" tests/integration/test_org_dependency_deny_bundle_pack_lifecycle.py -n 2
  -> 17 passed
uvx [email protected] check / format --check (CI paths)        -> All checks passed / formatted
pylint R0801 (CI paths)                                    -> 10.00/10
bash scripts/lint-auth-signals.sh                          -> clean
python scripts/check_complexity_ratchet.py --base-ref origin/main -> clean
python -m tests.quality.taxonomy --changed                 -> tm006 clean
python scripts/check_test_assertions.py                    -> ratchet clean
python scripts/lint_architecture_boundaries.py --root .    -> clean
python -m tests.lifecycle.generator --check                -> up to date (anchor re-cited 233 -> 236)
python .apm/skills/cut-release/scripts/changelog_fragments.py check -> 2 fragments valid; check-unreleased -> no new bullets

How to test

  • Serve a policy with dependencies.allow: ["**/p-skill"], run apm install <bundle> for a bundle whose lockfile records only p-skill: installs.
  • Same policy, bundle named p-skill recording p-exec: exit 1, Policy violation: github.com/<org>/p-exec -- not in allowed sources, nothing written.
  • Same policy, bundle with no recorded packages: exit 1, the bundle records no packages for dependencies.allow to match.

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .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 -- applies the existing dependencies.allow matcher (req-pl-005, req-pl-018) to a local bundle's recorded packages; the spec does not define local bundle admission. Waiver carried in the test(policy): remediation proof level ... commit.

Co-authored-by: Copilot [email protected]

Base automatically changed from danielmeppiel-bundle-pack-gate-coverage to main November 22, 2026 08:21
… recorded packages (#4646)

dependencies.allow matches only the packages a local bundle's embedded
lockfile records, with the remote-dependency matcher; it never matches
the author-chosen _local/<name>. Under an allow list a bundle that
records no package is refused before any write. dependencies.deny still
matches the bundle name and its packages.

Co-authored-by: Copilot App <[email protected]>
… allow (#4646)

apm-spec-waiver: local bundle install applies the existing dependencies.allow matcher (req-pl-005, req-pl-018) to the packages its embedded lockfile records; the spec does not define local bundle admission, so no new contract.

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

The release notes lack migration guidance for newly blocked bundles, and the documentation incorrectly implies allow lists prevent writes regardless of enforcement mode.

2 open issues
What changed in this PR

Extends local bundle admission to evaluate dependencies.allow against embedded lockfile packages, building on the existing deny-policy checks from #4645.

Changes:

  • Checks recorded packages against the allow list, excluding author-chosen bundle names; blocking policies reject bundles with no recorded packages.
  • Preserves deny checks for both bundle names and packages, and keeps pack behavior unchanged.
  • Adds component and installed-CLI coverage, remediation guidance, and policy documentation.
File Description
tests/​unit/​install/​test_bundle_policy_subjects.py Tests package-based admission, empty bundles, and deny compatibility.
tests/​unit/​core/​test_remediation_w2_bundle_catalog.py Records evidence for the new remediation hint.
tests/​quality/​lifecycle_obligations.json Updates a source evidence line reference.
tests/​lifecycle/​world/​test_world.py Adds expected results for the allow-list policy variant.
tests/​lifecycle/​world/​services.py Defines the allow-list policy fixture.
tests/​lifecycle/​generator/​rules.py Updates the preflight evidence anchor.
tests/​integration/​test_org_dependency_allow_local_bundle_lifecycle.py Exercises bundle admission and unchanged state after refusals.
src/​apm_cli/​policy/​policy_checks.py Applies allow checks to bundled packages and handles empty bundles.
src/​apm_cli/​policy/​models.py Separates bundle names from recorded package identities.
src/​apm_cli/​policy/​install_preflight.py Accepts the structured bundle policy subjects.
src/​apm_cli/​install/​bundle_admission.py Collects and forwards bundle names and packages separately.
src/​apm_cli/​core/​remediation.py Adds guidance for bundles without recorded packages.
packages/​apm-guide/​.apm/​skills/​apm-usage/​governance.md Documents local bundle allow-list behavior.
docs/​src/​content/​docs/​reference/​policy-schema.md Explains package-based allow matching.
docs/​src/​content/​docs/​reference/​cli/​install.md Describes bundle allow-list admission.
docs/​src/​content/​docs/​enterprise/​apm-policy.mdx Adds local bundle policy guidance.
changelog.d/​4677.added.md Announces local bundle allow-list enforcement.

Review effort: Balanced

Comment thread changelog.d/4677.added.md Resolved

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 are reported for the local-bundle allow-list policy change.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

…-bundle-allow-policy

# Conflicts:
#	tests/lifecycle/world/services.py

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 bundle dependency allow-list changes.

No open issues 🎉

Review effort: Balanced

@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Superseded by #4769 (lifecycle train L): it folds this PR at eba336d together with #4584 under one lifecycle regen. Closing so it doesn't land twice; authorship is preserved in #4769's commits.

Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
test(lifecycle): train L -- signed known cells (#4584) and bundle allow-list policy (#4677)
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
Merge main f4efa6b and fold #4730 and #4769 (bundle allow-list policy from #4677) into the [0.38.0] block.

Co-authored-by: Copilot App <[email protected]>
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.

policy: evaluate dependencies.allow for local bundle installs

2 participants