103 Commits
Author SHA1 Message Date
Tonis Tiigi a868d25987 containerdexecutor: fix race on err in event loops
The resize and signal goroutines in runProcess both assigned the err
variable of the enclosing function, so concurrent Resize and Signal
calls on a process raced, and either goroutine could log the other's
error. Use a local error in each goroutine.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-10-27 22:55:53 -07: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
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 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
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
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
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
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
Vigilans 30ef2919a9 Rename isolated to hypervIsolation
Signed-off-by: Vigilans <vigilans@foxmail.com>
2025-09-16 23:59:37 +08:00
Vigilans 209509356a Support isolated option in containerd executor in Windows
Signed-off-by: Vigilans <vigilans@foxmail.com>
2025-09-15 17:32:18 +08:00
Tonis Tiigi f1f56c2b77 golangci-lint: v2 upgrade
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-05-02 12:19:17 -07:00
Jonathan A. Sternberg 66016a8c63 vendor: switch from idtools to moby/sys/user
Convert usages of `github.com/docker/docker/pkg/idtools` to
`github.com/moby/sys/user` in order to break the dependency between
buildkit and docker.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2025-04-02 10:22:02 -05:00
Tonis Tiigi f61e01c14c llbsolver: on-demand CDI devices with automatic setup
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-02-11 11:21:48 +01:00
CrazyMax d69cc70521 cdi: use worker cdi manager when generating devices oci spec
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2025-02-11 11:21:47 +01:00
Marat RadchenkoandDerek McGowan 5be7edb69c Upgrade to containerd 2
Co-authored-by: Derek McGowan <derek@mcg.dev>
Signed-off-by: Marat Radchenko <marat@slonopotamus.org>
2025-01-13 16:42:48 -08:00
Justin Chadwell 7e6c20a0db exec: allow specifying non-zero exit codes for execs
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-09-17 11:36:07 +01:00
Alano Terblanche c3925da302 Refactor containerd NewWorkerOpt & containerdexecutor New parameters
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2024-06-25 10:24:47 +02:00
Tonis Tiigi 4103099d94 ensure context.WithoutCancel in defer funcs
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-06-12 19:18:32 -07:00
CrazyMax b5506327cf keep local dns in resolv.conf when host network enabled
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-02-09 09:27:39 +01:00
Tonis Tiigi 09648f4d29 replace WithTimeout with WithTimeoutCause
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-12-06 22:15:12 -08:00
Tonis Tiigi 8a2a3e83ec replace context.WithCancel with WithCancelCause
Keep stack traces for cancellation errors where possible.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-12-06 22:15:06 -08:00
Justin Chadwell 148e1ea413 containerd: support custom shim path
Like CRI, we should support custom shim paths. We can just add this as a
new config field "path" under the runtime object.

While "name" can be either the name of a custom shim (from which a path
is derived), or a path itself, if configured as a path, no options can
be provided - this is because to derive the type for the options struct,
we need the name to be a member of a well-known set (currently runc and
hcs).

With this patch, it's now possible to configure a runtime with a custom
shim at a non-default path, and include it's options (which was
previously not possible to do in buildkit).

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-11-07 11:18:51 +00:00
Justin Chadwell 116d0153f5 chore: update getTaskOpts to return multiple opts
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-11-07 11:16:51 +00:00
Justin ChadwellandMarat Radchenko 8bfd280ab7 Add options to specify containerd runtime
Co-authored-by: Marat Radchenko <marat@slonopotamus.org>
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-09-26 14:20:35 +01:00
Gabriel Adrian Samfira cc5657c600 Cleanup args, rename jobDetails
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2023-08-30 13:40:43 +03:00
Gabriel Adrian Samfira b6b322b327 Implement executor on Windows
This change splits the containerdexecutor.Run() function into smaller
pieces and enables it to run on Windows.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2023-08-15 12:35:45 +03:00
Artem KhramovandAkihiro Suda c415d85fe0 FreeBSD port
Buildkit code is mostly generic enough to support FreeBSD, however
there are some quirks / infrastructural pieces that need to be
addressed for full support, to name some

-    contenthash.NewFromStat attempts to set Devmajor / Devminor for
    regular files, assuming that RDev is zero for regular
    files. Unlike on Linux, it's not the case for FreeBSD.

-    containerdexecutor.Run uses bind mounts for rootfs. Bind mounts
    are not supported in FreeBSD and we should use nullfs instead

-    There is no CI job to run tests on FreeBSD

-    Some dependencies weren't ported

This change ports buildkit to FreeBSD

Signed-off-by: Artem Khramov <akhramov@pm.me>
Co-authored-by: Akihiro Suda <suda.kyoto@gmail.com>
2023-07-28 17:02:53 +03:00
Tonis Tiigi 6e87e4b455 resources: add build step resource tracking via cgroups
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-06-08 15:51:31 -07:00
coryb a8aa7b200c use bklog.G(ctx) instead of logrus directly
Signed-off-by: coryb <cbennett@netflix.com>
2023-03-15 12:07:44 -07:00
Tõnis Tiigi e0220af506 Merge pull request #3254 from corhere/c8dexecutor-inprocess-lifecycle-hook
[RFC] containerdexecutor: add network namespace callback
2022-12-22 12:44:31 -08:00
Cory Snider b5fdf90aee containerdexecutor: add network namespace callback
In order to support identity mapping and user namespaces, the Moby
project needs to defer the creation of a container's network namespace
to the runtime and hook into the container lifecycle to configure the
network namespace before the user binary is started. The standard way to
do so is by configuring a `createRuntime` OCI lifecycle hook, in which
the OCI runtime executes a specified process in the runtime environment
after the container has been created and before it is started. In the
case of Moby the network namespace needs to be configured from the
daemon process, which necessitates that the hook process communicate
with the daemon process. This is complicated and slow. All the hook
process does is inform the daemon of the container's PID and wait until
the daemon has finished applying the network namespace configuration.

There is an alternative to the `createRuntime` OCI hook which containerd
clients can take advantage of. The `container.NewTask` method is
directly analogous to the OCI create operation, and the `task.Start`
method is directly analogous to the OCI start operation. Any operations
performed between the `NewTask` and `Start` calls are therefore directly
analogous to `createRuntime` OCI hooks, without needing to execute any
external processes! Provide a mechanism for network.Namespace instances
to register a callback function which can be used to configure a
container's network namespace instead of, or in addition to,
`createRuntime` OCI hooks.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-12-08 19:46:23 -05:00
Justin Chadwell 6b265b1bae gateway: add RemoveMountStubsRecursive to exec meta options
This allows a frontend to request a specific for stubs removal.

By default, if not specified, this will revert to the previous
behaviour. New gateway clients however will set the property to the
desired recursive removal mode.

This property needs to be set for both components that call the
executor: for ExecOp, as well as for the StartContainer API.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2022-12-07 19:06:47 +00:00
Cory Snider f448313827 containerdexecutor: clean up task if Start() fails
Deleting a containerd task whose status is Created fails with a
"precondition failed" error. This is because (aside from Windows) a
process is spawned when the task is created, and deleting the task while
the process is running would leak the process if it was allowed.
Change the deferred `task.Delete` call to pass the `WithProcessKill`
delete option so the cleanup has a chance to succeed in the event that
the `p.Start` call inside `runProcess` returns an error.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-11-02 18:29:34 -04:00
Akihiro Suda bd57e5f6b8 Make SELinux labels opt-in (--oci-worker-selinux=<BOOL>)
Fix issue 3202

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2022-11-02 14:33:01 +09:00
Aaron Lehmann 588a72d04c Add network namespace pool support
This adds netNSPoolSize pool options which allow setting a target
network namespace pool size. buildkitd will create this number of
network namespaces at startup (without blocking). When a container
execution finishes, the network namespace gets returned to the pool. If
the pool goes above the target size, there is a grace period to allow
network namespaces to be reused, and if this passes without reuse, the
extra namespaces will be released.

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2022-09-14 07:08:31 -07:00
Alex Suraci e3c9e064a9 cniprovider: pass hostname as K8S_POD_NAME arg
Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
2022-08-21 15:43:12 -04:00
Sebastiaan van Stijn 21e9e9641e Remove uses of deprecated io/ioutil
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-10 00:57:07 +01:00
Edgar Lee d21254e7f7 Add events for exec op
Signed-off-by: Edgar Lee <edgarl@netflix.com>
2022-03-02 12:05:35 -08:00
Kohei Tokunaga 21aeba6fd6 Support rootless containerd worker
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2022-02-21 15:39:14 +09:00
Cory Bennett 559d079902 Allow signals to be sent to gateway exec containers
Signed-off-by: Cory Bennett <cbennett@netflix.com>
2022-02-02 16:57:10 +00:00
Tõnis Tiigi 539be17089 Merge pull request #2428 from tonistiigi/default-user-groups
executor: make sure supplementary groups are set for unset user
2021-12-14 17:02:09 -08:00
CrazyMax c82ef274bf cgroup-parent support
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-10-27 23:50:20 +02:00
Tonis Tiigi e82ccdf958 containerdexecutor: fix setting user
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-10-27 11:26:10 -07:00