feat(build): lock tool dependencies and keep package code off the network
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- build-system, tooling
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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:
- 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.
- 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.
- 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.
- 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 itspackage.jsonin the same folder. It's installed withnpm 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.
- Download and check the files with network on and install scripts turned off:
- 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.
- Allow only prebuilt wheels (uv's
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
-
Schema and validation.
- Add
lockFileunderpackage. 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.jsonnext to it. - Fail with a clear message if:
- the file is missing;
- the PyPI lock has no
name==versionline for the pinned package (compare names the way PyPI does: case-insensitive, with-,_and.treated the same); - the npm
package.jsondoesn'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.
- Add
-
PyPI install with a lock file.
uv tool installcan'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'sbininto/opt/agentkit-tools/bin. Fail if it isn't there.
Without a lock file, keep #54's
uv tool install, but add--no-build. - create a virtual environment with
-
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. - Step A, network on:
-
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 withUV_CACHE_DIR;llb.AsPersistentCacheDir("agentkit-npm", llb.CacheMountShared), pointed at withnpm_config_cache.
These mounts never become part of the image.
-
Check the flags against the uv and npm versions in the runtime images (Wolfi
uvandnpm-12, seeruntimes/*/Dockerfile).
Tests
- Go, validation:
- a missing lock file;
- the pinned version not in the lock;
- an npm
package.jsonthat doesn't match; - a path that escapes the build context.
- Go, build steps:
- PyPI steps use
--require-hashesand--no-build; - npm uses two steps, the first with
--ignore-scriptsand 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.
- PyPI steps use
- 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.
- Add fixtures with real lock files, for example under
- 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.
- Lingua principale
- Python
- Stelle
- 7
- Fork
- 5
- Merge medio
- 3h 39m
- PR unite (30g)
- 1
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di orka-agents/agentkit
-
fix(pydantic-ai): CI fails with newest pydantic-ai (unexpected 'history' argument)Forse già presa @gambtho l’ha presa 30 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
orka-agents/agentkit#77 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
orka-agents/agentkit#76 · 3 commenti ·
-
area/build area/orka area/runtime blocked enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
orka-agents/agentkit#69 ·
-
area/build area/orka area/runtime enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 68/100
orka-agents/agentkit#68 ·
-
area/build enhancement testing
Difficoltà 5/5 Più di una settimana Idoneità per principianti 42/100
orka-agents/agentkit#65 ·
Tutte le issue di orka-agents/agentkit
Issue simili
-
bot-triaged module: correctness (silent) module: fft triage review
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Remove Python pin in recipeAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
conda-forge/zarpaint-feedstock#8 · 1 commento · 1 reazione ·
-
plot_prediction colorbar shows a 0-1 range instead of the data rangeForse già presa @nikhil3495 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
mllam/neural-lam#902 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
didi/helixharness#28 ·
I maintainer di solito rispondono entro 1 giorno
-
【文档错误】创建镜像空间步骤中的截图标注与文字描述不一致Apertaenhancement
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
DaoCloud/DaoCloud-docs#7839 ·
I maintainer di solito rispondono entro 1 giorno