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
7 changes: 4 additions & 3 deletions crates/socket-patch-cli/CLI_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,12 @@ v5.0 removed the v4 spellings `scan --apply` (use `--mode agent`), `scan --vendo

**Experimental, and outside the semver policy.** This is for Socket Enterprise customers whose builds may only install through their own artifact host. `--patch-mirror-url` is hidden from `--help`. The flag, `SOCKET_PATCH_MIRROR_URL`, `SOCKET_PATCH_MIRROR_AUTHORIZATION`, the `redirect_mirror_*` codes and everything in this section may change or be removed in any release without a semver bump. The one exception is the rule "A run that was not given the mirror leaves its pins alone" below: it holds for every hosted run, mirror or not, and is additive (MINOR).

A patch mirror is a caching proxy the operator runs in front of the patch server that serves `https://patch.socket.dev/<path>` at `<base>/<path>`. `--patch-mirror-url <base>` / `SOCKET_PATCH_MIRROR_URL` names that base. It is tested against an Artifactory generic remote repository with npm, pnpm, yarn classic, yarn berry, pip, uv and Bundler; nothing else is tested yet, a Maven, Gradle or sbt build included.
A patch mirror is a caching proxy the operator runs in front of the patch server that serves `https://patch.socket.dev/<path>` at `<base>/<path>`. `--patch-mirror-url <base>` / `SOCKET_PATCH_MIRROR_URL` names that base. It is tested against an Artifactory generic remote repository with npm, pnpm, yarn classic, yarn berry, Bun, vlt, pip, uv, PDM, Pipenv, Bundler and Go; nothing else is tested yet, a Maven, Gradle or sbt build included, and Composer too (no Composer patch was available to test with).

* **Operator configuration only.** The base is read from the flag or the environment, never from `socket.yml` or any other repository file (the socket.yml trust boundary below): it names the host every later install fetches from and the host whose references `vex` attests. It must be an `http(s)` URL with a host and no userinfo, query or fragment, in the characters a grant URL may hold; trailing slashes are dropped. Anything else is a usage error (exit 2, `Error: --patch-mirror-url (or SOCKET_PATCH_MIRROR_URL) is not a usable patch mirror base URL: <why>`), checked before the project is read. The message never repeats the value. `apply` is the exception: it does not use the mirror and runs unattended from install hooks, so there a base it cannot use is no mirror and no error.
* **What hosted mode writes.** `scan` / `get --mode hosted` move each granted reference onto the mirror before anything else reads it: the artifact URL, and the registry index URL of a gem or Maven-layout reference, keep their path (grant token and patch uuid included) and take the base in place of scheme and authority. The integrity pins are unchanged, and a re-run is idempotent. A Go reference is not moved: its pin is the module path `patch.socket.dev/gopatch/<uuid>`, which names no host to fetch from. A Cargo or NuGet reference is not written at all: `skipped` / `redirect_mirror_unsupported` (their registry index is rendered by the patch server with its own absolute download URLs, which a mirror cannot rewrite; the detail names `--mode vendored`). A reference with no path to serve, or whose mirrored URL the grant gate refuses, is `skipped` / `redirect_mirror_url_refused`.
* **A project already pinned on the patch server.** npm, pnpm, yarn classic, `requirements.txt` and uv locks are re-pinned onto the mirror by the same run. The yarn berry, Bun, Bundler, Poetry and PDM rewriters own an earlier pin only on the host they are writing, so they leave a direct pin as it is: the patch is `skipped` (`redirect_unconfirmed`) and a `redirect_mirror_pin_not_moved` warning names the file, the host and the remedy (`rollback <purl>`, then the same command again).
* **What hosted mode writes.** `scan` / `get --mode hosted` move each granted reference onto the mirror before anything else reads it: the artifact URL, and the registry index URL of a gem or Maven-layout reference, keep their path (grant token and patch uuid included) and take the base in place of scheme and authority. The integrity pins are unchanged, and a re-run is idempotent. A Go reference is not moved: its pin is the module path `patch.socket.dev/gopatch/<uuid>`, which names no host to fetch from (go finds it through `GOPROXY`, see *Installing through the mirror*). A Cargo or NuGet reference is not written at all: `skipped` / `redirect_mirror_unsupported` (their registry index is rendered by the patch server with its own absolute download URLs, which a mirror cannot rewrite; the detail names `--mode vendored`). A reference with no path to serve, or whose mirrored URL the grant gate refuses, is `skipped` / `redirect_mirror_url_refused`.
* **Installing through the mirror.** The build installs from the pins alone, so it needs read access to the repository, and each package manager is handed the repository's credentials its own way: npm and pnpm send what `.npmrc` holds for the host (`//<host>/:_auth=…`); pip, uv, PDM and Pipenv what a netrc file holds for it; Bundler what `bundle config <host>` holds; vlt the token its keychain holds for the base or a URL above it (`vlt token add --registry=<base>`). yarn classic sends none for a URL pin outside its registry's path, and yarn berry and Bun none for a URL pin at all, so they need a repository that allows anonymous reads. Go fetches a Socket module over the GOPROXY protocol from the patch server's root, which the mirror serves at its base: list the base first in `GOPROXY` (`GOPROXY=<base>,https://proxy.golang.org`), and go fetches every Socket module through the mirror and moves past its 404 for every other module. The run writes nothing for this. go sends credentials (netrc, `GOAUTH`) only over `https`, so a plain-`http` mirror must allow anonymous reads. A generic remote repository is enough for Go; Artifactory OSS has no Go API (`/api/go/<repository>` answers 404 even for a repository of type Go).
* **A project already pinned on the patch server.** npm, pnpm, yarn classic, vlt, `requirements.txt`, uv and Pipenv locks are re-pinned onto the mirror by the same run. A Go pin is never moved (see *What hosted mode writes*). The yarn berry, Bun, Bundler, Poetry and PDM rewriters own an earlier pin only on the host they are writing, so they leave a direct pin as it is: the patch is `skipped` (`redirect_unconfirmed`) and a `redirect_mirror_pin_not_moved` warning names the file, the host and the remedy (`rollback <purl>`, then the same command again).
* **pnpm takes `trustLockfile`, never the registry route.** The registry address a grant carries (`npmRegistryUrl`, see "pnpm registry route") is not moved onto the mirror: the document the patch server answers there names the tarball on the patch server itself, which a mirror cannot rewrite, so pnpm would refuse a mirrored tarball against it. A mirrored tarball is no file of that address, which reads as no address, and a mirror run pins a pnpm project exactly as a patch service without registries does (`trustLockfile: true`, with nothing said of registries). A project an earlier run routed is taken off the route by the run that moves its pins onto the mirror: the registries (on the patch server, which the run still knows for one: the configured server, else the one the grants' registry addresses name), the overrides, the locks' records and the registry keys go as in *Leaving the route*, each entry reported as usual, and the `redirect_pnpm_trust_lockfile` warning says "the patch mirror serves no registry for `<name>@<version>`, …". `repair` and `scan --prune` clean up a route's unused entries the same with or without the setting; a registry of the CLI's name shape declared under the mirror's base or elsewhere on its host is on no patch server and is the user's.
* **The run's own downloads** (a wheel's metadata, a tarball's `package.json`, a gem for the stale-install refresh) read the patch server, not the mirror, which may want credentials the run does not have.
* **The mirror is checked before anything is pinned.** One `HEAD` for each mirrored reference the project's files do not already hold (a re-run that pins nothing new sends none), in candidate order, after the unconfigured-host guard and before the rewrite. The request carries no Socket credential, carries `SOCKET_PATCH_MIRROR_AUTHORIZATION` as its `Authorization` header when that is set, and follows no redirect. 2xx: that pin proceeds. 401 / 403 / 407, or a 3xx: nothing more is asked, every pin the mirror has not already refused proceeds, and one `redirect_mirror_unverified` warning says they were not checked. A transport failure, or no answer within the per-attempt timeout: nothing more is asked, and that reference and every one not yet asked about are `skipped` / `redirect_mirror_unavailable`. Any other answer: that reference is `skipped` / `redirect_mirror_unavailable`. Nothing is written for a skipped reference, and a warning names its package; when the mirror served none of the references it was asked about there is one warning instead, about the mirror. Exit 0 either way, files byte-identical for the skipped references, no `.npmrc` setting when nothing was pinned. No retry. A dry run checks too.
Expand Down
Loading
Loading