Repository navigation
Add opt-in read-only rootfs for Docker workloads - #7128
Conversation
Standalone workloads always ran with a writable root filesystem, while the operator already sets readOnlyRootFilesystem on Kubernetes. Add a RunConfig field, a thv run --read-only-rootfs flag and an API field that set HostConfig.ReadonlyRootfs on the MCP container. The setting is part of compareHostConfig so toggling it recreates the container. Off by default to avoid breaking servers that write to their root filesystem. Fixes stacklok#6729
|
@aponcedeleonch this is the first PR for #6729. Could you approve the workflow runs? I'm on Windows without Docker, so the e2e test hasn't run locally yet. tmpfs scratch mounts will follow in a separate PR as discussed. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7128 +/- ##
==========================================
+ Coverage 81.20% 81.24% +0.04%
==========================================
Files 877 877
Lines 89885 89907 +22
==========================================
+ Hits 72988 73049 +61
+ Misses 16892 16853 -39
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Podman's compat API adds its own executable, uncapped tmpfs on /tmp, /var/tmp and /run whenever ReadonlyRootfs is set, while Docker adds none, so the same flag behaved differently per runtime. Set those tmpfs mounts explicitly with rw,nosuid,nodev,noexec,size=64m and skip any path a volume already targets, since Docker rejects duplicate mount points. Also cover the field in the API threading and round-trip tests, the upgrade preservation test and runtime.Setup.
aponcedeleonch
left a comment
There was a problem hiding this comment.
Thanks for taking both on. The tmpfs change makes the flag behave the same on Docker and Podman, and the extra tests cover the wiring end to end. LGTM.
|
Small one: the Swagger docs check is failing because the |
|
Thanks for approving! 2954c75 only regenerates swagger and the SDK for the updated
Could you re-run the failed jobs? |
Summary
Standalone Docker/Podman workloads always run with a writable root filesystem, while the operator already sets
readOnlyRootFilesystem: trueon Kubernetes. A compromised or misbehaving MCP server can therefore modify its own image layer locally. This adds an opt-in way to lock the root filesystem down, as discussed in #6729.ReadOnlyRootfstoRunConfig(read_only_rootfs), with athv run --read-only-rootfsflag and aread_only_rootfsfield on the workload create/update API.runtime.SetupandDeployWorkloadOptionsintoPermissionConfig, and setHostConfig.ReadonlyRootfswhen creating the MCP container.ReadonlyRootfsincompareHostConfigso toggling the setting recreates an existing container instead of reusing it./tmp,/var/tmpand/runarw,nosuid,nodev,noexec,size=64mtmpfs when the rootfs is read-only, skipping paths a mount already targets. Podman's compat API otherwise adds its own executable, uncapped tmpfs there while Docker adds none, so the flag would behave differently per runtime.thv upgrade.docs/arch/05-runconfig-and-permissions.mdand regenerate CLI/API docs.Fixes #6729
Type of change
Test plan
task test)task test-e2e)task lint-fix)I'm on Windows, so I ran
go testand golangci-lint v2.15.0 against the touched packages rather than the fulltasktargets. The only failures (squid/envoy file modes,TestWriteInPlace, a fewpkg/api/v1router tests) also fail on a cleanmainon Windows. Lint found nothing in the changed files.Unit tests:
compareHostConfigis now table-driven with a read-only-rootfs mismatch case.createMcpContainerasserts thatReadonlyRootfsand the scratch tmpfs are wired, with a table test forreadOnlyRootfsTmpfs. New tests check that the option reachesDeployWorkloadandruntime.Setupand defaults to off. API threading, the round-trip test and thethv upgradepreservation test all cover the field. The e2e test (test/e2e/read_only_rootfs_test.go) runsfetchwith and without--read-only-rootfsand checksdocker inspectforReadonlyRootfsand the tmpfs mounts. I developed on Windows without Docker, so the e2e test has not run locally; I'm relying on CI for it.Does this introduce a user-facing change?
Yes. Before: standalone workloads always had a writable root filesystem. After:
thv run --read-only-rootfs(or"read_only_rootfs": truein the API/RunConfig) starts the MCP server with a read-only root filesystem, plus a 64 MiB noexec tmpfs on/tmp,/var/tmpand/runthat behaves the same on Docker and Podman. The default is unchanged (writable), so existing workloads behave the same.Special notes for reviewers
thv runflag, not a permission profile field, so notoolhive-corechange is needed.compareHostConfigdoesn't compareTmpfs, because the set follows fromReadonlyRootfsand the mounts, which are already compared.