Repository navigation
refactor(containers): one builder for the docker run hardening and resource flags - #249
Conversation
Pin the exact argv that repos/container.py and metrics/example_runner.py build today, flag order included, before a shared container policy builder touches either. Test-only: these pass on the unchanged code. Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
…source flags repos/container.py and metrics/example_runner.py each spelled their own docker run flags. dokimi/container_policy.py now owns the spelling; each call site splices the groups in its current order, so both argvs are unchanged (pinned by test_container_argv_characterization.py). harnesses/docker_solver.py is not touched here: its hardening and its adoption of the builder come in their own changes. Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
antonwolfy
left a comment
There was a problem hiding this comment.
LGTM. The refactor keeps the argv byte-identical, and the characterization tests pin both call sites. One nit inline. I agree the change has no user-visible effect, so skip-changelog fits; the Fragment for package changes step stays red until a maintainer adds the label.
What I ran, on Linux at 0100bf1:
make ci-local: 25 passed, 3 failed, 7 skipped. 8,991 tests passed. Changed-line coverage 100%.Fragment for package changesfails for the missing label, as in GitHub CI. The other two failures are the gitleaks download (the proxy returned 504) and the scan that needs it, not this PR.- Base vs head comparison of the argv with the transport mocked: 324
DockerRunner.argvcombinations (networks, names, users, workdirs, mounts, env) and 900 example-runner combinations (languages, cpus, memory, timeouts, images). The output is identical. - A mutation run: 53 mutants of the new code, 34 killed by the characterization file. The 19 survivors are equivalent mutants or the builder-level gap in the inline nit.
Checked, no issues
- Layer:
container_policy.pyimports onlydataclasses, so the foundation layer intest_import_architecture.pyanddocs/architecture.mdis right. - Tests: the characterization file is offline, writes nothing outside the temp dir, and leaves the tree clean.
- Scope claims:
harnesses/docker_solver.pyis untouched, and the otherdocker runbuilders the description names exist where it says.
Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
antonwolfy
left a comment
There was a problem hiding this comment.
LGTM. I pushed a commit per nit, up to 548d8c0, which fix the nit from my review:
548d8c0:dokimi/tests/test_container_policy.py:1: new test file asserts the default policy yields no flags and each field alone yields exactly its flag, includingcpus=0.0andmemory_mb=0.
make ci-local at 548d8c0: 25 passed, 3 failed, 7 skipped.
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #249 +/- ##
==========================================
+ Coverage 92.80% 92.83% +0.02%
==========================================
Files 261 262 +1
Lines 32986 33016 +30
Branches 5508 5510 +2
==========================================
+ Hits 30614 30649 +35
+ Misses 1574 1571 -3
+ Partials 798 796 -2
🚀 New features to boost your workflow:
|
Summary
#229 P2-1: the
docker runflags of the two container call sites are built by one policy module. Internal refactor; the argv does not change.Two commits, in this order:
test(containers): characterize ...: the exact argv of both call sites, written against the code before the builder existed.refactor(containers): one builder ...: both call sites splice the builder's groups in the order their argv has always had.Not in this PR:
harnesses/docker_solver.pyis not touched. A sibling PR adds its hardening flags (--cap-drop ALL,no-new-privileges,--pids-limit); adopting this builder there comes later.metrics/example_runner.pyhas no--init,--cap-droporno-new-privilegestoday. Adding them changes its argv, so it is a separate follow-up. The characterization test pins the absence and says so.docker run/podmanargv builders found by grep, candidates for later adoption:harnesses/docker_solver.py(run -dnear line 356, thedockerhelper near 876) andharnesses/container_agent.py(network create,create,exec).Refs #229 (P2-1).
Evidence
b76f1bc9, parent of the refactor) pass: 12 passed. They are characterization tests, so they pass by design; they pin the argv that already exists.After: the same file on the refactored code: 12 passed.
--cap-drop all; network and resource order swapped;--read-onlydropped;mbinstead ofm). Each one fails the characterization file (2 to 4 failures per break); the restored copy passes.pytest: 8989 passed, 4 skipped, exit 0.make ci-local CI_LOCAL_ARGS='--offline --jobs static,typecheck': ruff, schema, registry drift, growth report, guidance self-scan, zizmor, bandit, mypy (250 files), deptry, schema_compat: all pass.Fragment for package changesfails, see Merge Danger.Merge Danger
Door: two-way. The change is a refactor that the tests pin to the current argv; reverting restores the same argv.
Numbers: none change. No scores, no statistics, no report output.
Changelog: no fragment. This change has no user-visible effect, so the repo's rule (
changelog.d/README.md) asks a maintainer for theskip-changeloglabel. The CI stepFragment for package changesfails until that label is added.Blast radius: container runs. Every
repo run/repo tasks checkcontainer (DockerRunner.argv) and every example run with--backend docker. The argv is byte-identical, which the characterization tests check for each mode (networknone/bridge/host, the mounts, the user, the env, the resource flags). A regression in the builder would change how every repo container starts, so review the flag order incontainer_policy.pyand the splices at the two call sites first.New module:
dokimi/container_policy.pyis in the foundation layer;tests/test_import_architecture.pylists it anddocs/architecture.mdhas the row.🤖 Generated with Claude Code