Commit Graph
561 Commits
Author SHA1 Message Date
Steve 2a591c2aee fix(package): exclude CloudHypervisor README (#798)
## Summary

Exclude `Sources/CloudHypervisor/README.md` from the `CloudHypervisor`
SwiftPM target. The README remains tracked and available as source
documentation, while package evaluation and builds no longer emit an
unhandled-file warning.

## Motivation


[apple/containerization#782](https://github.com/apple/containerization/pull/782)
added a standalone `CloudHypervisor` target with a README inside its
source directory. SwiftPM requires non-source files in target
directories to be declared as resources or excluded. This README is
documentation rather than a runtime resource, so exclusion is the
smallest accurate manifest change.

## Changes

- Add `README.md` to the `CloudHypervisor` target's `exclude` list.
- Preserve the existing README content and location.
- Leave runtime code, products, resources, and package APIs unchanged.

## Validation

```sh
swift package describe >/dev/null
swift test --disable-automatic-resolution --filter CloudHypervisorTests
make check
git diff --check upstream/main...HEAD
```

- Package evaluation completes without the
`Sources/CloudHypervisor/README.md` warning.
- All 41 focused `CloudHypervisorTests` pass.
- Swift formatting and Hawkeye license checks pass.
- The committed diff has no whitespace errors.

## Compatibility And Risk

This manifest-only change does not alter compiled sources, runtime
resources, public APIs, or supported platforms. The README is already
non-executable documentation, so excluding it accurately records
SwiftPM's intended treatment of the file.

## Related

- Follow-up to
[apple/containerization#782](https://github.com/apple/containerization/pull/782).

## Release Note Highlight

- Stops SwiftPM builds from warning about the `CloudHypervisor` README
added by
[apple/containerization#782](https://github.com/apple/containerization/pull/782).
2026-07-15 10:20:08 -04:00
Aditya Ramani 2f947e7614 Unset CONFIG_VSOCKETS_LOOPBACK in kernel config (#797)
Align this setting with what the Kata kernel used by the container tool
specifies.
2026-07-09 17:25:44 -07:00
Michael Crosby 315341b625 add masked and readonly path support (#795)
Signed-off-by: michael_crosby <michael_crosby@apple.com>
2026-07-08 16:47:16 -04:00
Michael Crosby 6093542d9c cctl: deprecate creds over http (#788)
Signed-off-by: michael_crosby <michael_crosby@apple.com>
2026-07-08 14:31:26 -04:00
Michael Crosby 1d5641ff96 fix hotplug mounting of virtiofs (#794)
Signed-off-by: michael_crosby <michael_crosby@apple.com>
2026-07-07 18:09:37 -04:00
adityabagchi24 7aa4e723f6 Upgrade grpc-swift-nio-transport to 2.9.0 and remove HTTP2ConnectBuff… (#778)
- Fixes #776
- Release 2.9.0 of `grpc-swift-nio-transport` fixes
  the HTTP/2 initialization race that required a
  `HTTP2ConnectBufferingHandler` for the vminitd
  API. This upgrades the dependency and eliminates
  the workaround.
2026-07-07 08:49:17 -07:00
Michael Crosby bd709ba8cb fix: default to restricted OCI capability set (#786)
Changes the default Linux capability set for container processes from
`.allCapabilities` to `.defaultOCICapabilities`, making the library
secure-by-default. Callers that genuinely need elevated capabilities
must now opt in explicitly.

Signed-off-by: michael_crosby <michael_crosby@apple.com>
2026-07-02 12:45:15 -04:00
Michael Crosby b438e97b93 Add cloud-hypervisor VMM backend for Linux hosts (#782)
apple/containerization currently runs containers in per-container VMs on
macOS hosts via Virtualization.framework. This adds a second VMM backend
so the same Swift orchestration layer (LinuxContainer / LinuxPod /
Vminitd gRPC contract) runs on Linux hosts via cloud-hypervisor + KVM.

**CloudHypervisor Swift package** (`Sources/CloudHypervisor/`) — a thin
client for cloud-hypervisor's REST-over-UDS API, layered on
AsyncHTTPClient. Endpoints cover VMM / VM lifecycle / hotplug (disk, fs,
net, vsock, remove-device). Cross-platform (compiles on macOS for unit
tests; consumed at runtime only by the Linux side of Containerization).

**CH backend in Containerization** — one cloud-hypervisor subprocess per
VM, gated behind `#if os(Linux)`. CHVirtualMachineManager /
CHVirtualMachineInstance mirror the VZ shape behind the existing
VirtualMachineManager / VirtualMachineInstance protocol. CHProcess and
VirtiofsdProcess manage the binaries; CHHotplugProvider handles
virtio-blk and virtio-fs runtime hotplug (with one virtiofsd per unique
source-hash tag, refcounted across containers).

**Linux host networking** — BridgeManager brings up a Linux bridge with
an IPv4 subnet and (opt-in via `--enable-nat`) iptables MASQUERADE +
scoped FORWARD rules. LinuxBridgedNetwork enslaves a fresh TAP per
container to the bridge. State is recorded under `/run/containerization`
so `cctl bridge delete` reverses exactly what create did. Bridge
teardown verifies the link kind via sysfs to refuse deleting non-bridge
interfaces.

**cctl run / bridge** — end-to-end Linux container run path (image pull,
ext4 rootfs assembly, VM boot, container exec) plus `cctl bridge
create|delete` for the host network plumbing.

**Build & dist** — `make linux-build` / `make linux-integration` build
and exercise the host side inside an apple/container `--virtualization`
dev container. `make dist-x86_64` produces a deployment tarball (cctl +
cloud-hypervisor + virtiofsd + initfs + kernel) cross-compiled from the
aarch64 dev container; pipeline documented in `docs/x86_64-build.md`.
Static-musl C deps and the Zig cross compiler are pinned by SHA256.

The host orchestrator runs as root. Per-VM runtime state lives under
`/run/containerization/ch/<UUID>` with mode 0700; UDS sockets inside are
bound with mode 0600. Vminitd's gRPC channel inherits that trust
boundary — socket-file perms are the auth.

Sandbox flags are upstream-secure by default. Two per-component opt-outs
exist for the apple/container dev-container case (where the host seccomp
profile SIGSYS-kills CH and virtiofsd):
- `CONTAINERIZATION_NO_CH_SECCOMP=1` — `cloud-hypervisor --seccomp
false`.
- `CONTAINERIZATION_NO_VIRTIOFSD_SANDBOX=1` — `virtiofsd --sandbox
none`. Each emits a one-shot `logger.warning` at process start. Legacy
alias `CONTAINERIZATION_RELAXED_SANDBOX=1` flips both. cctl spawns both
binaries with `setsid` and a minimal env allowlist (PATH / HOME /
RUST_LOG / RUST_BACKTRACE) so the parent's secrets don't leak to
children.

`make linux-integration` runs the cross-platform integration suite
against a real cloud-hypervisor VM inside the dev container. Linux runs
the cross-platform subset (`process true`/`false`/`echo hi`, virtiofs
round-trip, hotplug); the macOS suite is unchanged.

Signed-off-by: michael_crosby <michael_crosby@apple.com>
2026-07-02 11:20:22 -04:00
Kathryn Baldauf ade205218c Add checksum validation to hawkeye installation (#785)
Related to https://github.com/apple/container/pull/1869

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2026-06-30 13:40:34 -07:00
Aditya Ramani 44bec8b993 Support disk image based pod volumes (#780)
The `PodVolume` type in `LinuxPod` only defined the `nbd` enum value -
however, disk based images are also supported and the pattern is
essentially the same

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2026-06-26 10:55:36 -07:00
Malte Poll d992a1996d fix(EXT4): create missing parent dirs for hardlinks during unpack (#777)
When unpacking an OCI/tar layer, create() already creates missing parent
directories recursively, so regular files and symlinks with absent
parent entries unpack correctly. link() did not, so a hardlink whose
parent directory had no explicit archive entry failed with "<path> not
found" (e.g. images produced by Bazel rules_img). Mirror create()'s
implicit parent creation in link() so such layers unpack, matching
Docker/containerd.

Adds a direct link() unit test and an end-to-end unpack regression test
covering a hardlink, regular file, and symlink with no explicit parent.

Fixes https://github.com/apple/container/issues/1797
2026-06-24 10:31:07 -07:00
J Logan a132341dc6 Make EXT4Unpacker configurable for journal mode. (#775)
- Closes #774.
- Adds a default journal configuration parameter to the EXT4Unpacker
init function, defaulting to nil (no journal) to preserve source
compatibility.
2026-06-23 10:41:25 -07:00
Saehej Kang 6b7b42ca3e [vminitd]: api for trim filesystem operations (#700)
Addition of `vminitd` API for trim filesystem operations

Closes #773

Depends on #685
2026-06-20 06:32:23 -07:00
Saehej Kang 5887dc55f3 [vminitd]: api for freeze/thaw filesystem operations (#685)
Addition of `vminitd` API for freeze/thaw filesystem operations

Closes #660
2026-06-19 14:45:17 -07:00
Aditya Ramani d55cc188ce Allow setting log level for vminitd (#772)
The `--log-level` option when running the agent sub-command for vminitd
was being silently ignored cause of the way the agent is being run. As a
workaround we need to read `/proc/self/cmdline` to get the right args
2026-06-16 18:04:31 -07:00
Mojtaba HosseiniandJ Logan 7e2ae5a170 docs: fix traversal in a public method's documentation (#770)
Seems like a typo.
The change only affected a comment and does not disturb the code at all
(backward compatible).

Co-authored-by: J Logan <john_logan@apple.com>
2026-06-16 12:41:46 -07:00
Michael Crosby ddd19a61a8 add x86 kernel config (#765)
Add x86 kernel config and build scripts.

Signed-off-by: michael_crosby <michael_crosby@apple.com>
2026-06-16 12:47:20 -04:00
J Logan e29657b86e Pin macOS CI builds to Swift 6.3 for now. (#771)
- CI runners moved to the Xcode developer beta as the default, but macOS
builds are failing with a conflicting options error for
`-warnings-as-errors` and `-suppress-warnings`.
2026-06-16 11:44:27 -04:00
Vitor Hugo 4f6df44c2a fix(Platform): make arm64 nil-variant and v8 hash identically (#764)
## Summary

`Platform.==` treats `arm64` with `nil` variant as equal to `arm64/v8`,
but `hash(into:)` used `description` which serializes them differently
(`linux/arm64` vs `linux/arm64/v8`). This violates the `Hashable`
contract — equal values must produce the same hash.

### Root cause

```swift
// == returns true for these two
let a = Platform(arch: "arm64", os: "linux", variant: nil)
let b = Platform(arch: "arm64", os: "linux", variant: "v8")
a == b // true ✓

// but hash was different — broken
a.hashValue == b.hashValue // false ✗ (before this fix)
```

This mismatch caused `Set<Platform>` and `Dictionary<Platform, ...>`
lookups to silently miss entries when one platform was decoded from JSON
(no `variant` field in the manifest) and another was created via
`Platform(from:)` or `Platform.current` (which both set `variant =
"v8"`).

### Practical consequence

In `apple/container`, this manifests as inconsistent platform-string
normalization across stages of a single `container build` — some stages
log `linux/arm64`, others `linux/arm64/v8` — which can cause `COPY
--from=<stage>` to fail to resolve the source stage under concurrent
builds. See apple/container#1542.

### Fix

`hash(into:)` now normalizes `arm64` with `nil` variant to `"v8"` before
hashing, matching the existing `==` behavior.
2026-06-16 10:06:06 -04:00
Kathryn Baldauf 1437c67f5a Update github actions to use SHA versions (#763)
Related to https://github.com/apple/container/pull/1649. This PR updates
the GitHub workflows to ensure all imported actions are referenced by
commit SHA.

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2026-06-04 15:08:22 -07:00
Danny Canter 9275f365dd [Experimental] Add Sandboxy binary (#607)
Sandboxy is an example tool to run isolated coding agents.
2026-06-03 12:27:49 -04:00
e1e31b7ae9 add IPv6 support (#752)
Extends the network plumbing to support per-interface IPv6 address
configuration.
The `Interface` protocol supports `ipv6Address` and `ipv6Gateway`.
The agent's networking RPCs carry per-family fields via new
`InterfaceAddress`, `LinkRoute`, and `DefaultRoute` types in
`ContainerizationExtras`.
`NetlinkSession` adds IPv6 methods for address and route operations.

---------

Co-authored-by: michael_crosby <michael_crosby@apple.com>
Co-authored-by: Michael Crosby <crosbymichael@gmail.com>
2026-06-03 12:07:20 -04:00
Yibo Zhuang 72043f90ac ContentStore: Fix totalAllocatedSize on Linux (#761)
`.totalFileAllocatedSizeKey` returns nil for directories on Darwin but
on Linux it returns `st_blocks * st_blksize` (4 KB each) in Foundation.
The empty-store test summed three directory inodes on Linux and failed
with `#expect(size == 0)`. This change adds filter on the enumerator to
regular files only so the totals are content-only and will work for both
Darwin and Linux.
2026-06-01 17:06:09 -07:00
Raj a2a1add6c7 Add totalAllocatedSize to ContentStore (#760)
This PR adds `totalAllocatedSize()` to the `ContentStore` protocol so it
can be used to get the on-disk footprint without reaching past the
abstraction. `LocalContentStore` implements it by walking its base path,
covering both committed blobs and active ingest sessions.
2026-06-01 14:22:04 -07:00
Danny Canter 6cb66583e2 Stats: Expose more memory stats (#758) 2026-06-01 11:52:53 -07:00
Danny Canter b1e779eb2a Cgroup2: Add ability to filter stats (#757) 2026-06-01 11:51:50 -07:00
mlsad3 fd820380a6 Fix head-of-line blocking and resource leak in BidirectionalRelay (#713)
- Closes #712.
- Replace synchronous `write()` calls in
  `BidirectionalRelay` with non-blocking I/O
  and `DispatchSourceWrite` backpressure
  handling. Under concurrent vsock proxy load,
  a single blocked write on the shared serial
  dispatch queue would freeze all relay
  connections permanently, including unrelated
  new connections.
- Set relay file descriptors to `O_NONBLOCK`
  and handle `EAGAIN` by suspending reads and
  installing a write source to drain pending data.
- Give each `BidirectionalRelay` its own serial queue
  instead of sharing one from `UnixSocketRelayManager`,
  eliminating cross-connection blocking.
- Resume suspended read sources before cancelling
  in `stop()` — GCD does not deliver cancel handlers
  on suspended dispatch sources, which caused file
  descriptor and memory leaks on teardown under
  backpressure.
- Guard-unwrap `buf.baseAddress` in
  `drainPendingWrite`.
2026-06-01 10:33:36 -07:00
Saehej Kang 2550dd49f1 [os]: add FilePathOps utility type + initial absolute path function (#751)
- Closes #744
- Adds the initial `FilePathOps` utility type
- Adds the `absolutePath` implementation
- Adds the `FilePathOpsTests` file and initial test cases
2026-05-27 08:27:28 -07:00
pickle-RickAandpickle-RickA 565e8a3e02 Improve documentation formatting and consistency (#633)
Small documentation improvements for better consistency:

- Fixed capitalization (url → URL) in kernel README
- Added bash syntax highlighting to code block in lab.md  
- Improved formatting consistency in ctr-example README (added colon +
code fence)

Co-authored-by: pickle-RickA <273219719+pickle-RickA@users.noreply.github.com>
2026-05-27 00:23:39 -07:00
Aditya Singh d09a1026b7 Fix incorrect byte shift in IPv4Address byte-array initializer (#754)
The `IPv4Address(_ bytes: [UInt8])` initializer in
ContainerizationExtras shifts the third octet by 16 bits instead of 8:

```swift
self.value =
    (UInt32(bytes[0]) << 24)
    | (UInt32(bytes[1]) << 16)
    | (UInt32(bytes[2]) << 16)   // should be << 8
    | UInt32(bytes[3])
```

Because `bytes[2]` lands in the same bit range as `bytes[1]`, the second
octet gets corrupted by the OR, the third octet is dropped, and bits 8
through 15 are always left zero. Concretely, decoding `[192, 168, 1, 1]`
yields `192.169.0.1` instead of `192.168.1.1`, and `[18, 52, 86, 120]`
yields `18.118.0.120` instead of `18.52.86.120`.

This went unnoticed because the `bytes` computed property getter uses
the correct `>> 8` for the third octet, but there was no test exercising
the byte-array initializer, so the encode and decode paths were never
checked against each other. The sibling `IPv6Address(_ bytes:)`
initializer uses the correct descending shifts (`<< 120, << 112, ... <<
8, << 0`), which is what the IPv4 version should mirror.

The fix changes the third octet shift to 8 bits so the initializer is
the exact inverse of the `bytes` property. I also added two tests to the
initializer suite: a valid-input test that asserts both the resulting
`value` and that `init(bytes).bytes == bytes` round-trips, and an
invalid-length test. The round-trip test fails on the current code and
passes with the fix.

Verification: `swift test --filter ContainerizationExtrasTests` passes
221 tests in 26 suites (the IPv4Address suite goes from 23 to 25 tests).
The new round-trip test fails before the one-line change and passes
after.

Signed-off-by: Aditya Singh <adisin650@gmail.com>
2026-05-26 13:38:05 -07:00
David Palma 25558e6b85 ImageStore: Preserve source index mediaType on push (#750)
- Closes #749.
- ExportOperation hardcoded the pushed index descriptor's
  mediaType to the OCI image index type. RegistryClient.push
  uses that descriptor's mediaType as the HTTP Content-Type
  header. When the source index was in
  Docker manifest.list.v2+json format (the common case for
  images pulled from Docker Hub and other public registries),
  the body's embedded mediaType field disagreed with the
  header, and OCI registries rejected the index PUT with
  HTTP 400 MANIFEST_INVALID.
- Use the source index's mediaType for the pushed descriptor
  so the header always matches the body. Per-architecture
  child manifests are unaffected because they were already
  pushed with their actual mediaType.
- Add a parameterized unit test for ExportOperation.export
  covering both Docker manifest.list
2026-05-21 17:48:40 -07:00
Dmitry Kovba 9205a76630 Keep CVersion in the vminitd package (#747)
Moves `CVersion` back to the `vminitd` package. This is a follow-up for
apple/containerization#742.
2026-05-20 20:17:26 -07:00
Shaurya Singh 485a1a3735 Fix missing apostrophes in Image scope-walk comment (#741)
- Grammar fix in comment.
2026-05-20 16:28:07 -07:00
J Logan d3d7d2143c Adds FileDescriptor-based enumerate(). (#746)
- Closes #745.
- Facilitates TOCTOU-safe recursion over directory contents.
- Replace FileDescriptor extensions with a static utility type to
prevent potential namespacing issues as this project and Swift evolve.
2026-05-20 15:55:29 -07:00
Dmitry Kovba c8fe3bbef9 Move the VminitdCore library to the top-level package (#742)
External Swift Package Manager consumers can only see products declared
in the top-level `Package.swift`. The `VminitdCore` library was declared
inside the `vminitd` subpackage, so it was impossible to build a custom
`vminitd` against it via a URL dependency on `containerization`. This
change moves the `VminitdCore` to the top-level `Package.swift`.
2026-05-20 15:46:32 -07:00
Simone Panico db5b5b9840 Add path resolution for CopyIn using Stat (#727)
This pull request enhances the handling of file and directory copy
operations in Linux containers, particularly by improving destination
path resolution and error handling for the `copyIn` operation with the
`Stat RPC`

This PR is needed for
[container#1190](https://github.com/apple/container/pull/1190)
2026-05-19 10:25:43 -07:00
Michael Crosby 872f601f93 add hotplug interfaces for vmms (#740)
Signed-off-by: michael_crosby <michael_crosby@apple.com>
2026-05-18 10:29:36 -07:00
jwhur f8a18e8dcd Make maxIDLength public (#734) 2026-05-11 16:31:30 -07:00
Danny Canter ece8f984b3 vminitd: Fix UDS length issue with large container IDs (#731)
Today we craft the proxied sockets we create at a path that contains the
container ID. This is normally completely fine, except if the ID is
enormous, as it can cause the UDS path to be longer than the allowed
length.
2026-05-11 15:26:31 -07:00
Danny Canter 737bd37777 LinuxContainer/LinuxPod: Add ID length restriction (#733)
I think realistically we should have a limit on this. Technically today
the ID length restriction is whatever our grpc buffer length is..

I think 64 is long enough so that folks could use an entire hex based
sha256, any uuid, and also sethostname has a length restriction of 64
anyways.
2026-05-11 14:47:20 -07:00
J Logan 3ff7321562 Set devcontainer Swift image version to 6.3.0. (#732)
- We were using Swift 6.3, which can pick up a newer version that is out
of sync of both the `.swift-version` file for the project and the Swift
SDK downloaded in the Dockerfile.
2026-05-09 17:38:24 -07:00
Dmitry Kovba e9f4ece2bb Skip comment lines when parsing the passwd and group files (#728)
Skips comment lines when parsing the `passwd` and `group` files.
2026-05-08 12:22:20 -07:00
Yibo Zhuang 03280f3952 refactor memory alignment to VZVirtualMachineInstance (#725)
Move the MiB rounding from LinuxContainer into
`VZVirtualMachineInstance`, so all callers are covered in one place and
the alignment constraint stays with the VMM layer that owns it.

This will also ensure LinuxPod can get memory alignment for free.
2026-05-06 07:36:10 -07:00
Danny Canter 8140499b4f TerminalIO: Fix ebadf on close (#719)
The stdout and stdin IOPairs in TerminalIO share the same Terminal fd.
Closing stdin first would close the Terminal, causing stdout to read -1
from fileDescriptor and fail to unregister from epoll. This left stale
handler closures (capturing the IOPair) in ProcessSupervisor.handlers
indefinitely.

Additionally, vsock sockets created in TerminalIO.start() with
closeOnDeinit disabled were never closed if the process exited before
attach() created IOPairs.
2026-05-04 10:35:41 -07:00
Tony Coconate 9d2b5794e3 Enable CIFS/SMB kernel support in arm64 config (#681)
## Summary

Enables CIFS (SMB) filesystem support in the arm64 kernel config,
required for the SMB volume driver added in apple/container#1414.

Without this change, SMB mounts fail at runtime with `errno 19
(ENODEV)`.

## Changes

- `kernel/config-arm64`: enable `CONFIG_CIFS=y` and related options
(`CIFS_ALLOW_INSECURE_LEGACY`, `CIFS_UPCALL`, `CIFS_XATTR`,
`CIFS_POSIX`, `CIFS_DFS_UPCALL`)
2026-05-02 18:04:14 -07:00
Kathryn Baldauf c519d57609 Add unit tests for AsyncLock (#720)
These tests were requested as part of a test change in
https://github.com/apple/container/pull/1497. These tests mimic a lot of
the tests in
https://github.com/apple/containerization/blob/main/Tests/ContainerizationExtrasTests/AsyncMutexTests.swift
where possible/appropriate.

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2026-05-01 16:05:49 -07:00
Danny Canter dc710a32a6 AsyncSignalHandler: Add helper to catch all signals (#722) 2026-05-01 15:02:34 -07:00
Danny Canter 57d157c82a Signal: Expose helpful helper methods (#721)
- Method to grab the signal name
- Convert macOS signal to linux equivalent
2026-05-01 14:51:40 -07:00
jwhur f2c42402e7 Refactor ArchiveWriter to expose archiving each path independently (#693)
This PR refactors `ArchiveWriter` to add an API `archive(_ paths:
base:)`. This API is used to archive the contents at each path
independently, similar to doing `tar -cvf archive.tar foo.bin
/bar/baz.txt`.
2026-04-30 18:23:47 -07:00
Sidhartha Mani df125a2300 Prevent recursion attacks in EXT4Formatter.unlink (#415)
This issue doesn't affect any of our existing products. This is a
preemptive fix for downstream consumers of EXT4.format where, in some
platforms, leading `//` in the path could get resolved into a FileTree
that looks like this

```sh
/ 
 └──  / 
 └── usr
```
2026-04-30 12:01:32 -07:00