Repository navigation
fix(marketplace): record catalog origin in the lock; fail closed on rebound aliases - #3917
Conversation
…ebound aliases A marketplace alias such as `company` is machine-local, but Git catalogs recorded only that alias in apm.lock.yaml. Rebinding the alias silently switched the catalog an object-form apm.yml entry resolved through. - Record the canonical catalog origin as `source_url` and a `source_digest` for every remote catalog kind, including Git (no new lockfile fields). - Re-resolving a locked entry fails closed when the alias's registered origin differs from the lock's `source_url`, naming both origins. - Warn when a second alias registers an already registered catalog. - Pre-0.37 rows without `source_url` keep working and gain it on the next lock write. Local file:// catalogs record no origin. Closes #3912 Co-authored-by: Copilot App <[email protected]>
…meppiel-lockfile-marketplace-origin-3912
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Catalog origin checks can silently accept rebound sources because URL comparisons discard query parameters and ambiguous lockfile provenance bypasses verification.
4 open issues
What changed in this PR
This PR addresses #3912 by extending marketplace provenance in existing lockfile fields and checking catalog origins before resolving locked dependencies. It aims to prevent machine-local alias changes from silently switching catalogs without introducing a lockfile schema change.
Changes:
- Records canonical origins and digests for remote catalogs, while omitting machine-specific local origins.
- Adds origin-conflict checks and duplicate-registration warnings.
- Adds lifecycle tests, architecture guards, and documentation for the new behavior.
| File | Description |
|---|---|
tests/unit/scripts/test_architecture_runner.py |
Registers the new guard in the expected rule inventory. |
tests/unit/marketplace/test_parser.py |
Tests origin normalization, comparison, and catalog digests. |
tests/integration/test_marketplace_origin_evidence_lifecycle.py |
Covers alias rebinding, duplicate warnings, and legacy locks. |
tests/integration/test_architecture_owner_rule_mutations.py |
Adds a mutation removing origin verification. |
tests/integration/test_architecture_marketplace_locked_evidence.py |
Tests owner routing and check ordering. |
src/apm_cli/marketplace/source_identity.py |
Defines canonical catalog origins and comparisons. |
src/apm_cli/marketplace/resolver.py |
Attaches remote catalog evidence to resolved plugins. |
src/apm_cli/marketplace/reconcile.py |
Warns about duplicate origins during manifest reconciliation. |
src/apm_cli/marketplace/models.py |
Computes fallback digests from canonical catalog JSON. |
src/apm_cli/marketplace/errors.py |
Adds an origin-conflict error with recovery guidance. |
src/apm_cli/marketplace/catalog_origin.py |
Centralizes locked-origin checks and duplicate detection. |
src/apm_cli/deps/apm_resolver.py |
Checks locked origins before catalog resolution. |
src/apm_cli/commands/marketplace/__init__.py |
Adds duplicate-origin warnings during registration. |
scripts/architecture_linter/checks/marketplace_locked_evidence.py |
Adds origin-owner routing and ordering checks. |
packages/apm-guide/.apm/skills/apm-usage/dependencies.md |
Explains origin evidence and conflict recovery. |
packages/apm-guide/.apm/skills/apm-usage/commands.md |
Documents duplicate-registration warnings. |
docs/src/content/docs/reference/lockfile-spec.md |
Updates provenance field meanings and compatibility notes. |
docs/src/content/docs/reference/cli/marketplace.md |
Documents remote evidence and alias-rebinding behavior. |
docs/src/content/docs/consumer/installing-from-marketplaces.md |
Explains alias safety and recovery steps. |
CHANGELOG.md |
Records the user-visible marketplace changes. |
.apm/architecture/owners/marketplace-plugins.json |
Registers catalog-origin ownership and its guard. |
Review effort: Balanced
…meppiel-lockfile-marketplace-origin-3912
Hosted catalog queries now take part in origin comparison, every locked row for an alias/plugin pair is checked so ambiguous associations cannot skip verification, the static guard requires `add` to call the duplicate warning, and guard mutation tests assert the mutated source still parses. Addresses Copilot inline review on source_identity.py:127, catalog_origin.py:40, marketplace_locked_evidence.py:45 and test_architecture_marketplace_locked_evidence.py:73. Co-authored-by: Copilot App <[email protected]>
…meppiel-lockfile-marketplace-origin-3912
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Supply Chain Security Expert | 0 | 2 | 0 | The origin pin and fail-closed check close the alias-rebind hole. Two gaps: case-sensitive alias matching can skip the check, and the error prints an unquoted, lockfile-derived command. |
| Test Coverage Expert | 0 | 3 | 0 | Lifecycle traps pass on source tree; the error's uninstall remediation fails for object-form deps and plain-install fail-closed is unasserted. |
| Python Architect | 0 | 3 | 0 | Owner split is sound; move the Git digest out of the parser default, share the lock-row predicate, and use one catalog-identity tuple for both checks. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 5 follow-ups
- [Supply Chain Security Expert] Casefold the alias comparison in require_locked_catalog_origin and add a regression test where
Companyin apm.yml meets acompanylock row. -- A case-sensitive match against a case-insensitive registry silently skips the fail-closed guard, which reopens the rebind hole this PR closes. - [Test Coverage Expert] Extend the existing rebind lifecycle block to assert that plain
apm installalso exits 1 after a rebind (0,1,1). -- This is new exit-code behavior users will see on a secure-by-default surface, and nothing asserts it. - [Supply Chain Security Expert] Harden MarketplaceOriginConflictError's remediation: shlex.quote the suggested
apm marketplace addcommand and suggest it only when the locked origin parses, otherwise show it as plain data. Reword the uninstall advice so it works for object-form entries, and prove the switch path in the lifecycle test. Track the object-form uninstall fix as a separate issue. -- Today the error copies an unquoted value from a committed lockfile into a shell command, and its uninstall advice fails for some dependency shapes. - [Python Architect] Keep parse_marketplace_json as a pass-through and compute catalog_digest in client.py for Git kinds only, on top of the fix(marketplace): explicit refresh revalidates catalogs or fails (#3279) #3910 fetch_marketplace restructure. -- As written, the url-kind digest scheme depends on whether cache metadata exists, so one hosted catalog can get two different source_digest values.
- [Python Architect] Add an additive LockFile.marketplace_rows(alias, plugin) shared by marketplace_index and the guard, plus one source_identity helper that documents identity as origin-only; pin both with tests, including a reconcile unit test for the duplicate-origin warning and its warn-once-per-pair dedupe. -- The guard and the warning currently use different predicates and identity tuples, which is the kind of drift that breaks silently.
Recommendation
Fold all follow-ups into this PR before landing, keeping the architect refactors additive so they don't churn against #3910 and #3911. Defer only the object-form apm uninstall fix to its own issue. The one to watch is the casefold alias bypass: until it is closed and covered by a regression test, the fail-closed guarantee does not hold. Also make sure the CHANGELOG line states the new fail-closed behavior on apm install and apm update after an alias rebind.
Full per-persona findings
Supply Chain Security Expert
- [recommended] The origin check compares alias names case-sensitively, but the registry looks aliases up case-insensitively, so a case mismatch skips the check. at
src/apm_cli/marketplace/catalog_origin.py:44
discovered_viais written with whatever case the manifest used, whileget_marketplace_by_nameandadd_marketplacelowercase.marketplace: Companyagainst a lock rowcompanyreturns early and re-locks through the rebound catalog.
Suggested: casefold both sides; add a mixed-case regression test. - [recommended] The conflict error tells the user to run a command built from an unvalidated, unquoted lockfile value, and the command may not restore the original registration. at
src/apm_cli/marketplace/errors.py:61
The lockfile is committed, so a PR can change it; a crafted source_url becomes a copy-paste injection APM suggests. The command also drops SSH user, path and ref.
Suggested: show the restore command only whenparse_marketplace_source(locked)succeeds, wrapped in shlex.quote; otherwise name the origin as data.
Test Coverage Expert
- [recommended] The 'To switch catalogs' remediation fails for the object-form apm.yml entry this PR targets, and no test exercises it. at
src/apm_cli/marketplace/errors.py:63
An ad-hoc probe ofapm uninstall example-plugin@companyexits 1 with "was not found in apm.yml", with or without the rebind (existing uninstall limitation).
Proof (missing at):tests/integration/test_marketplace_origin_evidence_lifecycle.py::test_git_catalog_origin_is_locked_and_a_rebound_alias_fails_update-- proves: the error's advice for intentionally switching catalogs actually works [devx,secure-by-default] - [recommended] Plain 'apm install' with a rebound alias also fails closed, but only 'apm update' is asserted. at
src/apm_cli/deps/apm_resolver.py:673
A probe confirms install exits 1 naming both origins with the lock unchanged; it is new user-visible behavior with no test pinning it.
Proof (missing at):tests/integration/test_marketplace_origin_evidence_lifecycle.py::test_git_catalog_origin_is_locked_and_a_rebound_alias_fails_update-- proves: re-running apm install after a rebind never silently switches catalogs [secure-by-default,portability-by-manifest] - [recommended] The duplicate-origin warning in user-manifest reconcile and its warn-once-per-pair logic have no test. at
src/apm_cli/marketplace/reconcile.py:124
Only theapm marketplace addstep is covered; the reconcile branch has its own registry fetch and pair dedupe.
Proof (missing at):tests/unit/marketplace/test_user_manifest_marketplaces.py::TestReconcile::test_two_manifest_aliases_for_one_origin_warn_once-- proves: two manifest names for one catalog produce exactly one warning [devx,governed-by-policy]
Python Architect
- [recommended] The catalog_digest fallback in parse_marketplace_json makes the digest scheme depend on cache state, not just catalog kind. at
src/apm_cli/marketplace/models.py:652
For url kinds, a missing or old cache meta yields a canonical-JSON digest instead of the raw-bytes one, so one catalog can carry two digests.
Suggested: keep the parser a pass-through; compute catalog_digest in client.py for Git kinds and point the guard route there. - [recommended] require_locked_catalog_origin re-implements LockFile.marketplace_index's alias/plugin row predicate. at
src/apm_cli/marketplace/catalog_origin.py:40
Row association is computed in two places, and [BUG] apm install re-resolves marketplace dependencies on every run instead of replaying the lockfile #3911 adds a third consumer.
Suggested: addLockFile.marketplace_rows(alias, plugin)returning every row, and build both consumers on it. - [recommended] Catalog identity is (origin, path) for the duplicate warning but origin-only for the fail-closed guard. at
src/apm_cli/marketplace/catalog_origin.py:60
The lock cannot record path without new fields, so re-pointing to another path in the same repo passes the guard; that decision should be explicit in one source_identity helper.
Suggested: one identity helper, a docstring stating the origin-only limit, and a pinning test.
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.
- Match aliases case-insensitively via LockFile.marketplace_rows, so a recased alias cannot skip the fail-closed origin check. - Quote the restore command in MarketplaceOriginConflictError, suggest it only for a parseable origin, and give a switch path that works for object-form apm.yml entries (proved end-to-end in the lifecycle test). - Compute the Git catalog digest in client._parse_catalog so the digest scheme depends only on catalog kind; parse_marketplace_json is a pass-through again. - One catalog identity helper (same_marketplace_catalog) for the duplicate warning; document and pin the origin-only limit of the lock check. - Assert plain `apm install` also fails closed after a rebind, and cover the user-manifest reconcile duplicate warning. Addresses the lean panel advisory on #3917 (supply-chain F1/F2, test-coverage F1-F3, python-architect F1-F3). Co-authored-by: Copilot App <[email protected]>
…meppiel-lockfile-marketplace-origin-3912
…meppiel-lockfile-marketplace-origin-3912
With #3915 on main, a plain `apm install` replays the locked catalog without consulting the rebound alias, so it succeeds and keeps the locked bytes; `apm update` still re-resolves and fails closed naming both origins. Docs and the CHANGELOG line now describe that split. Co-authored-by: Copilot App <[email protected]>


TL;DR
A marketplace alias like
companyonly means something on one machine, yet for Git-hosted catalogsapm.lock.yamlrecorded nothing but that alias. Rebinding the alias madeapm update --yessilently swap the package for one from a different catalog. This PR records the catalog's canonical origin (source_url) and a digest (source_digest) for every remote catalog kind, fails closed when an alias's origin no longer matches the lock, and warns when a second alias registers an already registered catalog. It adds no new lockfile fields.Fixes #3912
Description
Reproduced on
mainwith the real CLI before any change. Two hermetic Git catalogs A and B each listexample-plugin, and the consumerapm.ymldeclares{name: example-plugin, marketplace: company}.apm install, the lock row hasdiscovered_via: companyand nosource_url/source_digest.apm marketplace add <A>.git --name company-mirrorregisters silently, with no duplicate warning.apm marketplace add <B> --name companyfollowed byapm update --yesprints[+] .../catalog-b/... (new) [-] .../catalog-a/... (removed)and deploys# from catalog B. The catalog switched silently.Issue and approved scope
Issue: Fixes #3912
Human scope-approval comment: #3912 (comment) (
apm-scope:v1, approver and review contact Daniel Meppiel (@danielmeppiel);eligibility.cjsreportsrecord-presentat HEAD).Does this PR complete the issue? Yes. Every "Done when" item is covered by a lifecycle test (see Scenario evidence).
Explicit scope statements (requested by the coordinating session):
Important
source_urlandsource_digestalready existed (hosted-URL catalogs only). There is no new field, nolockfile_versionbump, nocatalog:key and no spec amendment.marketplace_path/marketplace_ref/marketplace_revisionstay 0.38 work ([FEATURE] Persist marketplace object-form deps; accept SHA catalog pins #2903).file://catalogs record no origin. Their path is machine-specific and would leak into committed lockfiles, so they record neithersource_urlnorsource_digest.Type of change
Approach (WHAT)
marketplace/source_identity.pymarketplace_origin,same_marketplace_origin.git, with a lowercase host. Local →"". Comparison ignores transport (HTTPS vs SSH), so pre-0.37 hosted-URL locks still match.marketplace/models.pycatalog_digestsha256:over the canonical JSON (sorted keys, no whitespace), used when the fetcher has no raw bytes. The hosted-URL raw-bytes digest is unchanged.marketplace/catalog_origin.pyrequire_locked_catalog_originAPMDependencyResolver._resolve_marketplace_depbefore any catalog I/O. RaisesMarketplaceOriginConflictErrornaming both origins plus restore and switch commands.catalog_origin.registrations_sharing_origin[!]fromapm marketplace addand the user-manifestmarketplaces:reconcile, when origin and--pathmatch another alias.Implementation (HOW)
marketplace/source_identity.pymarketplace_origin()andsame_marketplace_origin(), built oncache.url_normalize.normalize_repo_url.marketplace/models.pycatalog_digest().parse_marketplace_jsonfalls back to it when no digest is supplied.marketplace/resolver.pyresolve_marketplace_pluginrecordssource_url = marketplace_origin(source)instead of the hosted-URL-onlymanifest.source_url. The digest is dropped when there is no origin (local).marketplace/catalog_origin.py(new)marketplace/errors.pyMarketplaceOriginConflictError.deps/apm_resolver.pyresolve_marketplace_plugin; the error joins the recorded-resolution-error tuple, so the command exits 1 before the plan or any write.commands/marketplace/__init__.py,marketplace/reconcile.py[!]warning (reconcile dedupes symmetric pairs).scripts/architecture_linter/checks/marketplace_locked_evidence.py+ owner registrymarketplace-integrations-catalog-origin: requires the owner calls, and requires the origin check to come beforeresolve_marketplace_plugin.reference/lockfile-spec.md,consumer/installing-from-marketplaces.md,reference/cli/marketplace.md, apm-guidedependencies.mdandcommands.md.Diagrams
The legend: where the origin check runs on a locked object-form entry, relative to catalog I/O.
sequenceDiagram participant U as apm update participant R as APMDependencyResolver participant G as catalog_origin participant Reg as marketplaces.json participant C as catalog fetch U->>R: resolve name=x, marketplace=company R->>G: require_locked_catalog_origin G->>Reg: origin of alias company alt lock source_url missing (pre-0.37) G-->>R: accept else origins match G-->>R: accept else origins differ G-->>R: MarketplaceOriginConflictError (both origins) R-->>U: exit 1, nothing written end R->>C: resolve_marketplace_plugin C-->>R: selection + source_url + source_digestTrade-offs
apm updatefails closed". The check sits at the single resolver choke point, so on today'smainit also fires on a plainapm installthat re-resolves (design G3). Once [BUG] apm install re-resolves marketplace dependencies on every run instead of replaying the lockfile #3911 (lock-first replay) lands, only update and refresh re-resolve. Agreed with the [BUG] apm install re-resolves marketplace dependencies on every run instead of replaying the lockfile #3911 worker: its replay early-return comes first and this check sits immediately beforeresolve_marketplace_plugin. Whoever lands second rebases.apm updatestops before the lockfile phase by design (update.py/ install fast path, owned by fix(marketplace): explicit refresh revalidates catalogs or fails (#3279) #3910 and fix: derive install expected state from the lock #3900). Such rows never fail closed and gainsource_urlwhen the lock is next written.--pathin the same repo is not detected yet. The duplicate warning does compare--path, so one-catalog-per-audience monorepos do not warn.Benefits
source_url+source_digest, matching hosted-URL catalogs.[!]) atmarketplace addand in user-manifest reconcile.Testing
Scenario evidence
tests/integration/test_marketplace_origin_evidence_lifecycle.py::test_git_catalog_origin_is_locked_and_a_rebound_alias_fails_updatecompanynow points elsewhere,apm updaterefuses, names both catalogs, and changes nothingcompany-mirrorwith.gitsuffix →[!] ... same catalog ... 'company')source_urlnever fails closed and gains it on the next lock write...::test_pre_037_lock_without_origin_evidence_still_updates.git, keeps hosted URLs, skips local; digest is order-insensitivetests/unit/marketplace/test_parser.py(4 new tests)tests/integration/test_architecture_marketplace_locked_evidence.py(3 new),test_architecture_owner_rule_mutations.pycaseBoth lifecycle tests fail on
main(KeyError: 'source_url') and pass on this branch.Validation commands and results
How to test
APM_E2E_TESTS=1 APM_BINARY_PATH=.venv/bin/apm uv run --extra dev pytest tests/integration/test_marketplace_origin_evidence_lifecycle.py -p no:xdist.apm marketplace add <git-catalog-A> --name company, declare{name: x, marketplace: company}inapm.yml, runapm install, and checksource_urlinapm.lock.yaml.apm marketplace add <A>.git --name mirrorand expect a[!] ... same catalog as 'company'line.apm marketplace add <git-catalog-B> --name company, thenapm update --yes. Expect exit 1 naming both origins, with the lock unchanged.Changelog
## [Unreleased]inCHANGELOG.md(Fixed).Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regeneratedsource_url/source_digestlock fields are populated for more catalog kinds; noreq-XXXchanges.Co-authored-by: Copilot [email protected]