Repository navigation
[0.38] fix(policy): required-package checks read explicit proxy-URL lock rows (#4037) - #4067
Merged
Daniel Meppiel (danielmeppiel) merged 3 commits intoNov 21, 2026
Merged
Conversation
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-require-proxy-4037
branch
from
November 20, 2026 03:30
7639a3c to
0919108
Compare
7 of 14 tasks
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-require-proxy-4037
branch
from
November 21, 2026 08:30
0919108 to
b23335c
Compare
#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]>
… rows (#4037) Co-authored-by: copilot-swe-agent[bot] <[email protected]>
) Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-require-proxy-4037
branch
from
November 21, 2026 08:45
b23335c to
9fd0e2b
Compare
Daniel Meppiel (danielmeppiel)
marked this pull request as ready for review
November 21, 2026 09:03
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 21, 2026 09:03
Daniel Meppiel (danielmeppiel)
deleted the
danielmeppiel-require-proxy-4037
branch
November 21, 2026 09:04
Contributor
There was a problem hiding this comment.
🟡 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 |
This was referenced Nov 21, 2026
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]>
This was referenced Nov 21, 2026
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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 withoutPROXY_REGISTRY_URL, and the org policy entrydependencies.require: [art.example.com/acme/tools]. The package was declared and locked, yetrequired-packages-deployedreported it absent from the lockfile. That failedapm audit --ci, and it blocked anyapm installthat 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 noregistry_prefix, so the row key isart.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.comacme/toolsrow also existed, it read that wrong row instead.Fix: a lockfile-owned lookup,
locked_row_for(lock, dep_ref)indeps/lockfile_lookup.py, resolves a reference to the row the writer created for it:registry_prefix(written under a registry-proxy config): the row under the reference key, as before.from_dependency_refwrites. A bare row withoutregistry_prefixis never read for it, since that row is another package.RequiredPackageMatch.locked_innow reads through this lookup, sorequired-packages-deployed,required-package-versionandrequired-executable-untrustedall 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)
deps/lockfile.pyis 2097 lines, and the original 15-line method would push it over the 2100 cap. Decision (S15 default): the lookup now lives indeps/lockfile_lookup.py, registered under theread-only-lockfile-pathowner besidedeps/lockfile.py. It reads rows only throughLockFile.get_dependencyand the keyLockedDependency.from_dependency_refwrites, so the lockfile stays the single owner of row keying.lockfile.pyis unchanged.pytest.mark.e2eandpytest.mark.promise("req-pl-018")(tm006).lint_architecture_boundaries.py --root .;test_architecture_owner_rule_mutations.py: 1246 passed;orphan_checkOK (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
Testing
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 forart.example.testand the org policy (enforcement: block) fromapi.github.com; the policy is discovered through the project'soriginremote.apm installsucceeds under the policy, and the lock row isart.example.test/acme/toolswith noregistry_prefix.apm audit --cipassesrequired-packagesandrequired-packages-deployedforart.example.test/acme/tools. A reinstall with the lockfile present passes the install gate.apm.ymlfails both checks. An env-proxy install (PROXY_REGISTRY_URL, shorthand dependency, hostless entry, bare row withregistry_prefix) keeps passing.Unit tests in
tests/unit/policy/test_required_package_host_identity.pycover:A conformance test cites
req-pl-018clause (g): read the lock entry by the dependency's own lockfile identity.Red/green, with
src/reverted:required-packages-deployedreportingart.example.test/acme/toolsabsent. The reinstall gate also blocks ("required package absent"). Two of the new unit tests fail, one of them because fix(policy): one host-bound identity for dependencies.require on every host #4008 reads the github.com row. The conformance test fails.apm installis already blocked at the gate ("required by org policy but not declared"), because main has no host-bound require identity.APM_BINARY_PATH=.venv/bin/apm pytest -q tests/integration/policy/test_required_packages_explicit_proxy_lifecycle.pypytest -q tests/unit/policy/test_required_package_host_identity.pypytest -q -p no:randomly tests/spec_conformance/test_policy_reqs.pypytest -q -n 8 tests/unit/policy tests/unit/deps tests/spec_conformance/test_policy_reqs.py tests/integration/policyruff check/ruff format --check/pylint R0801/lint-auth-signals.sh/lint_architecture_boundaries.py --root .python -m tests.spec_conformance.orphan_checkResidual, out of scope per the record ("other lockfile consumers of explicit-proxy rows"): for the same explicit-proxy project,
apm audit --cistill fails four baseline checks:ref-consistency,no-orphaned-packages,skill-subset-consistencyanddrift. They also look up rows by the bare reference key. That needs a follow-up issue;deps.lockfile_lookup.locked_row_foris the lookup they can adopt.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)
docs/src/content/docs/specs/openapm-v0.1.mdupdated(new/changed
<a id="req-XXX"></a>anchor + prose + Appendix Crow).
docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.ymlupdated.
@pytest.mark.req("req-XXX")test undertests/spec_conformance/added or extended.CONFORMANCE.{md,json}regenerated viauv run --extra dev python -m tests.spec_conformance.gen_statementand committed.
There is no spec text change:
req-pl-018clause (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.
dependencies.requirematching for explicit proxy URLsdocs/src/content/docs/reference/policy-schema.mdpackages/apm-guide/.apm/skills/apm-usage/governance.md