Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- `apm marketplace add` now accepts local filesystem paths, `file://` URIs, SSH URLs, and HTTPS URLs to any git host (Azure DevOps via `ADO_APM_PAT`, GitLab, Gitea, Bitbucket Server, self-hosted). Generic-git registrations fetch `marketplace.json` via `GitCache` and never forward APM tokens; local marketplaces read the manifest directly. `apm install <plugin>@<local-marketplace>` is fully supported, including marketplaces whose `marketplace.json` uses relative plugin sources.

### Security

- `GitCache` now disables git hooks (`core.hooksPath=/dev/null`) and skips submodule recursion on every clone, fetch, and checkout. Hardens APM against malicious upstreams, which is on-path for the new generic-git marketplace support.

### Fixed

- Copilot, Codex, Cursor, Claude, Windsurf, OpenCode, and Gemini adapters handle MCP v0.1 `runtimeArguments`/`packageArguments` with `variables` (no `type` key), matching the VS Code fix from #1444. (#1461, closes #1452, thanks @sergio-sisternes-epam)
Expand Down
33 changes: 33 additions & 0 deletions docs/src/content/docs/consumer/installing-from-marketplaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,39 @@ reproducible across machines and CI.
path that enforces it. See
[Governance on the consumer ramp](../governance-on-the-consumer-ramp/).

## Local and self-hosted marketplaces

`apm marketplace add` accepts more than GitHub-hosted repos. The same
register / browse / install / update workflow works against:

- **Local filesystem paths** -- `apm marketplace add /srv/marketplaces/agent-forge`
(or a relative path, or `~/code/marketplace`). Useful for
privacy-sensitive packages, offline workflows, and air-gapped
environments. Local marketplaces with relative plugin sources
install by copying from disk via `LocalDependencySource`.
- **`file://` URIs** -- `apm marketplace add file:///srv/marketplaces/agent-forge.git`.
Behaves the same as a local path.
- **Generic git URLs** -- any host APM does not classify as
GitHub or GitLab family flows through subprocess `git` and
`GitCache`. Includes Azure DevOps (auth via `ADO_APM_PAT`),
Gitea, Bitbucket Server, and self-hosted git servers.
- **SSH URLs** -- `git@gitea.example.com:org/repo.git`. The host
is extracted, classified, and routed through the matching
fetcher.

For generic-git marketplaces, `marketplace.json` is fetched via a
sparse-cone clone (only the manifest path is downloaded); APM does
not forward `GITHUB_APM_PAT` or `GITLAB_APM_TOKEN` to non-GitHub /
non-GitLab hosts. Authentication falls through to the host's
`*_APM_PAT` (e.g. `ADO_APM_PAT`) or your local
`git credential-manager`. See
[Authentication](../authentication/).

**Lockfile note.** Installs from a local marketplace record a
local-path source in `apm.lock.yaml`. Lockfiles produced this way
are machine-specific -- do not commit them into a shared repo. See
[lockfile reference](../../reference/lockfile-spec/).

## Where next

- [Install packages](../install-packages/) -- the full `apm install`
Expand Down
55 changes: 50 additions & 5 deletions docs/src/content/docs/reference/cli/marketplace.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ validating it, and publishing updates to consumer repositories).

```bash
# Consume
apm marketplace add REPO [--name N] [--branch B] [--host FQDN]
apm marketplace add SOURCE [--name N] [--ref R | --branch B] [--host FQDN]
apm marketplace list
apm marketplace browse NAME
apm marketplace update [NAME]
Expand Down Expand Up @@ -55,21 +55,66 @@ read; use `apm marketplace migrate` to fold them into `apm.yml`.

### `apm marketplace add`

Register a marketplace from a repo reference. Accepts `OWNER/REPO`,
`HOST/OWNER/.../REPO`, or an HTTPS git URL.
Register a marketplace from a source reference. Accepted forms:

- `OWNER/REPO` -- GitHub shorthand (`acme/marketplace`).
- `HOST/OWNER/.../REPO` -- non-GitHub host shorthand
(`gitlab.com/team/marketplace`).
- HTTPS URL -- any git host, including Azure DevOps, GitLab,
Gitea, Bitbucket Server, or a self-hosted git server.
- SSH URL -- `git@host:org/repo.git` style.
- Local filesystem path -- absolute (`/srv/marketplaces/agent-forge`),
relative (`./local-mkt`), or home-based (`~/code/marketplace`).
- `file://` URI -- `file:///srv/marketplaces/agent-forge.git`.

```bash
# GitHub shorthand
apm marketplace add my-org/awesome-agents

# GitLab via host shorthand
apm marketplace add gitlab.com/my-org/awesome-agents --host gitlab.com

# Azure DevOps (auth via ADO_APM_PAT, same as `apm install`)
apm marketplace add https://dev.azure.com/contoso/eng/_git/agent-forge \
--name agent-forge

# Gitea / Bitbucket Server / self-hosted git
apm marketplace add https://gitea.example.com/org/repo.git --name custom

# SSH
apm marketplace add git@gitea.example.com:org/repo.git --name custom

# Local filesystem (bare repo or working directory)
apm marketplace add /srv/marketplaces/agent-forge.git --name agent-forge

# file:// URI
apm marketplace add file:///srv/marketplaces/agent-forge.git --name agent-forge
```

| Flag | Description |
|---|---|
| `--name`, `-n` | Display name. Defaults to the repo name. |
| `--branch`, `-b` | Branch to track. Default: `main`. |
| `--host` | Git host FQDN. Default: `github.com`. |
| `--ref`, `-r` | Git ref (branch, tag, or SHA). Default: `main`. |
| `--branch`, `-b` | Deprecated alias for `--ref`. |
| `--host` | Git host FQDN. Default: `github.com`. Ignored when `SOURCE` is a URL or local path. |
| `--verbose`, `-v` | Show detailed output. |

**Trust boundary.** APM forwards its authentication tokens
(`GITHUB_APM_PAT`, `GITLAB_APM_TOKEN`) only when the marketplace
host is classified as GitHub or GitLab family. For any other host
-- generic HTTPS, SSH, Azure DevOps, self-hosted -- the
marketplace is fetched via subprocess `git` through `GitCache`,
and authentication falls through to the host's APM PAT (e.g.
`ADO_APM_PAT` for Azure DevOps) or your local
`git credential-manager`. See
[`getting-started/authentication`](../../../getting-started/authentication/).

**Azure DevOps.** ADO-hosted marketplaces fetch `marketplace.json`
via a sparse-cone git clone (not the ADO REST API), so authentication
uses `ADO_APM_PAT` -- identical to how `apm install` handles
ADO-hosted package dependencies. See
[`consumer/private-and-org-packages`](../../../consumer/private-and-org-packages/).

### `apm marketplace list`

List every registered marketplace with its source URL and tracked
Expand Down
2 changes: 1 addition & 1 deletion packages/apm-guide/.apm/skills/apm-usage/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ If no `--target`, no `targets:` in `apm.yml`, and no harness signal is present,

| Command | Purpose | Key flags |
|---------|---------|-----------|
| `apm marketplace add OWNER/REPO` | Register a marketplace (also accepts `HOST/OWNER/REPO`, nested `HOST/group/sub/.../REPO`, or full HTTPS URL) | `-n NAME`, `-b BRANCH`, `--host HOST` |
| `apm marketplace add SOURCE` | Register a marketplace. `SOURCE` accepts `OWNER/REPO`, `HOST/OWNER/REPO`, nested `HOST/group/sub/.../REPO`, HTTPS URL (any git host -- GitHub, GitLab, ADO, Gitea, self-hosted), SSH URL (`git@host:org/repo.git`), local filesystem path, or `file://` URI. | `-n NAME`, `-r REF`, `--host HOST` |
| `apm marketplace list` | List registered marketplaces | -- |
| `apm marketplace browse NAME` | Browse marketplace plugins | -- |
| `apm marketplace update [NAME]` | Update marketplace index | -- |
Expand Down
70 changes: 70 additions & 0 deletions scripts/e2e/marketplace_local_e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
# Manual end-to-end reproduction of the local-marketplace user flow.
#
# Not wired into CI -- keeps CI hermetic and avoids depending on
# external repos. Reproduces the workflow the requesting team was
# trapped in (manual editing of ~/.apm/marketplaces.json + cache
# pre-seeding) and validates the new register / browse / install /
# update / refresh / drift paths.
#
# Prereqs:
# - apm CLI on PATH (or run from the repo's venv)
# - git
# - network access for the initial bare clone of the demo repo
#
# Cleanup: removes /tmp/apm-e2e/ on success. Re-run is idempotent.

set -euo pipefail

E2E_ROOT="/tmp/apm-e2e"
# Point this at any git remote that exposes a marketplace.json at the root of
# its default branch. Override via DEMO_REMOTE=... before invoking.
DEMO_REMOTE="${DEMO_REMOTE:-}"
BARE_REPO="${E2E_ROOT}/demo-marketplace.git"

if [ -z "${DEMO_REMOTE}" ]; then
echo "Set DEMO_REMOTE to a git URL exposing marketplace.json, e.g.:" >&2
echo " DEMO_REMOTE=https://example.com/org/repo.git $0" >&2
exit 2
fi

rm -rf "${E2E_ROOT}"
mkdir -p "${E2E_ROOT}"

echo "[1/7] Cloning demo marketplace into a local bare repo..."
git clone --bare "${DEMO_REMOTE}" "${BARE_REPO}"

echo "[2/7] Registering via local filesystem path (kind=local)..."
apm marketplace add "${BARE_REPO}" --name demo-local

echo "[3/7] Registering same repo via file:// URI (kind=local, exercises git show)..."
apm marketplace add "file://${BARE_REPO}" --name demo-fileuri

echo "[4/7] Browsing both registrations..."
apm marketplace browse demo-local
apm marketplace browse demo-fileuri

echo "[5/7] Picking the first plugin from each registration and installing..."
PLUGIN_NAME="$(apm marketplace browse demo-local --json 2>/dev/null | python -c 'import json,sys; print(json.load(sys.stdin)["plugins"][0]["name"])' || echo "")"
if [ -n "${PLUGIN_NAME}" ]; then
apm install "${PLUGIN_NAME}@demo-local"
apm install "${PLUGIN_NAME}@demo-fileuri"
echo " Installed ${PLUGIN_NAME} from both registrations."
else
echo " No plugins exposed by the demo marketplace; skipping install."
fi

echo "[6/7] Refreshing both marketplaces (validates GitCache ls-remote refresh path)..."
apm marketplace update demo-local
apm marketplace update demo-fileuri

echo "[7/7] Drift smoke: marketplace update picks up working-tree edits without manual cache flushing."
# (Would need a writable working-tree mirror; bare repos don't have one.
# Documented as a manual step: edit the working tree, re-run update,
# observe the change.)

echo ""
echo "E2E flow completed successfully."
echo "Workspace: ${E2E_ROOT}"
echo "Registered marketplaces:"
apm marketplace list
59 changes: 47 additions & 12 deletions src/apm_cli/cache/git_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@
# Full SHA pattern: 40 hex characters
_SHA_RE = re.compile(r"^[0-9a-f]{40}$", re.IGNORECASE)


def _safe_git_args() -> list[str]:
"""Return hardening ``-c`` args prepended to every git subprocess.

- ``core.hooksPath=/dev/null`` disables any hook script that a
malicious upstream might ship (``.git/hooks/post-checkout`` etc.)
so a clone or checkout cannot trigger arbitrary code execution.
- ``submodule.recurse=false`` prevents any subcommand from
recursing into attacker-controlled submodule URLs.

These flags are scoped per-invocation via ``-c`` and never mutate
the user's gitconfig. The cache layer is the single source of
truth for git subprocess invocation -- callers must use this
helper rather than ad-hoc ``git`` argv construction.
"""
from ..utils.git_env import git_long_paths_args

return [
*git_long_paths_args(),
"-c",
"core.hooksPath=/dev/null",
"-c",
"submodule.recurse=false",
]


# Partial bare-cache flavor suffix (perf #1433 follow-up).
# When a caller requests sparse_paths, we use a separate bare keyed at
# ``<shard>__p`` cloned with ``--filter=blob:none``. The partial bare
Expand Down Expand Up @@ -214,7 +240,7 @@ def _ls_remote_resolve(
# auth-delegated: cache-layer ref resolution runs after lockfile
# already pinned the commit; no PAT->bearer fallback applies here
# (env is sanitized, no embedded creds).
cmd = [git_exe, "ls-remote", url]
cmd = [git_exe, *_safe_git_args(), "ls-remote", url]
if ref:
cmd.append(ref)

Expand Down Expand Up @@ -287,7 +313,7 @@ def _ensure_bare_repo(

Returns the path to the bare repo directory.
"""
from ..utils.git_env import get_git_executable, git_long_paths_args, git_subprocess_env
from ..utils.git_env import get_git_executable, git_subprocess_env

bare_shard = shard_key + (_PARTIAL_BARE_SUFFIX if partial else "")
bare_dir = self._db_root / bare_shard
Expand Down Expand Up @@ -318,7 +344,14 @@ def _ensure_bare_repo(
os.chmod(str(staged), 0o700)

subprocess_env = env if env is not None else git_subprocess_env()
clone_args = [git_exe, *git_long_paths_args(), "clone", "--bare", "--no-tags"]
clone_args = [
git_exe,
*_safe_git_args(),
"clone",
"--bare",
"--no-tags",
"--no-recurse-submodules",
]
if partial:
# Promisor partial clone: trees + commits only. Blobs
# arrive lazily via the remote when the consumer needs
Expand Down Expand Up @@ -368,10 +401,11 @@ def _ensure_bare_repo(
subprocess.run(
[
git_exe,
*git_long_paths_args(),
*_safe_git_args(),
"clone",
"--bare",
"--no-tags",
"--no-recurse-submodules",
url,
str(staged),
],
Expand Down Expand Up @@ -456,7 +490,7 @@ def _create_checkout(
get the lock and return immediately. Critical for CI matrix
builds where multiple jobs hit the same uncached repo.
"""
from ..utils.git_env import get_git_executable, git_long_paths_args, git_subprocess_env
from ..utils.git_env import get_git_executable, git_subprocess_env

bare_shard = shard_key + (_PARTIAL_BARE_SUFFIX if promisor_url else "")
bare_dir = self._db_root / bare_shard
Expand Down Expand Up @@ -505,11 +539,12 @@ def _create_checkout(
subprocess.run(
[
git_exe,
*git_long_paths_args(),
*_safe_git_args(),
"clone",
"--local",
"--shared",
"--no-checkout",
"--no-recurse-submodules",
str(bare_dir),
str(staged),
],
Expand All @@ -536,7 +571,7 @@ def _create_checkout(
subprocess.run(
[
git_exe,
*git_long_paths_args(),
*_safe_git_args(),
"-C",
str(staged),
"config",
Expand All @@ -558,13 +593,13 @@ def _create_checkout(
staged,
list(sparse_paths),
env=subprocess_env,
extra_git_args=git_long_paths_args(),
extra_git_args=_safe_git_args(),
)
# Checkout the specific SHA
subprocess.run(
[
git_exe,
*git_long_paths_args(),
*_safe_git_args(),
"-C",
str(staged),
"checkout",
Expand Down Expand Up @@ -606,7 +641,7 @@ def _bare_has_sha(self, bare_dir: Path, sha: str, *, env: dict[str, str] | None
subprocess_env = env if env is not None else git_subprocess_env()
try:
result = subprocess.run(
[git_exe, "-C", str(bare_dir), "cat-file", "-t", sha],
[git_exe, *_safe_git_args(), "-C", str(bare_dir), "cat-file", "-t", sha],
capture_output=True,
text=True,
timeout=10,
Expand Down Expand Up @@ -648,7 +683,7 @@ def _fetch_into_bare_locked(
# so we don't pull all blobs reachable from the new SHA. Detected
# via shard-suffix naming convention (cheap, no git config probe).
is_partial = bare_dir.name.endswith(_PARTIAL_BARE_SUFFIX)
fetch_args = [git_exe, "-C", str(bare_dir), "fetch"]
fetch_args = [git_exe, *_safe_git_args(), "-C", str(bare_dir), "fetch"]
if is_partial:
fetch_args += ["--filter=blob:none"]
fetch_args += [url, sha]
Expand All @@ -664,7 +699,7 @@ def _fetch_into_bare_locked(
except subprocess.CalledProcessError:
# Some servers don't allow fetching by SHA -- fetch all refs
subprocess.run(
[git_exe, "-C", str(bare_dir), "fetch", "--all"],
[git_exe, *_safe_git_args(), "-C", str(bare_dir), "fetch", "--all"],
capture_output=True,
text=True,
timeout=120,
Expand Down
Loading
Loading