Skip to content

[0.38] fix(policy): required-package checks read explicit proxy-URL lock rows (#4037) - #4067

Merged
Daniel Meppiel (danielmeppiel) merged 3 commits into
mainfrom
danielmeppiel-require-proxy-4037
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 3 commits into
mainfrom
danielmeppiel-require-proxy-4037

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

A required package declared as an explicit registry-proxy URL could not be found in the lockfile by the required-package checks.

Take a dependency written as art.example.com/artifactory/github/acme/tools, installed without PROXY_REGISTRY_URL, and the org policy entry dependencies.require: [art.example.com/acme/tools]. The package was declared and locked, yet required-packages-deployed reported it absent from the lockfile. That failed apm audit --ci, and it blocked any apm install that ran with a lockfile present.

Root cause: the lockfile writer and the required checks used different keys for the same package.

  • LockedDependency.from_dependency_ref (deps/lockfile.py) records an explicit proxy row under its proxy host with no registry_prefix, so the row key is art.example.com/acme/tools.
  • RequiredPackageMatch.locked_in (policy/matcher.py, from fix(policy): one host-bound identity for dependencies.require on every host #4008) looked the row up by the reference's own key, which stays bare (acme/tools). So the check missed the row. If a github.com acme/tools row also existed, it read that wrong row instead.

Fix: a lockfile-owned lookup, locked_row_for(lock, dep_ref) in deps/lockfile_lookup.py, resolves a reference to the row the writer created for it:

  • Most references, and an explicit proxy whose bare-key row has registry_prefix (written under a registry-proxy config): the row under the reference key, as before.
  • Otherwise, for an explicit proxy reference: the row under the key from_dependency_ref writes. A bare row without registry_prefix is never read for it, since that row is another package.

RequiredPackageMatch.locked_in now reads through this lookup, so required-packages-deployed, required-package-version and required-executable-untrusted all read the right row.

Unchanged: lock keys and lockfile format, the require identity (an explicit proxy path is identified by its written proxy host, per #4008), env-proxy (PROXY_REGISTRY_URL) behaviour, and allow/deny matching.

Issue and approved scope

Issue: Fixes #4037

Human scope-approval comment: #4037 (comment)

Rebased onto main after 0.37.0 (#4008 has landed); it builds on #4008's host-bound RequiredPackageMatch.

Rebase onto 0.37.0 (decision log)

  • Lookup location: after 0.37, deps/lockfile.py is 2097 lines, and the original 15-line method would push it over the 2100 cap. Decision (S15 default): the lookup now lives in deps/lockfile_lookup.py, registered under the read-only-lockfile-path owner beside deps/lockfile.py. It reads rows only through LockFile.get_dependency and the key LockedDependency.from_dependency_ref writes, so the lockfile stays the single owner of row keying. lockfile.py is unchanged.
  • Test taxonomy: the new lifecycle module carries pytest.mark.e2e and pytest.mark.promise("req-pl-018") (tm006).
  • Checks run before the push:
    • complexity ratchet, taxonomy allowance and tm006 (36 passed);
    • ruff and lint_architecture_boundaries.py --root .;
    • the full test_architecture_owner_rule_mutations.py: 1246 passed;
    • orphan_check OK (149).
      Targeted failures (gpg signing, sparse cache, the fix(policy): one host-bound identity for dependencies.require on every host #4008 host-identity lifecycle with base_env={}) fail identically on pristine main in this sandbox.

Type of change

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

Testing

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

The new installed-CLI lifecycle test, tests/integration/policy/test_required_packages_explicit_proxy_lifecycle.py, uses a loopback HTTPS proxy (local_scripted_https_proxy). It serves the Artifactory archive for art.example.test and the org policy (enforcement: block) from api.github.com; the policy is discovered through the project's origin remote.

  • Explicit proxy URL: apm install succeeds under the policy, and the lock row is art.example.test/acme/tools with no registry_prefix. apm audit --ci passes required-packages and required-packages-deployed for art.example.test/acme/tools. A reinstall with the lockfile present passes the install gate.
  • Controls: an entry naming another proxy host fails both checks. The same entry with the dependency removed from apm.yml fails both checks. An env-proxy install (PROXY_REGISTRY_URL, shorthand dependency, hostless entry, bare row with registry_prefix) keeps passing.

Unit tests in tests/unit/policy/test_required_package_host_identity.py cover:

  • the version pin and executable checks reading the explicit-proxy row;
  • a same-path github.com row never being read for an explicit proxy dependency;
  • a row written under a registry config still being found.

A conformance test cites req-pl-018 clause (g): read the lock entry by the dependency's own lockfile identity.

Red/green, with src/ reverted:

Command Result
APM_BINARY_PATH=.venv/bin/apm pytest -q tests/integration/policy/test_required_packages_explicit_proxy_lifecycle.py 4 passed (1 failed with the fix reverted)
pytest -q tests/unit/policy/test_required_package_host_identity.py 15 passed (2 failed with the fix reverted)
pytest -q -p no:randomly tests/spec_conformance/test_policy_reqs.py passed (new test fails with the fix reverted)
pytest -q -n 8 tests/unit/policy tests/unit/deps tests/spec_conformance/test_policy_reqs.py tests/integration/policy 3557 passed; the 12 failures are sandbox git-signing failures, identical with the fix reverted
ruff check / ruff format --check / pylint R0801 / lint-auth-signals.sh / lint_architecture_boundaries.py --root . clean
python -m tests.spec_conformance.orphan_check OK, 148 requirements aligned

Residual, out of scope per the record ("other lockfile consumers of explicit-proxy rows"): for the same explicit-proxy project, apm audit --ci still fails four baseline checks: ref-consistency, no-orphaned-packages, skill-subset-consistency and drift. They also look up rows by the bare reference key. That needs a follow-up issue; deps.lockfile_lookup.locked_row_for is the lookup they can adopt.

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: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

There is no spec text change: req-pl-018 clause (g) (revised by #4008 as 0.1.67) already requires reading the lock entry by the dependency's own lockfile identity.

Docs re-home after #3996

The docs are in the last commit, by themselves.

Topic Page
dependencies.require matching for explicit proxy URLs docs/src/content/docs/reference/policy-schema.md
Same, for agents packages/apm-guide/.apm/skills/apm-usage/governance.md

Base automatically changed from danielmeppiel-scaling-potato to main November 20, 2026 06:40
#4037)

An explicit registry-proxy URL dependency (host/artifactory/...) installed
without PROXY_REGISTRY_URL is written to the lockfile by
LockedDependency.from_dependency_ref under its proxy host
(<proxy-host>/owner/repo, no registry_prefix), while its reference key
stays bare. RequiredPackageMatch.locked_in looked the row up by the bare
reference key, so required-packages-deployed (and the version and
executable checks) missed a declared, locked package -- or read a
same-path github.com row instead.

Add the lockfile-owned lookup deps.lockfile_lookup.locked_row_for(lock, dep_ref), which
resolves a reference to the row the writer created for it, and route the
required-check lock read through it. Lock keys, lockfile format, require
identity, env-proxy behaviour and allow/deny matching are unchanged.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) marked this pull request as ready for review November 21, 2026 09:03
Copilot AI balanced review requested due to automatic review settings November 21, 2026 09:03
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 1eb559d into main Nov 21, 2026
65 of 68 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-require-proxy-4037 branch November 21, 2026 09:04

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 critical lockfile lookup collision can select a package from the wrong registry, causing incorrect presence and version checks and potentially bypassing executable trust restrictions.

1 open issue
What changed in this PR

This PR addresses #4037 by adding a lockfile-owned lookup for required packages declared through explicit registry-proxy URLs. It builds on #4008's host-aware policy matching without changing the lockfile format.

Changes:

  • Routes required-package checks through the shared lock-row lookup.
  • Adds unit, installed-CLI lifecycle, and conformance coverage.
  • Documents explicit-proxy matching and updates ownership and conformance records.
File Description
src/​apm_cli/​deps/​lockfile_lookup.py Adds reference-to-lock-row resolution for explicit proxies.
src/​apm_cli/​policy/​matcher.py Delegates required-package row reads to the lookup.
tests/​unit/​policy/​test_required_package_host_identity.py Covers proxy rows, default-host collisions, version pins, and trust.
tests/​integration/​policy/​test_required_packages_explicit_proxy_lifecycle.py Exercises install, audit, reinstall, and negative controls.
tests/​spec_conformance/​test_policy_reqs.py Adds explicit-proxy coverage for req-pl-018.
CONFORMANCE.json Registers the added conformance test.
CONFORMANCE.md Updates the requirement's test count.
docs/​src/​content/​docs/​reference/​policy-schema.md Explains proxy-qualified required-package entries.
packages/​apm-guide/​.apm/​skills/​apm-usage/​governance.md Updates matching guidance for agents.
.apm/​architecture/​owners/​contracts-tooling.json Registers the lookup under the lockfile owner.
CHANGELOG.md Records the required-package lookup fix.

Review effort: Balanced

Comment on lines +26 to +31
from .lockfile import LockedDependency

row = lock.get_dependency(dep_ref.get_unique_key())
owner = getattr(dep_ref, "ownership_reference", dep_ref)
if not getattr(owner, "artifactory_prefix", None) or (row and row.registry_prefix):
return row
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
…file-owner

[0.38] test(arch): read-only lockfile owner has two selectors after #4067 (main red)
chessMan (mohitmishra786) pushed a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
…t#4067

microsoft#4067 registered src/apm_cli/deps/lockfile_lookup.py beside
src/apm_cli/deps/lockfile.py in the read-only-lockfile-path owner
(.apm/architecture/owners/contracts-tooling.json); the integration test
still asserted a single selector, so the dispatch-only integration suite
failed on main 5337f2f.

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.

dependencies.require does not match explicit proxy-URL dependencies to their lockfile key

2 participants