From 6090d7e762bbb96b01a63409e85be17e4f654d0d Mon Sep 17 00:00:00 2001 From: Sweepy Date: Sun, 15 Nov 2026 22:46:51 +0000 Subject: [PATCH 1/4] ci: publish the image from a tag-only job, and move workflow shell into nu tasks The image job ran pull request code with packages, id-token and attestations write. It now builds and smoke-tests with contents: read and hands the index, package cache and SBOMs to image-publish, which only tags run and which alone holds the write permissions. The release job downloads only the dist-* archives, so the image artifact never becomes a release asset. The tag check, the archive smoke test and the Action workflow's release pin are nu tasks (release:check-tag, release:smoke, action:pin-release) instead of inline bash. --- .github/workflows/action.yml | 14 ++--- .github/workflows/release.yml | 100 +++++++++++++++++++++++----------- mise-tasks/action/pin-release | 27 +++++++++ mise-tasks/release/check-tag | 11 ++++ mise-tasks/release/smoke | 24 ++++++++ 5 files changed, 138 insertions(+), 38 deletions(-) create mode 100755 mise-tasks/action/pin-release create mode 100755 mise-tasks/release/check-tag create mode 100755 mise-tasks/release/smoke diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 22bb4a48..72d4fddd 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -7,6 +7,7 @@ on: paths: &paths - "action.yml" - ".github/workflows/action.yml" + - "mise-tasks/action/**" - "tests/action/**" pull_request: paths: *paths @@ -29,22 +30,21 @@ jobs: - uses: actions/checkout@v7.0.1 with: persist-credentials: false + # Only the task's tools, enabled per step: the action's own mise exec + # must not inherit the list. - uses: jdx/mise-action@v5.2.4 with: - install: false cache: false + env: + MISE_ENABLE_TOOLS: nu,gh # The action runs the latest release, which can predate this checkout's # schema. Pin that release here and write its own schema beside the # stand-in config, so the two always match. - id: release env: + MISE_ENABLE_TOOLS: nu,gh GH_TOKEN: ${{ github.token }} - run: | - version=$(gh release view --repo "$GITHUB_REPOSITORY" --json tagName --jq '.tagName | ltrimstr("v")') - schema=$(cd "$RUNNER_TEMP" && MISE_MINIMUM_RELEASE_AGE=0 mise exec "packslip:sweepies/count-patchula@$version" -- patchula config schema) - rm -f tests/action/PatchulaConfig.pkl - printf '%s\n' "$schema" > tests/action/PatchulaConfig.pkl - echo "version=$version" >> "$GITHUB_OUTPUT" + run: mise run action:pin-release # A GitHub Actions-only config stands in for this repository's own, so # the dry run plans real updates without lockfile tools. - uses: $/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e4b1bd0d..9907ec78 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,8 +3,9 @@ name: Release # Pushing a v* tag builds static archives, checks each one runs on its own # platform, builds and pushes the server image from the Linux archives, # publishes the GitHub release with a signed packslip manifest, then lets -# communique rewrite the notes. Only tags run it: pull requests don't build the -# release archives or the image. +# communique rewrite the notes. A pull request that changes the image or this +# workflow builds and checks the Linux archives and the image, with read-only +# permissions, and publishes nothing. on: push: tags: ["v*"] @@ -12,6 +13,7 @@ on: paths: - image/** - mise-tasks/image/** + - mise-tasks/release/smoke - .github/workflows/release.yml permissions: @@ -67,15 +69,7 @@ jobs: cache: false - name: Check the tag matches the crate version if: github.event_name == 'push' - run: | - # `path+file:///…/crates/cli#patchula-cli@0.7.0`: the version is the - # last field. - id=$(cargo pkgid --locked -p patchula-cli) - version=${id##*[@#]} - if [ "$GITHUB_REF_NAME" != "v$version" ]; then - echo "Tag $GITHUB_REF_NAME does not match patchula-cli $version" >&2 - exit 1 - fi + run: mise run release:check-tag "$GITHUB_REF_NAME" - name: Package env: TARGET: ${{ matrix.target }} @@ -95,24 +89,31 @@ jobs: runs-on: >- ${{ fromJSON('{"linux-x64-musl": "ubuntu-latest", "linux-arm64-musl": "ubuntu-24.04-arm", "darwin-arm64": "macos-26"}')[matrix.platform] }} timeout-minutes: 10 + env: + # Only the task runner, not the workspace toolchains. + MISE_ENABLE_TOOLS: nu steps: + - uses: actions/checkout@v7.0.1 + with: + persist-credentials: false - uses: actions/download-artifact@v8.0.2 with: + pattern: dist-* path: dist merge-multiple: true + - uses: jdx/mise-action@v5.2.4 + with: + cache: false - name: Run the binary env: PLATFORM: ${{ matrix.platform }} - run: | - mkdir smoke - tar -xzf dist/patchula-v*-"$PLATFORM".tar.gz -C smoke - smoke/bin/patchula --version | grep -E '^patchula [0-9]+\.[0-9]+\.[0-9]+' - smoke/bin/patchula config check --help > /dev/null + run: mise run release:smoke "$PLATFORM" # Both platforms are built and smoke-tested before anything is pushed, and # the push must publish the very index that ran. Nothing runs under # emulation except melange's two copy steps and the arm64 image's quick - # checks. + # checks. This job runs a pull request's code, so it holds no write + # permissions; image-publish, which only tags run, pushes what it built. image: name: Container image needs: smoke @@ -120,11 +121,6 @@ jobs: timeout-minutes: 30 permissions: contents: read - # Logs in to GHCR and pushes the image. - packages: write - # Signs and stores the image's provenance attestation. - id-token: write - attestations: write env: # Only nu and the image tools, not the workspace toolchains. MISE_ENABLE_TOOLS: nu,melange,apko @@ -157,31 +153,71 @@ jobs: GITHUB_TOKEN: ${{ github.token }} run: mise run image:smoke - run: mise run image:smoke --arch arm64 + # What image:push needs to publish this exact index again: the index + # the smoke test ran, the package cache and local packages it rebuilds + # from, and apko's SBOMs. - if: github.event_name == 'push' - uses: docker/login-action@v4.7.0 + uses: actions/upload-artifact@v7.0.2 + with: + name: image + path: | + target/image/image.tar + target/image/apk-cache + target/image/packages + target/image/sbom + if-no-files-found: error + retention-days: 1 + + image-publish: + name: Publish the container image + needs: image + if: github.event_name == 'push' + runs-on: ubuntu-latest + timeout-minutes: 20 + permissions: + contents: read + # Logs in to GHCR and pushes the image. + packages: write + # Signs and stores the image's provenance attestation. + id-token: write + attestations: write + env: + # Only nu and apko, not the workspace toolchains. + MISE_ENABLE_TOOLS: nu,apko + MISE_LOCKED: "1" + steps: + - uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - uses: actions/download-artifact@v8.0.2 + with: + name: image + path: target/image + - uses: jdx/mise-action@v5.2.4 + with: + # A release never restores a cache, so nothing cached reaches the image. + cache: false + install_args: nu + - uses: docker/login-action@v4.7.0 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ github.token }} - id: push - if: github.event_name == 'push' run: mise run image:push - - if: github.event_name == 'push' - uses: actions/attest-build-provenance@v4.2.2 + - uses: actions/attest-build-provenance@v4.2.2 with: subject-name: ghcr.io/sweepies/count-patchula subject-digest: ${{ steps.push.outputs.digest }} push-to-registry: true # apko's SBOM for each platform, attested to that platform's image. - - if: github.event_name == 'push' - uses: actions/attest-sbom@v4.1.0 + - uses: actions/attest-sbom@v4.1.0 with: subject-name: ghcr.io/sweepies/count-patchula subject-digest: ${{ steps.push.outputs.amd64 }} sbom-path: target/image/sbom/sbom-x86_64.spdx.json push-to-registry: true - - if: github.event_name == 'push' - uses: actions/attest-sbom@v4.1.0 + - uses: actions/attest-sbom@v4.1.0 with: subject-name: ghcr.io/sweepies/count-patchula subject-digest: ${{ steps.push.outputs.arm64 }} @@ -190,7 +226,7 @@ jobs: release: name: Publish - needs: [smoke, image] + needs: [smoke, image-publish] if: github.event_name == 'push' runs-on: ubuntu-latest timeout-minutes: 20 @@ -203,8 +239,10 @@ jobs: with: fetch-depth: 0 persist-credentials: false + # The archives only: the image artifact is not a release asset. - uses: actions/download-artifact@v8.0.2 with: + pattern: dist-* path: dist merge-multiple: true - name: Create a draft release diff --git a/mise-tasks/action/pin-release b/mise-tasks/action/pin-release new file mode 100755 index 00000000..b9eefae1 --- /dev/null +++ b/mise-tasks/action/pin-release @@ -0,0 +1,27 @@ +#!/usr/bin/env nu +#MISE description="In the Action workflow: pin the latest release for the dry run, write that release's config schema beside the stand-in config, and hand its version to the action step through GITHUB_OUTPUT" +#MISE tools={gh="2.103.3"} + +# The action runs a released Count, which can predate this checkout's schema, +# so the stand-in config must amend the release's own schema. +def main [] { + let version = ^gh release view --repo $env.GITHUB_REPOSITORY --json tagName | from json | get tagName | str replace --regex '^v' '' + let target = "tests/action/PatchulaConfig.pkl" | path expand --no-symlink + let schema = release-schema $version + # The checkout's file links to the repository's schema: replace the link, + # not the file it points to. + rm --force $target + $schema | save $target + $"version=($version)\n" | save --append $env.GITHUB_OUTPUT + print $"pinned ($version) and wrote its schema" +} + +# mise runs outside the checkout, so none of its config applies, and it +# installs the release whatever tools the workflow step enabled. +def release-schema [version: string]: nothing -> string { + cd $env.RUNNER_TEMP + hide-env --ignore-errors MISE_ENABLE_TOOLS + with-env {MISE_MINIMUM_RELEASE_AGE: "0"} { + ^mise exec $"packslip:sweepies/count-patchula@($version)" -- patchula config schema + } +} diff --git a/mise-tasks/release/check-tag b/mise-tasks/release/check-tag new file mode 100755 index 00000000..8d24bd30 --- /dev/null +++ b/mise-tasks/release/check-tag @@ -0,0 +1,11 @@ +#!/usr/bin/env nu +#MISE description="In the release workflow: check that the pushed tag is v of patchula-cli, so a tag never releases another version" +#USAGE arg "" help="The pushed tag, such as v1.2.3" + +def main [tag: string] { + let version = ^cargo metadata --format-version 1 --no-deps --locked | from json | get packages | where name == "patchula-cli" | first | get version + if $tag != $"v($version)" { + error make --unspanned {msg: $"tag ($tag) does not match patchula-cli ($version)"} + } + print $"($tag) matches patchula-cli ($version)" +} diff --git a/mise-tasks/release/smoke b/mise-tasks/release/smoke new file mode 100755 index 00000000..201cef35 --- /dev/null +++ b/mise-tasks/release/smoke @@ -0,0 +1,24 @@ +#!/usr/bin/env nu +#MISE description="In the release workflow: unpack one platform's archive from dist and check that its patchula runs and reports the archive's version" +#USAGE arg "" help="The archive's platform, such as linux-x64-musl" + +def main [platform: string] { + let archives = glob $"dist/patchula-v*-($platform).tar.gz" + if ($archives | length) != 1 { + error make --unspanned {msg: $"expected one ($platform) archive in dist, found ($archives | length)"} + } + let archive = $archives | first + let name = $archive | path basename + let version = $name | parse $"patchula-v{version}-($platform).tar.gz" | first | get version + let out = mktemp --directory --tmpdir patchula-smoke.XXXXXX + ^tar --extract --gzip --file $archive --directory $out + let patchula = $out | path join bin patchula + let reported = ^$patchula --version | str trim + if $reported != $"patchula ($version)" { + error make --unspanned {msg: $"($name) reports '($reported)', not patchula ($version)"} + } + if (^$patchula config check --help | complete).exit_code != 0 { + error make --unspanned {msg: $"($name): patchula config check --help failed"} + } + print $"ok ($name): ($reported)" +} From 30fd8e419ff4c8bdd3d501b3ed1a4d8faf17f104 Mon Sep 17 00:00:00 2001 From: Sweepy Date: Sun, 15 Nov 2026 22:46:51 +0000 Subject: [PATCH 2/4] fix(action): refuse Count releases before 0.9.0 The action kept fallbacks for releases up to 0.4.0, which took --cache as the SQLite file, and for releases without patchula cache schema, which it keyed by version. 0.9.0 is the first release with cache schema; the action now fails the step with a clear error for an older version or binary and always passes the cache directory. --- action.yml | 27 ++++++------------- docs/src/content/docs/guide/github-actions.md | 12 ++++++--- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/action.yml b/action.yml index 3412ed8a..85c366a2 100644 --- a/action.yml +++ b/action.yml @@ -21,10 +21,10 @@ inputs: description: Print the planned branches and diffs without writing to GitHub. default: "false" version: - description: Count Patchula version to run. Empty means the version of this action, or the latest release when the action is not used at a release tag. + description: Count Patchula version to run, 0.9.0 or later. Empty means the version of this action, or the latest release when the action is not used at a release tag. default: "" binary: - description: The path to a patchula binary to run instead of installing a release, such as one built from source. Overrides version. + description: The path to a patchula binary to run instead of installing a release, such as one built from source, 0.9.0 or later. Overrides version. default: "" settings: description: Path to an operator settings file (amending PatchulaSettings.pkl) for HTTP limits and other operator settings. The action does not check out the repository, so check it out first when the file lives there. Empty falls back to PATCHULA_SETTINGS, then ~/.config/patchula/settings.pkl, then the defaults. @@ -46,8 +46,8 @@ runs: working_directory: ${{ runner.temp }} # Installs the binary first, so the cache below can be keyed by the cache # schema it reads. A binary refuses a cache from a newer schema, so each - # schema keeps its own lineage. Older releases, without - # `patchula cache schema`, key by their version instead. + # schema keeps its own lineage. The action runs 0.9.0 and later, the + # releases with `patchula cache schema`, and refuses an older binary. - name: Install Count Patchula id: patchula shell: bash @@ -78,16 +78,12 @@ runs: fi bin=$(cd "$RUNNER_TEMP" && MISE_MINIMUM_RELEASE_AGE=0 mise exec "packslip:sweepies/count-patchula@$version" -- sh -c 'command -v patchula') fi - if schema=$("$bin" cache schema 2>/dev/null) && [[ "$schema" =~ ^[0-9]+$ ]]; then - lineage="s$schema" - elif [[ "$("$bin" --version)" =~ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then - lineage="v${BASH_REMATCH[1]}" - else - echo "::error::cannot tell which cache $bin reads" >&2 + if ! schema=$("$bin" cache schema) || ! [[ "$schema" =~ ^[0-9]+$ ]]; then + echo "::error::$bin has no 'patchula cache schema', so it predates 0.9.0, the oldest release this action runs. Set version (or binary) to 0.9.0 or later." >&2 exit 1 fi echo "bin=$bin" >> "$GITHUB_OUTPUT" - echo "lineage=$lineage" >> "$GITHUB_OUTPUT" + echo "lineage=s$schema" >> "$GITHUB_OUTPUT" # The cache holds HTTP validators, write receipts and the lockfile tool # store. Each run saves a new entry and restores the newest one. - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 @@ -128,12 +124,5 @@ runs: args+=("${extra[@]}") fi mkdir -p "$CACHE_DIR" - # The version input can install any release. Releases up to 0.4.0 take - # --cache as the SQLite file; later ones take the directory holding it. - help=$("$PATCHULA_BIN" run --help) - if [[ "$help" == *'--cache '* ]]; then - args+=(--cache "$CACHE_DIR") - else - args+=(--cache "$CACHE_DIR/cache.sqlite") - fi + args+=(--cache "$CACHE_DIR") "$PATCHULA_BIN" "${args[@]}" diff --git a/docs/src/content/docs/guide/github-actions.md b/docs/src/content/docs/guide/github-actions.md index 0bda16e0..b7b491df 100644 --- a/docs/src/content/docs/guide/github-actions.md +++ b/docs/src/content/docs/guide/github-actions.md @@ -123,8 +123,8 @@ build these files on one organization module. | `repositories` | this repository | `owner/repo` names, separated by spaces or newlines | | `all-repos` | `false` | Every repository the token can reach | | `dry-run` | `false` | Print planned branches and diffs without writing | -| `version` | the action's version, or the latest release when the action is not used at a release tag | The Count version to install, such as `@@version@@` | -| `binary` | | The path to a `patchula` binary to run instead of installing a release, such as one built from source to try unreleased changes. Overrides `version` | +| `version` | the action's version, or the latest release when the action is not used at a release tag | The Count version to install, such as `@@version@@`; 0.9.0 or later | +| `binary` | | The path to a `patchula` binary to run instead of installing a release, such as one built from source to try unreleased changes; 0.9.0 or later. Overrides `version` | | `settings` | | The path to an operator [settings](/reference/settings/) file, for HTTP limits and other operator settings. The action does not check out your repository, so add `actions/checkout` before it when the file lives there. Empty falls back to `PATCHULA_SETTINGS`, then `~/.config/patchula/settings.pkl`, then the defaults | | `args` | | Extra `patchula run` arguments, such as `--config-dir policy` | @@ -133,7 +133,13 @@ saved after every run and restored on the next, so later runs are much faster than the first. Entries are keyed by the cache schema the binary reads (`patchula cache schema`), so moving to a release with a new schema, or back to an older one, starts from a cold cache instead of failing on a database it -cannot read. Releases older than the command key by their version. Where a repository keeps +cannot read. + +The action runs Count Patchula 0.9.0 or later, the first release with +`patchula cache schema`. Given an older `version` or `binary`, it fails the +step with an error naming the binary rather than running it. + +Where a repository keeps [`.github/workflows/actions.lock`](/guide/managers/#actions-lock), the lockfile tool authenticates with the token the run was given — the `token` input's token — scoped to the repository when the App can mint one. From 52841e4f1754116f5ec1b8d033059a6946e38e2e Mon Sep 17 00:00:00 2001 From: Sweepy Date: Sun, 15 Nov 2026 22:46:51 +0000 Subject: [PATCH 3/4] docs(threat-model): state the lockfile exception The threat model said a repository never runs code, while the lockfile guide said Bundler, dotnet, uv, Poetry, Yarn and npm do. The threat model now names those tools, what triggers them, what their code can reach and which guards still hold, and the lockfiles guide points to it. --- docs/src/content/docs/guide/lockfiles.md | 44 ++++++---- .../content/docs/internals/threat-model.md | 86 +++++++++++++++++-- 2 files changed, 104 insertions(+), 26 deletions(-) diff --git a/docs/src/content/docs/guide/lockfiles.md b/docs/src/content/docs/guide/lockfiles.md index c6ca43e9..905aee7d 100644 --- a/docs/src/content/docs/guide/lockfiles.md +++ b/docs/src/content/docs/guide/lockfiles.md @@ -325,16 +325,23 @@ lockfile needs none of them. Output is kept only when something fails, at most 4 KiB of each stream. -:::danger[Lockfile tools run repository and package code] -Regenerating a lockfile runs code from the repository and from its -dependencies: Bundler evaluates the Gemfile and gemspecs, dotnet evaluates -MSBuild projects and targets, uv and Poetry build source distributions to read -their metadata, and Yarn and npm prepare git dependencies by running their -build scripts. The tools run unsandboxed, as the Count's own user, so that code -can read anything the Count can: its environment and settings secrets, the -GitHub App credentials, and what other runs on the same host hold at the time. -Run the Count only for repositories you trust that far, or turn lockfile -updates off for the others. +:::danger[Some lockfile tools run repository and package code] +A few tools cannot regenerate their lockfile without running code from the +repository or the dependencies it names: Bundler evaluates the Gemfile and +gemspecs, dotnet evaluates MSBuild projects and runs restore's targets, uv and +Poetry build local projects and source distributions that lack static +metadata, and Yarn Berry and npm can prepare git dependencies by running their +build scripts. This is the one exception to the rule that a repository never +runs code on the Count's machine (see the +[threat model](/internals/threat-model/#the-lockfile-exception)). Every other +lockfile tool runs none. + +These tools run unsandboxed, as the Count's own user, so that code can read +anything the Count can: its environment and settings secrets, the GitHub App +credentials, and what other runs on the same host hold at the time. There is +no setting that turns them on: they run whenever a repository commits one of +those lockfiles. Run the Count only for repositories you trust that far, or +keep the others away from those managers with a `--config-dir` policy. ::: ## Tool caches @@ -374,13 +381,13 @@ partition with Go's default environment, so repositories with internal modules keep working. Partitions keep honest repositories' private packages apart; they are -not an isolation boundary. Lockfile tools run repository code +not an isolation boundary. The tools that run repository code do so unsandboxed — Bundler evaluating the Gemfile, uv or Poetry building -sdists, MSBuild evaluating project files — so code from any installed -repository can read every partition on the host, `public`, another -installation's and another credential set's alike. That is within the -trust model above: every installation is trusted, and lockfile tools run -repository code anyway. +sdists, MSBuild evaluating project files — so code from any repository +that uses one of them can read every partition on the host, `public`, +another installation's and another credential set's alike. That follows +from the lockfile exception above: running the Count for such a +repository trusts its writers with everything the Count can read. A partition a run uses is held shared, so eviction never removes one in use, and tools whose caches are not documented for concurrent use — aube, Bun, @@ -395,8 +402,9 @@ Lockfile tools get a [registry entry's](/guide/sources/#private-registries) credentials only when the entry sets `tools = true`; APM, Nix, `mise lock` and the Gradle wrapper read no private registries and get none. In the server, `allowedInstallations` decides which installations' tools are given them, -and the CLI gives them to every repository it runs on. As lockfile tools run -repository and package code, any repository the Count processes can read a +and the CLI gives them to every repository it runs on. As some lockfile tools run +repository code (see [Isolation](#isolation)) and any repository can commit a +lockfile for one, any repository the Count processes can read a credential it holds, so neither setting is a boundary. Each tool gets the credentials in the form it reads, only for its own run: diff --git a/docs/src/content/docs/internals/threat-model.md b/docs/src/content/docs/internals/threat-model.md index e94b21d7..299c5f59 100644 --- a/docs/src/content/docs/internals/threat-model.md +++ b/docs/src/content/docs/internals/threat-model.md @@ -34,11 +34,12 @@ It may: It may not: -- run code on the Count's machine. That covers plugin backends (asdf, vfox), - lifecycle scripts, hooks, build logic, credential helpers and anything else - that executes something the repository chose. The Count runs as one user, - with his credentials, his cache and, under an App, the private key, so code - running there reaches all of them. +- run code on the Count's machine, except through the lockfile tools listed + under [the lockfile exception](#the-lockfile-exception). That covers plugin + backends (asdf, vfox), lifecycle scripts, hooks, build logic, credential + helpers and anything else that executes something the repository chose. + The Count runs as one user, with his credentials, his cache and, under an + App, the private key, so code running there reaches all of them. - obtain a credential wider than its own reach: the installation token, the App key, another repository's token, an operator registry credential meant for other repositories, or the machine's own credentials. Cloud @@ -48,16 +49,85 @@ It may not: shared between repositories, such as listings and catalogs, are shared only when they came from public data or from a credential the reader may hold. +## The lockfile exception + +Some lockfiles can only be regenerated by a tool that evaluates repository +code. The Count runs those tools anyway, because a lockfile written any other +way would not be the one the ecosystem's tool writes. This is the only place a +repository runs code on the Count's machine. + +**Which tools.** Each of these runs code the repository wrote or chose as part +of resolving, with no flag that turns it off: + +- Bundler (`bundle lock`) evaluates the `Gemfile` and any gemspecs it loads as + Ruby. +- dotnet (`dotnet restore`) evaluates MSBuild project, props and targets + files, and runs the targets restore reaches, which can run commands. +- uv (`uv lock`) and Poetry (`poetry lock`) build local projects and source + distributions that lack static metadata through their PEP 517 build + backends, which run `setup.py` and other build code. +- Yarn Berry and npm can prepare a git dependency by packing it, which runs + the build scripts of the repository the manifest names. + +Every other lockfile tool runs with no repository code: aube and Bun (with +scripts off), Cargo, Go, Terraform, Composer (with `--no-scripts +--no-plugins`), nix, `mise lock`, APM and gh-actions-lock. So do lookups, which +run for every repository whether or not it has a lockfile. + +**Under what opt-in.** There is no separate switch. One of these tools runs +when a repository commits its lockfile and an update changes the manifest +beside it, or when the repository turns on `lockfiles.refresh`. The +operator's opt-in is choosing which repositories the Count runs for: the +repositories a CLI run names, or the installations and repositories the server +allows (`server.allowedInstallations`, `server.allowedRepositories`). With +`--config-dir`, an operator policy that replaces a repository's config can +also leave those managers out. + +**What the code reaches.** The tool process starts from the allowlisted +environment (`patchula_mise::sandbox_env`) plus the tool's own settings and +the operator registry credentials of entries with `tools = true` that match +the repository's sources. None of the tools above gets a GitHub token: git's +credential header goes only to the Count's own checkout, and nix and +gh-actions-lock get theirs only in their own runs. That limits what a +well-behaved tool sees and echoes. It does not limit evaluated code, because +the tools run unsandboxed as the Count's user. That code can read whatever the +user can: the operator settings and the secrets they name, the App private +key, the Count's own environment through `/proc`, every tool-cache partition, +and other runs on the same host. An operator who runs the Count for a +repository that uses one of these tools trusts that repository's writers with +all of it. + +**What still holds.** The rest of this page applies to every repository, +those included: + +- Every tool not listed above, and every lookup, runs no repository code, and + the guards that keep it so still matter: Yarn's `.yarnrc.yml` loses + `yarnPath` and plugins, mise plugin backends stay off, install and lifecycle + scripts are skipped, Composer and Poetry plugins are off, and git hooks and + credential helpers are disabled. They hold the exception to the list above. + Without one of them, any repository could run code through an ecosystem + that otherwise evaluates none, including a repository that commits none of + the lockfiles above or that the operator's policy keeps away from those + tools. +- Credentials given to tools stay scoped by the rules above, and shared + results stay honest, so honest repositories never see each other's private + data. These keep data apart between repositories that do not attack the + Count; they are not a boundary against code running in the exception. +- Argument hygiene applies as everywhere else. + ## Consequences - **Follow, don't refuse.** If the Count can reproduce what a repository declares, he does it. He refuses only what would run code chosen by the - repository, or what he cannot reproduce faithfully. + repository outside the lockfile exception, or what he cannot reproduce + faithfully. - **Scope credentials, don't strip them.** Give each lookup the narrowest credential its repository is entitled to. Don't withhold that credential because a repository-chosen host could see it. -- **Never run code a repository chose.** Plugin backends, lifecycle scripts, - hooks and the like stay off for every repository. +- **Never run code a repository chose** outside the lockfile exception. + Plugin backends, lifecycle scripts, hooks and the like stay off for every + repository, and a new lockfile tool joins the exception only when it cannot + regenerate its lockfile without evaluating repository code. - **Keep shared results honest.** A shared cache key includes everything that changes the answer: the options, the source, and the reach of the credential that fetched it. From 69f0355abacb59ab984716ff6eab31361e0f8964 Mon Sep 17 00:00:00 2001 From: Sweepy Date: Mon, 16 Nov 2026 02:11:15 +0000 Subject: [PATCH 4/4] docs: leave the threat model and lockfile guide to the no-execution change Running repository code is not something the threat model makes an exception for; the tools that would do it are changed instead, in a separate PR. --- docs/src/content/docs/guide/lockfiles.md | 44 ++++------ .../content/docs/internals/threat-model.md | 86 ++----------------- 2 files changed, 26 insertions(+), 104 deletions(-) diff --git a/docs/src/content/docs/guide/lockfiles.md b/docs/src/content/docs/guide/lockfiles.md index 905aee7d..c6ca43e9 100644 --- a/docs/src/content/docs/guide/lockfiles.md +++ b/docs/src/content/docs/guide/lockfiles.md @@ -325,23 +325,16 @@ lockfile needs none of them. Output is kept only when something fails, at most 4 KiB of each stream. -:::danger[Some lockfile tools run repository and package code] -A few tools cannot regenerate their lockfile without running code from the -repository or the dependencies it names: Bundler evaluates the Gemfile and -gemspecs, dotnet evaluates MSBuild projects and runs restore's targets, uv and -Poetry build local projects and source distributions that lack static -metadata, and Yarn Berry and npm can prepare git dependencies by running their -build scripts. This is the one exception to the rule that a repository never -runs code on the Count's machine (see the -[threat model](/internals/threat-model/#the-lockfile-exception)). Every other -lockfile tool runs none. - -These tools run unsandboxed, as the Count's own user, so that code can read -anything the Count can: its environment and settings secrets, the GitHub App -credentials, and what other runs on the same host hold at the time. There is -no setting that turns them on: they run whenever a repository commits one of -those lockfiles. Run the Count only for repositories you trust that far, or -keep the others away from those managers with a `--config-dir` policy. +:::danger[Lockfile tools run repository and package code] +Regenerating a lockfile runs code from the repository and from its +dependencies: Bundler evaluates the Gemfile and gemspecs, dotnet evaluates +MSBuild projects and targets, uv and Poetry build source distributions to read +their metadata, and Yarn and npm prepare git dependencies by running their +build scripts. The tools run unsandboxed, as the Count's own user, so that code +can read anything the Count can: its environment and settings secrets, the +GitHub App credentials, and what other runs on the same host hold at the time. +Run the Count only for repositories you trust that far, or turn lockfile +updates off for the others. ::: ## Tool caches @@ -381,13 +374,13 @@ partition with Go's default environment, so repositories with internal modules keep working. Partitions keep honest repositories' private packages apart; they are -not an isolation boundary. The tools that run repository code do so +not an isolation boundary. Lockfile tools run repository code unsandboxed — Bundler evaluating the Gemfile, uv or Poetry building -sdists, MSBuild evaluating project files — so code from any repository -that uses one of them can read every partition on the host, `public`, -another installation's and another credential set's alike. That follows -from the lockfile exception above: running the Count for such a -repository trusts its writers with everything the Count can read. +sdists, MSBuild evaluating project files — so code from any installed +repository can read every partition on the host, `public`, another +installation's and another credential set's alike. That is within the +trust model above: every installation is trusted, and lockfile tools run +repository code anyway. A partition a run uses is held shared, so eviction never removes one in use, and tools whose caches are not documented for concurrent use — aube, Bun, @@ -402,9 +395,8 @@ Lockfile tools get a [registry entry's](/guide/sources/#private-registries) credentials only when the entry sets `tools = true`; APM, Nix, `mise lock` and the Gradle wrapper read no private registries and get none. In the server, `allowedInstallations` decides which installations' tools are given them, -and the CLI gives them to every repository it runs on. As some lockfile tools run -repository code (see [Isolation](#isolation)) and any repository can commit a -lockfile for one, any repository the Count processes can read a +and the CLI gives them to every repository it runs on. As lockfile tools run +repository and package code, any repository the Count processes can read a credential it holds, so neither setting is a boundary. Each tool gets the credentials in the form it reads, only for its own run: diff --git a/docs/src/content/docs/internals/threat-model.md b/docs/src/content/docs/internals/threat-model.md index 299c5f59..e94b21d7 100644 --- a/docs/src/content/docs/internals/threat-model.md +++ b/docs/src/content/docs/internals/threat-model.md @@ -34,12 +34,11 @@ It may: It may not: -- run code on the Count's machine, except through the lockfile tools listed - under [the lockfile exception](#the-lockfile-exception). That covers plugin - backends (asdf, vfox), lifecycle scripts, hooks, build logic, credential - helpers and anything else that executes something the repository chose. - The Count runs as one user, with his credentials, his cache and, under an - App, the private key, so code running there reaches all of them. +- run code on the Count's machine. That covers plugin backends (asdf, vfox), + lifecycle scripts, hooks, build logic, credential helpers and anything else + that executes something the repository chose. The Count runs as one user, + with his credentials, his cache and, under an App, the private key, so code + running there reaches all of them. - obtain a credential wider than its own reach: the installation token, the App key, another repository's token, an operator registry credential meant for other repositories, or the machine's own credentials. Cloud @@ -49,85 +48,16 @@ It may not: shared between repositories, such as listings and catalogs, are shared only when they came from public data or from a credential the reader may hold. -## The lockfile exception - -Some lockfiles can only be regenerated by a tool that evaluates repository -code. The Count runs those tools anyway, because a lockfile written any other -way would not be the one the ecosystem's tool writes. This is the only place a -repository runs code on the Count's machine. - -**Which tools.** Each of these runs code the repository wrote or chose as part -of resolving, with no flag that turns it off: - -- Bundler (`bundle lock`) evaluates the `Gemfile` and any gemspecs it loads as - Ruby. -- dotnet (`dotnet restore`) evaluates MSBuild project, props and targets - files, and runs the targets restore reaches, which can run commands. -- uv (`uv lock`) and Poetry (`poetry lock`) build local projects and source - distributions that lack static metadata through their PEP 517 build - backends, which run `setup.py` and other build code. -- Yarn Berry and npm can prepare a git dependency by packing it, which runs - the build scripts of the repository the manifest names. - -Every other lockfile tool runs with no repository code: aube and Bun (with -scripts off), Cargo, Go, Terraform, Composer (with `--no-scripts ---no-plugins`), nix, `mise lock`, APM and gh-actions-lock. So do lookups, which -run for every repository whether or not it has a lockfile. - -**Under what opt-in.** There is no separate switch. One of these tools runs -when a repository commits its lockfile and an update changes the manifest -beside it, or when the repository turns on `lockfiles.refresh`. The -operator's opt-in is choosing which repositories the Count runs for: the -repositories a CLI run names, or the installations and repositories the server -allows (`server.allowedInstallations`, `server.allowedRepositories`). With -`--config-dir`, an operator policy that replaces a repository's config can -also leave those managers out. - -**What the code reaches.** The tool process starts from the allowlisted -environment (`patchula_mise::sandbox_env`) plus the tool's own settings and -the operator registry credentials of entries with `tools = true` that match -the repository's sources. None of the tools above gets a GitHub token: git's -credential header goes only to the Count's own checkout, and nix and -gh-actions-lock get theirs only in their own runs. That limits what a -well-behaved tool sees and echoes. It does not limit evaluated code, because -the tools run unsandboxed as the Count's user. That code can read whatever the -user can: the operator settings and the secrets they name, the App private -key, the Count's own environment through `/proc`, every tool-cache partition, -and other runs on the same host. An operator who runs the Count for a -repository that uses one of these tools trusts that repository's writers with -all of it. - -**What still holds.** The rest of this page applies to every repository, -those included: - -- Every tool not listed above, and every lookup, runs no repository code, and - the guards that keep it so still matter: Yarn's `.yarnrc.yml` loses - `yarnPath` and plugins, mise plugin backends stay off, install and lifecycle - scripts are skipped, Composer and Poetry plugins are off, and git hooks and - credential helpers are disabled. They hold the exception to the list above. - Without one of them, any repository could run code through an ecosystem - that otherwise evaluates none, including a repository that commits none of - the lockfiles above or that the operator's policy keeps away from those - tools. -- Credentials given to tools stay scoped by the rules above, and shared - results stay honest, so honest repositories never see each other's private - data. These keep data apart between repositories that do not attack the - Count; they are not a boundary against code running in the exception. -- Argument hygiene applies as everywhere else. - ## Consequences - **Follow, don't refuse.** If the Count can reproduce what a repository declares, he does it. He refuses only what would run code chosen by the - repository outside the lockfile exception, or what he cannot reproduce - faithfully. + repository, or what he cannot reproduce faithfully. - **Scope credentials, don't strip them.** Give each lookup the narrowest credential its repository is entitled to. Don't withhold that credential because a repository-chosen host could see it. -- **Never run code a repository chose** outside the lockfile exception. - Plugin backends, lifecycle scripts, hooks and the like stay off for every - repository, and a new lockfile tool joins the exception only when it cannot - regenerate its lockfile without evaluating repository code. +- **Never run code a repository chose.** Plugin backends, lifecycle scripts, + hooks and the like stay off for every repository. - **Keep shared results honest.** A shared cache key includes everything that changes the answer: the options, the source, and the reach of the credential that fetched it.