Repository navigation
Description
Describe the bug
On a non-default git host (self-managed GitLab, GHES, Gitea), a repository that declares the required package in
apm.yml and has it locked cannot satisfy a policy that carries dependencies.require:
- With the hostless entry (
group/sub/pkg),required-packagespasses andrequired-packages-deployedreports
1 required package(s) absent from the lockfilefor a package that is in the lockfile. - With the host-qualified entry (
gitlab.example.com/group/sub/pkg),required-packagesreports it as missing from
the manifest, andrequired-packages-deployedpasses only because it skips the entry.
Both checks build their lookup from the host-blind canonical identity
(get_canonical_dependency_string() -> group/sub/pkg) while the lockfile index is keyed by
get_unique_key(), documented in src/apm_cli/models/dependency/identity.py:236-243 as the lockfile/dedup key that
includes the host segment for non-default hosts. On github.com both sides stay bare owner/repo, which is why the
mismatch does not show up on the default host.
Consequence: with any dependencies.require in the policy, enforcement: block is not usable on a non-default host -
the schema has no per-check switch, so one of the two checks is always red for a compliant repository.
The same identity mix affects required-executable-untrusted (executables.require): the package is
exec_status: deployed in the lockfile and the check still reports 1 required executable(s) present but untrusted.
To Reproduce
No network needed; the snippet runs against current main with a fictional non-default host:
from apm_cli.models.apm_package import DependencyReference
from apm_cli.policy.policy_checks import (
_check_required_packages, _check_required_packages_deployed, _check_required_executable_untrusted,
)
from apm_cli.policy.schema import DependencyPolicy, ExecutablesPolicy
from apm_cli.deps.lockfile import LockFile, LockedDependency
HOST = "gitlab.example.com"
qualified, hostless = HOST + "/group/sub/pkg", "group/sub/pkg"
dep = DependencyReference.parse(qualified)
print(dep.get_canonical_dependency_string(), "|", dep.get_unique_key())
# -> group/sub/pkg | gitlab.example.com/group/sub/pkg
lock = LockFile()
lock.add_dependency(LockedDependency.from_dict(
{"repo_url": hostless, "host": HOST, "resolved_ref": "main", "exec_status": "deployed"}))
print(list(lock.dependencies.keys()))
for entry in (qualified, hostless):
policy = DependencyPolicy(require=(entry,))
c3 = _check_required_packages([dep], policy)
c4 = _check_required_packages_deployed([dep], lock, policy)
print(entry, "->", c3.passed, c3.message, "|", c4.passed, c4.message)
ex = _check_required_executable_untrusted([dep], lock, ExecutablesPolicy(require=(entry,)))
print(" executables:", ex.passed, ex.message)Observed output:
group/sub/pkg | gitlab.example.com/group/sub/pkg
['gitlab.example.com/group/sub/pkg']
gitlab.example.com/group/sub/pkg -> False 1 required package(s) missing from manifest | True All required packages present in lockfile
executables: True All required executables are trusted
group/sub/pkg -> True All required packages present in manifest | False 1 required package(s) absent from the lockfile. Hint: run apm install --no-policy to repair the lockfile, then reinstall normally.
executables: False 1 required executable(s) present but untrusted.
At the CLI level this shows up as apm audit --ci --policy <policy> failing on a repository whose apm.yml declares the
dependency and whose apm.lock.yaml contains it in a row carrying host: for the non-default server.
Expected behavior
- A repository that declares the required package and has it locked passes both
required-packagesand
required-packages-deployed, whatever the host is. - A required package missing from the manifest or from the lockfile fails the check that owns that condition, and the two
checks agree about which identity they compare. enforcement: blockis usable on a self-managed host.
Environment
- OS: Linux (container, x86_64) and macOS (arm64)
- Python Version: 3.12
- APM Version: 0.36.1 (
Agent Package Manager (APM) CLI version 0.36.1 (784d778)) - Also reproduced against current
main(ee00d6aae,pyproject.tomlversion 0.36.1)
Logs
Message seen in CI for a package that is present in apm.lock.yaml with the non-default host:
1 required package(s) absent from the lockfile. Hint: run apm install --no-policy to repair the lockfile, then reinstall normally.
Additional context
Root cause as of ee00d6aae (src/apm_cli/policy/policy_checks.py):
# _check_required_packages (line 215) - index built from the host-blind canonical
index = _required_policy_index(deps, dep_names) # matcher.py:48 from_dependencies
# matcher.py:52 get_canonical_dependency_string()
for req in policy.effective_require:
if index.find_name(req.split("#", 1)[0]) is None: # matcher.py:67 exact lookup
missing.append(pkg_name)
# _check_required_packages_deployed (line 254) - host-blind value, host-qualified keys
lock_by_name = {locked.get_unique_key(): locked for _key, locked in lock.dependencies.items()} # line 279
for req in policy.effective_require:
lock_name = index.find_name(pkg_name) # line 283 - host-blind, e.g. group/sub/pkg
if lock_name is None:
continue # line 285 - documented as "check 3 handles this"
if lock_by_name.get(lock_name) is None: # line 288 - keys are host-qualified, so it always misses
not_present.append(pkg_name)The identical lock_by_name + find_name pair also appears in _check_required_executable_untrusted (line 344) and in
_check_required_package_version (line 408); the latter did not misreport in the probe above, so its lookup path may
differ - worth a look while touching this.
Why the current tests miss it: tests/unit/policy/test_policy_checks.py::TestRequiredPackagesDeployed and
tests/unit/policy/test_dependency_identity_case.py build hostless repo_urls (the github.com default), and the identity
tests there cover casing, not hosts. The probe above is a ready regression test for a non-default host.
Related: #1313 (the lockfile-wipe catch-22 on this same check), #1735 and #3932 (lockfile key host/port handling),
#3606 / #3509 (host-qualified patterns - implemented for allow/deny; require still compares host-blind canonical
identities, and the policy reference documents <host>/<owner>/<repo> patterns for the dependencies block without
stating that require is hostless-only).
Related observation: audit judges direct declarations while install judges the resolved tree
Same code family, different input set. apm install runs the policy checks against ctx.deps_to_install
(install/phases/policy_gate.py:111-112 - the resolved installation list, transitives included), while
apm audit --ci runs them against manifest.get_apm_dependencies() (policy_checks.py:1593,
models/apm_package.py:917-922 - direct declarations only). For a require entry that a repository pulls
transitively, the two entry points already disagree today:
apm install: passes, because the resolved list contains the package;apm audit --ci:required-packagesfails, because the manifest does not declare it directly.
Fixing the identity mismatch does not change this. Emulating the fix (host-blind lock keys) in the probe above keeps
required-packages failing for the transitive-only package, and required-packages-deployed skips it by design
(if lock_name is None: continue # not in manifest -- check 3 handles this, line 285).
So dependencies.require means "declared in apm.yml" in the audit, whatever the host. If the intent is
"present in the resolved tree" - which is what install already accepts - the two entry points need to agree, and the
documented meaning of require ("must be present in every repository's apm.yml") likely needs an explicit
mode. Reporting it here because it sits in the same checks; happy to split it into its own issue if you prefer.
Reporting only - I am not proposing to implement a fix here. Happy to add the regression test, or to help review a fix,
if a maintainer confirms the scope per CONTRIBUTING.md.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
danielmeppiel commentedon Nov 19, 2026
Thanks Luis Azevedo (@azevedo-luis), this is a clear and well-diagnosed report: the two checks use a host-blind identity while the lockfile is host-keyed, so self-managed hosts can never satisfy both. We're fixing it for 0.37; scope below.
danielmeppiel commentedon Nov 19, 2026
Decision: approve
Area: project
Scope: Make the org policy checks required-packages and required-packages-deployed use ONE host-aware identity for dependencies.require entries, at the policy owner: a hostless entry matches the declared and locked dependency on the default host only; a host-qualified entry matches that host on both the manifest and the lockfile side. Neither check may skip an entry it cannot resolve; an unmatched entry fails with a hint naming the expected form. Docs (policy reference) and apm-usage governance.md state the matching rule.
Done when: On a non-default host (GitLab, GHES, Gitea), a declared and locked required package passes both checks with the host-qualified entry; the hostless entry keeps working on the default host; a missing package fails both checks; no check silently skips an entry; regression tests cover each case plus the reporter's repro.
Out of scope: New policy schema keys; changing get_unique_key() or the lockfile format.
Review contact: Daniel Meppiel (@danielmeppiel)
fix(policy): one host-bound identity for dependencies.require
fix(policy): one host-bound identity for dependencies.require
fix(policy): one host-bound identity for dependencies.require
fix(policy): one host-bound identity for dependencies.require