302 Commits
Author SHA1 Message Date
Tonis Tiigi 2efe98b13a executor: make resolv.conf generation flags atomic
GetResolvConf read and wrote the package-level notFirstRun and
lastNotEmpty flags inside its flightcontrol callback. flightcontrol
only serializes calls with the same key, so calls for different roots,
or for resolv.conf and resolv-host.conf at once, raced on them. Make
both flags atomic.Bool; the sequential behavior is unchanged.

Add a test that generates resolv.conf for several roots concurrently;
it reports the race under -race without the fix.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-10-25 20:08:26 -07:00
Tonis Tiigi 50452fdb63 runcexecutor: stop tty resize loop before closing pty
The resize goroutine calls ptm.Resize (os.File.Fd) and only exits once
runcProcess.Shutdown() cancels its context, which ran after the cleanup
had already closed ptm. A resize racing with process exit could read a
closed or reused fd, so TIOCSWINSZ could hit an unrelated descriptor.
Stop and join the resize loop before the pty is closed.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-10-24 21:50:50 -07:00
Joao Otavio ManieriandClaude Opus 5.5 eac3279c43 runcexecutor: share keyring in NoProcessSandbox
In NoProcessSandbox mode the build container runs in the PID namespace
of buildkitd, so a process that a step leaves running in the background
is not killed when the step ends. runc still creates a new session
keyring for every container, and each leftover process keeps that
keyring alive. Each of them takes one key from the per-user quota of the
daemon user (kernel.keys.maxkeys, 200 by default for non-root). Once the
quota is used up, every new container fails with:

    unable to join session keyring: unable to create session key: disk
    quota exceeded

Restarting buildkitd ends the leftover processes and frees the keys, so
long-running rootless daemons hit this again after some days.

Run runc with --no-new-keyring in this mode, so the build containers
use the session keyring of buildkitd. They already share the PID
namespace and procfs with the daemon, and runc treats the per-container
keyring as best-effort isolation, so this removes nothing the mode
provides. ProcessSandbox mode is unchanged.

Fixes #7310
Refs #6247

Signed-off-by: Joao Otavio Manieri <69759037+JoaoManierii@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 19:54:31 +00:00
Tonis Tiigi 3f864e412f executor: reject proxy CA bundle devices
Read proxy CA bundles through RegularInRoot before accessing their contents.
Keep temporary writes and replacement confined to a retained root handle.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 914ed29f24515cf7dbfeff1c169538123945437b)
2026-09-30 15:12:28 +02:00
Tonis Tiigi 2c60ca96c0 executor: fail closed on proxy CA cleanup
Propagate proxy CA cleanup failures from both Linux executors so builds
cannot succeed when the temporary certificate cannot be removed.

Restore certificate bundles byte-for-byte while preserving build-time changes
and report process and cleanup failures together.

Based on: moby/buildkit#7043

Co-authored-by: bbartels <23058572+bbartels@users.noreply.github.com>
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 62a1b69ee38bc68b23e7c096bbb7372ed13af6e1)
2026-09-30 15:12:26 +02:00
Tonis Tiigi 71dc7cfbd6 errors: report build-facing paths on read failure
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 12bf293e5feee7393e971a1d22a191dff7f6e7f8)
(cherry picked from commit 5a01794b79c7af91a961b1236b0e0661975161d7)
2026-09-30 15:12:24 +02:00
Tonis Tiigi 1accd8ea20 openfile: reject special files in daemon reads
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 164c90a88ef0203f7160d212e54fdbdc97f6f355)
(cherry picked from commit 62c82f71f2e9f10ea3c014f2e21818f76b8649b8)
2026-09-30 15:12:24 +02:00
CrazyMax 01e63e2c88 executor: avoid blocking on proxy CA bundle cleanup
Open the proxy CA bundle with O_NONBLOCK before checking that it
is a regular file. This prevents cleanup from hanging when a build
replaces the bundle path with a FIFO that has no writer.

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
(cherry picked from commit ed6a9a02de11435e43a42efa6bbde835c08ebe3d)
(cherry picked from commit 567f0e193d2aefa47de3cb430b71946e8f68f40a)
2026-09-30 15:12:21 +02:00
CrazyMax 1bf93e25a0 executor: keep proxy CA cleanup inside the rootfs
Store the resolved certificate bundle target relative to the rootfs
and resolve it again during cleanup. This prevents cleanup from
following a container-retargeted symlink through the stale worker path.

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
(cherry picked from commit 573ec15277605de470a7c969b182b7ef4c495e7d)
(cherry picked from commit 51eb362664370570cd8f569ea76cd10ebf22fa0f)
2026-09-30 15:12:21 +02:00
CrazyMax 1e507ff6ce Merge pull request #7074 from tonistiigi/proxy-env-update
proxy: support daemon upstream proxies
2026-08-26 10:38:39 +02:00
Tonis Tiigi 71bb8734c8 proxy: support daemon upstream proxies
Route proxy-network traffic through HTTP_PROXY and HTTPS_PROXY from the
buildkitd environment. Propagate ALL_PROXY to gateway execs and document
upstream proxy behavior.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-08-25 23:42:29 -07:00
Tonis Tiigi 6ed70f8651 executor: restore mount points removed for rootless
The rootless spec conversion removes the /sys mount, so the runtime never
creates its mount point in the rootfs. A rootful build gets that empty
directory, which meant the same LLB left different mount points behind
depending on whether the worker was rootless.

Recreate the mount points of the removed mounts after the container has
exited, rather than cleaning them up from the rootful result, which would
change existing output and need a compatibility version bump. Creating
them up front would instead turn a mount point that the image does not
ship into a directory the build can write to. Nested destinations are
skipped: the runtime creates those inside the parent mount, where they
never reach the rootfs.

Fixes #6686

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-08-13 16:04:16 +03:00
Leo Li 069b2d673b executor: clean finalized runc mount stubs
BuildKit records mount-stub cleanup before rootless conversion finishes changing the mount list, which can leave rootful and rootless builds with different empty directories.

This change registers cleanup after rootless conversion, when the mount list is final, and uses that list for cleanup.

Signed-off-by: Leo Li <cheerleaderleo@outlook.com>
2026-08-12 08:58:37 +08:00
Matthieu MOREL 5a96f64d01 Refactor error handling to use errors.New for consistency
- Updated multiple instances across various files to replace errors.Errorf with errors.New for error message creation.
- This change enhances consistency in error handling throughout the codebase.

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2026-08-07 10:13:54 +02:00
Guthrie McAfee Armstrong fbf541b856 network: centralize proxy environment entries
Signed-off-by: Guthrie McAfee Armstrong <guthrie.armstrong@coalitioninc.com>
2026-07-30 09:52:30 -04:00
Guthrie McAfee Armstrong e3d3d7f6f3 executor: propagate proxy env to gateway execs
Signed-off-by: Guthrie McAfee Armstrong <git@gmarmstrong.dev>
2026-07-28 17:02:25 -04:00
Tonis Tiigi 96879c682d Update critical containerd and Docker deps
Bump containerd/containerd/api, containerd/containerd/v2, and
docker/cli to current critical direct versions. Regenerate vendor and
accept required transitive/go directive updates from containerd.

Adjust resource pointer helpers for Go 1.26 gopls modernize lint.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-07-21 17:29:37 -07:00
CrazyMax 6286b9f7ff Merge pull request #6962 from tonistiigi/forward-v0.31.2-patches
Forward port v0.31.2 patches
2026-07-17 10:28:27 +02:00
Tonis Tiigi bd8f652e91 executor/oci: avoid delete access for WCOW pin
Open the resolved mount source with GENERIC_READ instead of DELETE.
The nonzero desired access keeps the share-mode pin effective, while
omitting FILE_SHARE_DELETE still prevents the source from being renamed
or deleted before HCS realizes the mount.

Avoid requiring delete permission on legitimate mount sources, which
caused access denied failures for WCOW bind mounts. Keep write sharing
enabled so writable cache contents continue to work normally.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 2523c023ecac816c8131ea08b37f9b84145d5acc)
(cherry picked from commit 0669f4b974)
2026-07-16 17:37:24 -07:00
Tonis Tiigi 4dcf35c691 executor/oci: pin resolved WCOW cache source
Resolve the selected cache subpath through the same handle used to
pin it, then verify that resolved target is still within the cache
root before passing it as the mount source.

This closes the check-to-use gap where containment verification and
pinning could observe different path objects. It also avoids handing
HCS the original path containing attacker-controlled reparse points.

Open the pinned directory with delete access while omitting delete
sharing, so the selected resolved directory cannot be renamed, deleted,
or swapped before HCS consumes the mount source. Keep write sharing
enabled so writable cache contents can still be modified while the
handle is alive.

Keep the HCS-facing source in the normal DOS path form when possible,
so this does not introduce a new \\?\ path format requirement for WCOW
mount realization.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit d854e00d473958b6e164f2e821eab902245705ad)
(cherry picked from commit 44c0ed6b1c)
2026-07-16 17:37:16 -07:00
Dawei Wei 2ee0a47757 executor/oci: pin WCOW cache mount source across mount realization
The Windows cache mount is realized later by HCS from the resolved host
path, so verification alone leaves a check-to-use window in which the
verified entry could be swapped for a junction escaping the cache root
(concurrent cache access). Hold the verified source open with
GENERIC_READ and a share mode that omits FILE_SHARE_DELETE until the
mount is released, so the entry cannot be renamed or deleted (and thus
swapped) during that window. GENERIC_READ rather than DELETE is used so a
concurrent read/traverse open by the mount stack still succeeds;
validated against a real HCS worker (benign cache mounts still mount and
the escape is still rejected).

Add a unit test asserting the source cannot be renamed while pinned and
can be renamed after release.

Signed-off-by: Dawei Wei <wei.dawei.cn@gmail.com>
(cherry picked from commit 39a7b40489a036134a93502ea3d84d71dca072ea)
(cherry picked from commit 473663bad0)
2026-07-16 17:37:11 -07:00
Dawei Wei 0c3bb3c7ed executor/oci: confine WCOW cache mount source within cache root
On Windows, RUN --mount=type=cache,source=<subdir> resolved the source
subpath with fs.RootPath, which does not follow Windows reparse points.
A junction placed inside the cache root could therefore point to a path
outside the cache, and the resolved source was mounted into the build
container, exposing host files outside the intended cache subdirectory.

Resolve the real path of both the cache root and the selected source via
GetFinalPathNameByHandle (which follows junctions and symlinks) and reject
any source that resolves outside the cache root.

Add Windows unit tests for the resolver and end-to-end regression tests
for the junction escape (Windows) and the symlink escape (Linux).

Signed-off-by: Dawei Wei <wei.dawei.cn@gmail.com>
(cherry picked from commit 70370e18de3cc7545fcf7f986612a28a803f59d2)
(cherry picked from commit a9155a456b)
2026-07-16 17:37:06 -07:00
Kunalbehbud fb88c3a0ec oci: don't override build-provided OpenTelemetry env vars
BuildKit injects OTEL_TRACES_EXPORTER (and the OTLP endpoint/protocol)
into the build environment whenever a tracing socket is configured, and
it did so unconditionally -- appending its values after any the build
already set. That made it impossible to opt out or override them; for
example `--opt env.OTEL_TRACES_EXPORTER=none` had no effect because
BuildKit re-added OTEL_TRACES_EXPORTER=otlp afterwards.

Only inject the trace-exporter variables the build has not already set,
so a build can override them or opt out of tracing.

Fixes #4972

Signed-off-by: Kunalbehbud <b.kunal2002@gmail.com>
2026-07-15 18:45:49 +03:00
Tonis Tiigi 9cdf642943 fs: reject special files for ref reads
Ref and rootfs helpers may read paths supplied by frontends or build outputs.
Reject non-regular files before reading them into memory so device and FIFO
paths cannot feed no-EOF streams into parsers or bundle injection logic.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-06-26 00:02:39 -07:00
Tonis Tiigi 408266e4ba user: limit size of parsed passwd/group files
Resolving a username to uid/gid read /etc/passwd and /etc/group via
os.Open with no upper bound, letting a crafted image force unbounded
memory use during user resolution. Cap reads at 10MiB and reject
non-regular files in both the OCI executor and the chown user resolver.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 83cfc1e0ea1dcf8816f259ee6720b8694ab874e5)
2026-06-24 10:56:53 -07:00
Tonis Tiigi 64bbec89ca security: validate exec security modes
Reject unknown SecurityMode values before generating executor specs. Ensure
only SecurityMode_INSECURE takes the insecure path, while validated non-insecure
modes keep sandbox security options. Add gateway, raw LLB, and LLB marshal
regression coverage for invalid enum values.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 972895718f963c71388aeebb7cff423ef6963a92)
2026-06-24 10:56:46 -07:00
Sebastiaan van Stijn 50b548a135 vendor: migrate to github.com/gohugoio/hashstructure
The github.com/mitchellh/hashstructure/v2 module was archived, and
there's a maintained fork in the gohugoio org.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-06-17 10:02:52 +02:00
CrazyMax d13b3ac2ce Revert "executor: fix containerd stdin close race"
This reverts commit cb6df1c266.

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2026-06-10 18:25:51 +02:00
CrazyMax 7a2c61eefd Merge pull request #6810 from tonistiigi/containerd-exec-test-fix
test: stabilize worker exec pid1 lifetime
2026-06-10 11:18:19 +02:00
Tonis Tiigi cb6df1c266 executor: fix containerd stdin close race
Delay containerd stdin CloseIO until BuildKit's stdin reader reaches EOF.
This avoids racing the shim FIFO copy path, where closing stdin before
the copy completes can leave execs stuck or missing stdin data.

Add a client gateway regression that runs concurrent execs writing stdin
into files and verifies every payload is present.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-06-09 17:28:39 -07:00
Tonis Tiigi 91cc422d5f network: split exec proxy from net mode
Keep exec network modes limited to sandbox, host, and none, and pass proxy
network configuration separately through solve and executor runtime state.

Proxy execs now use bridge-style egress by default, host egress only for host
network mode with entitlement, and no proxy for none mode. Add integration
coverage for bridge, host, and none proxy behavior across OCI and containerd
workers.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-06-09 09:11:33 -07:00
CrazyMax 63e37e87d1 Merge pull request #6815 from tonistiigi/stdin-fix
executor: avoid runc stdin shutdown hangs
2026-06-09 10:36:53 +02:00
Tonis Tiigi 953437b102 executor: avoid runc stdin shutdown hangs
Forward non-tty stdin through an os.Pipe so runc receives an *os.File
instead of the caller's reader. This lets runc exit after the container
process is killed without waiting on Go's internal stdin copy.

Add gateway coverage for graceful pid1 exit, release-based cleanup, and
explicit SIGKILL while pid1 stdin is still open.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-06-08 18:10:52 -07:00
Tonis Tiigi 6f08a4ab4a test: cover proxy network source conversion
Add integration coverage for exec proxy source policy conversion. The test
requests /foo, rewrites it to /bar, and verifies exported content and
provenance materials use the converted source.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-06-04 11:23:03 -07:00
Tonis Tiigi 2bdf6abf99 network: capture proxy exec materials
Record successful GET responses through the exec proxy as provenance
materials and report incomplete material coverage as a typed solve error.
Thread proxy policy and capture state through typed executor/network options.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-06-04 11:23:02 -07:00
Tonis Tiigi 3254832159 solver: add proxy network mode
Add a build request option that rewrites default exec networking to an
internal proxy network while preserving explicit none networking.

Route HTTP and HTTPS traffic through a BuildKit-owned proxy namespace, enforce
source policy checks for proxied requests, and inject a temporary CA into Linux
rootfs trust bundles for HTTPS interception.

Share namespace pooling between CNI and proxy providers, and cover proxy mode
with unit and integration tests.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-06-04 11:23:00 -07:00
Tõnis Tiigi f5ec43c9e9 Merge pull request #6569 from jirimoravcik/feat/add-cpu-memory-limits
solver: add per-step CPU and memory resource limits
2026-05-27 10:29:57 -07:00
Jiří Moravčík f85c740c2b solver: add per-step CPU and memory resource limits
Add support for setting cgroup resource limits (memory, memory-swap,
cpu-shares, cpu-period, cpu-quota, cpuset-cpus, cpuset-mems) on
individual build steps.

Signed-off-by: Jiří Moravčík <jiri.moravcik@gmail.com>
2026-05-27 11:34:13 +02:00
Jonathan A. Sternberg 87627f0115 runcexecutor: change how the runc executor kills runc processes
Change how the runc executor kills runc processes by removing the
previous warning message that occurred every 50 milliseconds with a bit
more precision in how it sends the warning.

The previous version could potentially successfully kill the runc
process and then the runc process could take some time to exit. It would
spam the logs every 50 milliseconds until the process exited and would
attempt to rekill a container that was already marked as killed.

This change makes it so we detect a successful kill. If we detect a
successful kill, we then wait for the process while writing a warning to
the log that the process is taking a long time to end. We print one
message 50 milliseconds after the kill and then an additional one with
the exact time it took to exit after the exit succeeds.

If the kill is not successful, we stay in the same loop as previously
existed.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2026-05-19 14:19:04 -05:00
Tõnis Tiigi 550cf8b8b7 Merge pull request #6774 from tonistiigi/0513-dev-tools-updates
dev tools updates
2026-05-14 17:37:14 -07:00
Tonis Tiigi 98e1113c6d lint: modernize Go lint findings
Update non-generated code for the newer lint recommendations by using typed
atomic values, strings.Cut, and slices.Backward where applicable.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-05-14 10:13:21 -07:00
Tonis Tiigi bd3608ddc9 lint: update golangci-lint to v2.12.2
Update golangci-lint and adjust code for new gosec diagnostics. Use
root-scoped filesystem operations where appropriate, preserve explicit
user path behavior for SSH keys, and avoid background contexts in
request-scoped cleanup paths.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-05-14 10:13:15 -07:00
Maya Chen 3786f4e24d chore: fix duplicated words in llb, executor and dockerfile_test comments
Signed-off-by: Maya Chen <275405107+otjdiepluong@users.noreply.github.com>
2026-05-14 06:42:49 +00:00
Jonathan A. Sternberg 265c6e08ff otel: refactor tracing helpers for child processes
Merge the `tracing/env` and `tracing/exec` package into a single package
with some common types shared between the two.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2026-04-16 10:28:19 -05:00
Tonis Tiigi b46ee07a5d executor/oci: scope state files to roots
Use os.OpenRoot for resolv.conf and hosts state file creation, and
adapt executor callers and tests to the root-relative helper API.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-03-25 08:14:31 -07:00
Tonis Tiigi 6e9d3d4bbc executor: validate container IDs centrally
Add executor.ValidContainerID and enforce it in runc/containerd Run paths.

Only runc executor used the ID in filesystem operations.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 789df2422341960b7549d14ea475add43e73cd74)
2026-03-25 08:14:29 -07:00
Tonis Tiigi 481132ff14 refactor: deduplicate NopWriteCloser into util/iohelper
Replace duplicate nopCloser, nopWriteCloser, and bufferCloser
type definitions across test and production code with the
shared iohelper.NopWriteCloser type.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-03-09 22:16:14 -07:00
Tonis Tiigi b61489948c tests: use t.Context in unit tests
Replace context.TODO/background calls in targeted unit tests with
t.Context().

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-02-25 16:41:54 -08:00
Tonis Tiigi a8b83196f3 ci: update golangci to v2.8.0
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-01-13 22:09:20 -08:00
Vigilans 30ef2919a9 Rename isolated to hypervIsolation
Signed-off-by: Vigilans <vigilans@foxmail.com>
2025-09-16 23:59:37 +08:00