feat(build): lock tool dependencies and keep package code off the network

オープン
#63 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
docker, go, node.js, python

調査の方向性

Start with pkg/agentkit/config/tool.go, validate.go, pkg/agentkit2llb/agent/convert.go, and pkg/build/instructions.go; trace how package installs and build-context files are handled. Run the Go validation and build-step tests, then go test ./... and make lint. Done means lock files are validated and affect the build cache, installs follow the network and wheel restrictions, caches stay out of the image, and the docs and end-to-end checks cover the specified behavior.

索引モデルが issue の本文から書いたものです。

説明

area/build blocked enhancement security

Depends on #54. #54 installs each stdio tool's package into the image at build time, pinned to an exact version. This issue makes those installs fully locked, safer and faster to rebuild.

Problem

After #54, a tool's own version is pinned, but four gaps remain:

  1. Dependencies are not pinned. The tool's dependencies are picked fresh every time the install step runs. Two builds of the same file a week apart can contain different dependency code. A bad or compromised dependency release slips in without anyone noticing.
  2. Downloads are not checked. Nothing confirms that the downloaded files are the ones you expected. A lock file fixes both of these: it lists the exact version of every dependency plus a hash, a fingerprint of each file. The installer can then refuse anything that doesn't match.
  3. Package code runs with network access. npm packages can run scripts while installing, and Python packages without a prebuilt version (a wheel) run build code. With the network on, that code can download and run more code.
  4. Every rebuild downloads everything again. There's no download cache between builds.

dalec handles this by downloading dependencies in one step with network access, then building in a separate step with the network off (see dalec's generator_pip.go and the Go and Cargo generators). It also keeps download caches between builds (see dalec's caches docs).

What

1. Optional lock file per tool

The lock file is read from the build context:

tools:
  - name: fetch
    package:
      pypi: mcp-server-fetch==<version>
      lockFile: ./tools/fetch/requirements.txt
    command: ["mcp-server-fetch"]

  - name: everything
    package:
      npm: "@modelcontextprotocol/server-everything@<version>"
      lockFile: ./tools/everything/package-lock.json   # package.json must sit next to it
    command: ["mcp-server-everything"]
  • PyPI: a requirements file with hashes, made with uv pip compile --generate-hashes. The install refuses any file whose hash doesn't match.
  • npm: a package-lock.json, with its package.json in the same folder. It's installed with npm ci, which checks every file against the lock file.
  • Must match. The build fails if the lock file doesn't contain the pinned package at the pinned version.
  • Docs. Show the exact commands for creating both kinds of lock file.
2. Package code never runs while the network is on

This applies to every packaged tool, with or without a lock file.

  • npm:
    • Download and check the files with network on and install scripts turned off: npm ci --ignore-scripts.
    • Then run the install scripts in a second step with the network off: npm rebuild.
    • A script that needs the network will fail, and the docs should say so.
  • PyPI:
    • Allow only prebuilt wheels (uv's --no-build). Installing a wheel just unpacks files and runs no package code.
    • If a package has no wheel, fail with a clear message that names the package.
3. Download cache between builds
  • Keep uv's and npm's download caches between builds.
  • After a version bump, only what changed gets downloaded.
  • The cache must never end up in the image.
Out of scope
  • Private package indexes and registries that need credentials. That needs BuildKit build secrets and is still a follow-up.
  • A way to allow Python packages that have no wheel. Add it later if people need it.
  • Plain binary downloads. That's #43.

Why

  • Same file, same tool code. Every build installs the same dependency code, down to the file fingerprint.
  • Tampering is caught. The build fails if a download doesn't match.
  • Package scripts can't fetch more code during the build.
  • Faster rebuilds.

How

Where things are
File What it does
pkg/agentkit/config/tool.go ToolPackage from #54. Add LockFile here.
pkg/agentkit/config/validate.go Tool checks, including the package rules from #54.
pkg/agentkit2llb/agent/convert.go The install steps added by #54.
pkg/build/instructions.go contextFileReader.ReadFile reads files from the build context. Instruction files already use it. Read lock files the same way.
Steps
  1. Schema and validation.

    • Add lockFile under package. The path is relative to the build context, and paths that escape it, such as ../, are rejected. Check how instruction file paths are handled and do the same.
    • When building, read the file. For npm, also read the package.json next to it.
    • Fail with a clear message if:
      • the file is missing;
      • the PyPI lock has no name==version line for the pinned package (compare names the way PyPI does: case-insensitive, with -, _ and . treated the same);
      • the npm package.json doesn't list the pinned package at the pinned version.
    • Pass the file contents into the install step by writing them into an empty filesystem (llb.Scratch().File(llb.Mkfile(...))). That way the build cache notices when a lock file changes.
  2. PyPI install with a lock file. uv tool install can't check hashes, so instead:

    • create a virtual environment with uv venv /opt/agentkit-tools/uv/<tool>;
    • install with uv pip install --python /opt/agentkit-tools/uv/<tool>/bin/python --require-hashes --no-build -r <lock>;
    • link the program named in command[0] from that environment's bin into /opt/agentkit-tools/bin. Fail if it isn't there.

    Without a lock file, keep #54's uv tool install, but add --no-build.

  3. npm install, two steps. Use one folder per tool, for example /opt/agentkit-tools/npm/<tool>.

    • Step A, network on: npm ci --ignore-scripts.
    • Step B, network off (llb.Network(llb.NetModeNone)): npm rebuild.
    • Link the program into /opt/agentkit-tools/bin.

    Without a lock file, use npm install --ignore-scripts <spec> in step A, then the same step B.

  4. Download cache. During the install steps, mount uv's cache directory and npm's cache directory as shared persistent caches:

    • llb.AsPersistentCacheDir("agentkit-uv", llb.CacheMountShared), pointed at with UV_CACHE_DIR;
    • llb.AsPersistentCacheDir("agentkit-npm", llb.CacheMountShared), pointed at with npm_config_cache.

    These mounts never become part of the image.

  5. Check the flags against the uv and npm versions in the runtime images (Wolfi uv and npm-12, see runtimes/*/Dockerfile).

Tests
  • Go, validation:
    • a missing lock file;
    • the pinned version not in the lock;
    • an npm package.json that doesn't match;
    • a path that escapes the build context.
  • Go, build steps:
    • PyPI steps use --require-hashes and --no-build;
    • npm uses two steps, the first with --ignore-scripts and the second with network off;
    • both cache mounts are present;
    • the image contents don't include the caches;
    • a changed lock file changes the step.
  • End to end:
    • Add fixtures with real lock files, for example under test/tool-locks/.
    • The agent builds and starts with docker run --network none.
    • Editing one hash in a lock file makes the build fail.
    • A second build after bumping one version reuses cached downloads.
  • If #61 has landed, add the new install steps to its checks that builds come out the same every time.

Run:

go test ./...
make lint
Docs
  • docs/agentkitfile.md: add a "Locking tool dependencies" section covering:
    • how to create each kind of lock file;
    • the "package code never runs with network on" rule;
    • the wheels-only rule for Python;
    • what to do when a package fails because of either rule.

Done when

  • Tools with a lock file install exactly the locked files, and a tampered hash fails the build.
  • npm install scripts run only with the network off, and Python installs use wheels only.
  • Rebuilds after a version bump reuse cached downloads, and no cache ends up in the image.
  • Agents with locked tools start with --network none.
  • The docs explain how to create lock files and what the new rules mean.
主要言語
Python
スター
7
フォーク
5
平均マージ
3時間 39分
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

orka-agents/agentkit のほかの issue

orka-agents/agentkit の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。