Commit Graph
453 Commits
Author SHA1 Message Date
Danny Canter 9d40420cd0 Swift: Bump to 6.3 (#646)
6.3 is released now
2026-04-03 14:04:50 -07:00
Dmitry Kovba 79427211dc Fix a retain cycle in the FileTreeNode class (#638)
Fixes a retain cycle in the `FileTreeNode` class.
2026-04-03 17:01:24 -04:00
Danny Canter c32d0f3716 makefile: Don't point to /usr/bin/swift on non-macOS (#644)
We hardcode /usr/bin/swift to point to your xcodes swift for the host
code. This isn't the usual path on other OS'.
2026-04-03 12:37:18 -07:00
Danny Canter 1d60473274 LinuxPod: Remove macOS ifdef (#643)
It compiles fine on non-macOS
2026-04-03 12:31:42 -07:00
Aditya Ramani f8c943b44d Write file data in chunks in ContentWriter (#634)
Update the `ContentWriter.create(from url: URL)` method to not load the
whole file in memory when computing its hash and writing its contents
2026-04-03 12:20:12 -07:00
Danny Canter 3c4215702b LinuxContainer/LinuxPod: Sort mounts by depth (#601) 2026-04-03 10:28:47 -07:00
J Logan f2dda5d9b5 Show memory, cpusets in /proc/cgroups. (#642)
- Helps with JDK 11 workloads.
- Adds CONFIG_LOCALVERSION to kernel build.
2026-04-03 09:54:16 -07:00
Anthony 35f97f225d Add progress handler for rootfs unpacking (#515)
I've added an optional progress handler for rootfs unpacking so that
consumers can show progress. The Ubuntu image takes about 8 seconds to
unpack on my machine, and I'm developing an app where it would be useful
to show progress in the UI.

Total size is determined in an optional first pass that scans archive
headers. Bytes written are then reported during unpacking. The optional
first pass adds 15 (Alpine) to 115 (Ubuntu) ms to unpacking duration on
my machine, depending on image size.
2026-04-02 17:33:55 -07:00
Dmitry Kovba 11bbbbb852 Support a default route without a gateway (#628)
Adds the support for a default route without a gateway.

```
/ # ip route show default
default dev eth0 scope link 
```
2026-04-02 14:27:56 -07:00
Danny Canter 4040ce20c2 vminitd: Get rid of unused CgroupManager (#621) 2026-04-02 10:13:07 -07:00
Danny Canter 8615e3b021 Remove more incorrect os gates (#632)
A lot of logic we have works perfectly fine on other OS'.
2026-04-02 10:12:55 -07:00
Danny Canter 4c28821fef LinuxContainer: Move memory clamping to VZ code (#630)
The memory limit (clamp to system ram) is a VZ limitation so it's weird
that we had that logic directly in LinuxContainer. Someone could make a
VZVirtualMachineInstance that doesn't have this limitation but we
inherit this logic because it's done before passing off the memory
amount to the VMM.
2026-04-01 20:17:14 -07:00
Danny Canter baccf3f44b Hash: Make package visibility/remove ifdef (#631)
These build fine on Linux, and I don't honestly know why we had
hashMountSource as public API..
2026-04-01 19:45:53 -07:00
Danny Canter a864456240 ArchiveWriter: Fix uaf in finishEncoding() (#622)
finishEncoding() called archive_free() and then passed the freed pointer
to wrap(), which would call archive_error_string() on it if the return
code was not ARCHIVE_OK. Fix by nil-ing the pointer before freeing and
throwing directly without attempting to read the (already freed) error
string.
2026-04-01 18:29:46 -07:00
Danny Canter 1f495bc5be ArchiveReader: Cleanup tempdirs/files (#623)
There was a couple spots we were leaving around tempdirs
2026-04-01 14:20:44 -07:00
Danny Canter 220042089b Remove LinuxContainer.setupIO (#627)
Dead code
2026-04-01 13:57:43 -07:00
Danny Canter aa6f2c5d6c ContainerizationExt4: Remove unneeded os guards (#626)
There was some platform (darwin) specific guards in this package that
didn't make sense.
2026-04-01 15:07:26 -04:00
Dmitry Kovba d46f6ec92f Fix a range subscript when reading an xattr header (#612)
Fixes a range subscript when reading an `xattr` header.
2026-04-01 09:06:39 -07:00
Dmitry Kovba c28d3f1ba9 Fix a hardlink cycle detection (#611)
Fixes a hardlink cycle detection.
2026-03-30 19:02:54 -07:00
Danny Canter c5c1500eac Remove some unneeded Foundation imports (#613) 2026-03-30 17:00:58 -07:00
Danny Canter 2bce72d57e vminitd: Log git info (#609)
Logs the git sha, tag (if we're on one), and build time.
2026-03-30 13:46:35 -07:00
Dmitry Kovba 15bbddcaeb Fix the xattr sort comparator (#605)
- Closes #603.
- Fixes the `xattr` sort comparator. For example, when `$0.index >
$1.index` and `$0.name.count < $1.name.count`.
2026-03-30 13:03:37 -07:00
sterner-13-macumbaandsterner-13-macumba 0aedf8f9d9 Fix inconsistent heading punctuation in CONTRIBUTING.md (#602)
- Small formatting fix - removed trailing period from
  the "I can't finish the contribution I started" heading
  to match the style of other headings in the same
  section.

Co-authored-by: sterner-13-macumba <259387217+sterner-13-macumba@users.noreply.github.com>
2026-03-30 11:55:45 -07:00
Danny Canter 6444b23f13 Netlink: Support glibc (#600)
- Closes #491.
2026-03-30 10:58:32 -07:00
Dmitry Kovba 72432f148c Add the vminitd version to the logs (#604)
Adds the vminitd version to the logs.

Switching to a local version of vminitd is non-trivial:

```
-                .define("CZ_VERSION", to: "\"\(scVersion)\""),
+                .define("CZ_VERSION", to: "\"latest\""),
```

Having an additional confirmation of the used version in the logs is
vital.
2026-03-30 10:15:00 -07:00
Dmitry KovbaandRonit Sabhaya bed3705dbb Remove a double-counted offset in large files (#597)
* Removes a double-counted offset in large files. 
* This is the same fix as was suggested previously in 
https://github.com/apple/containerization/pull/462.

Co-authored-by: Ronit Sabhaya <ronitsabhaya75@gmail.com>
2026-03-30 09:50:43 -07:00
Dmitry Kovba 2c286fd0de Remove the macos-sdk build target (#596)
Removes the `macos-sdk` build target.
2026-03-26 12:56:16 -07:00
Maxime Grenu 1951816427 fix(dns): validate nameserver addresses are valid IP addresses (#534)
## What

Add a `DNS.validate()` method that verifies all nameserver entries are
valid IPv4 or IPv6 addresses. The method is called from
`Vminitd.configureDNS()` before applying the configuration.

## Why

Closes #467. Currently, any arbitrary string can be passed as a
nameserver in `DNSConfiguration`, which silently results in an invalid
`/etc/resolv.conf` inside the container. Hostname strings like
`dns.example.com` would be written to resolv.conf but would not work as
nameservers.

## How

- Added `DNS.validate() throws` method in `DNSConfiguration.swift` that
iterates over all nameservers and attempts to parse each as either an
`IPv4Address` or `IPv6Address` (using the existing parsers in
`ContainerizationExtras`)
- Added `import ContainerizationExtras` to `DNSConfiguration.swift` (the
`Containerization` target already depends on `ContainerizationExtras`)
- Called `config.validate()` at the start of `Vminitd.configureDNS()` so
validation happens before any GRPC call

## Testing

Added 6 new unit tests in `DNSTests.swift`:
- ✅ Valid IPv4 nameservers accepted
- ✅ Valid IPv6 nameservers accepted  
- ✅ Mixed IPv4/IPv6 nameservers accepted
- ✅ Empty nameserver list accepted
- ❌ Hostname rejected
- ❌ Invalid address rejected

## Checklist

- [x] Tests added
- [x] No breaking changes to existing API (validate() is a new method,
existing init is unchanged)
- [x] Follows existing patterns (uses ContainerizationExtras IP address
types, ContainerizationError for errors)

Signed-off-by: Maxime Grenu <maxime.grenu@gmail.com>
2026-03-25 02:40:07 -07:00
Dmitry Kovba 59f0a046f2 Fix date and time bugs in EXT4 (#592)
- Fixes EXT4 timestamp encoding for pre-1970 dates
- Fixes EXT4 timestamp decoding for pre-1970 dates
- Fixes the creation date
- Fixes a `UInt32` overflow

Resolves the following failures in the added tests:
```
Swift/arm64e-apple-macos.swiftinterface:38198: Fatal error: Double value cannot be converted to UInt64 because the result would be less than UInt64.min
error: Process '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/libexec/swift/pm/swiftpm-testing-helper --test-bundle-path /Users/Dmitry/Apple/containerization/.build/arm64-apple-macosx/debug/containerizationPackageTests.xctest/Contents/MacOS/containerizationPackageTests --filter encodeNegativeTimestamp /Users/Dmitry/Apple/containerization/.build/arm64-apple-macosx/debug/containerizationPackageTests.xctest/Contents/MacOS/containerizationPackageTests --testing-library swift-testing' exited with unexpected signal code 5
```

```
✘ Test decodeNegativeTimestamp() recorded an issue at TestEXT4Format+Create.swift:100:6: Caught error: not a valid EXT4 superblock
✘ Test decodeNegativeTimestamp() failed after 0.003 seconds with 1 issue.
✘ Suite NegativeTimestampRoundtripTests failed after 0.004 seconds with 1 issue.
✘ Test run with 1 test in 1 suite failed after 0.004 seconds with 1 issue.
```
2026-03-25 02:25:19 -07:00
Dmitry Kovba 7da377974b Use the actual path to Swiftly on GitHub runners (#595)
Use the actual path to Swiftly on GitHub runners instead of a link.
2026-03-24 16:49:59 -07:00
Danny Canter 54b91c4e6f README: Add logo (#598)
We had the logo in the repo preview, but not in our readme.
2026-03-24 10:17:00 -07:00
Dmitry Kovba 2c79ff681f Use an explicit path to Swift from Swiftly (#594)
Prior to this change, `make vmintid` failed with `which swift` equals to
`/usr/bin/swift`:

>
/Users/Dmitry/Apple/containerization/vminitd/.build/checkouts/swift-protobuf/Sources/SwiftProtobuf/AnyMessageStorage.swift:16:8:
error: compiled module was created by an older version of the compiler;
rebuild 'Foundation' and try again:
/Users/Dmitry/Library/org.swift.swiftpm/swift-sdks/swift-6.3-DEVELOPMENT-SNAPSHOT-2026-02-27-a_static-linux-0.1.0.artifactbundle/swift-6.3-DEVELOPMENT-SNAPSHOT-2026-02-27-a_static-linux-0.1.0/swift-linux-musl/musl-1.2.5.sdk/aarch64/usr/lib/swift_static/linux-static/Foundation.swiftmodule/aarch64-swift-linux-musl.swiftmodule

With an explicit path to Swift from Swiftly, `make vminitd` works both
with `which swift` equals to `~/.swiftly/bin/swift` or `/usr/bin/swift`.
2026-03-23 16:38:48 -07:00
splint-disk-8i d1b5bdb166 Fix misleading echo in swift-fmt-check target (#585)
Small documentation and Makefile fixes:

- Makefile: swift-fmt-check echo says "Applying" but the target only
checks/lints — changed to "Checking code formatting compliance"
- README.md: "libraries surface" → "libraries' API surface"
- README.md: "light weight" → "lightweight" (consistent with rest of
doc)
- README.md: "for use a default" → missing comma, grammar fix
- CONTRIBUTING.md: "To clarify of what" → "To clarify what"
2026-03-23 12:05:57 -07:00
Yibo Zhuang a59ed89421 vmexec: create working directory if it doesn't exist (#591)
This seems like standard OCI runtime behavior, which is to create the
working directory if it doesn't exist.
2026-03-19 22:24:25 -07:00
Danny Canter d8fcd1e9ca Network: Move to standalone type (#584)
The network protocol and VMNetNetwork implementation currently are
housed on ContainerManager even though they are generally useful types
even outside of this easy to use helper type. This change moves them to
not be nested types anymore, as well as exposes a new param on
VMNetNetworks constructor so we can pass the type of network.
2026-03-19 11:33:46 -07:00
Aditya Ramani 420b915d8b Write archive contents in chunks (#589)
Fix a bug in ArchiveWriter where large files would only partly be
written into an archive.
This is done so by writing the data in chunks.

---------

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2026-03-18 13:06:28 -07:00
Michael Crosby 84b71f10ae Revert "Upgrade vminitd API to use grpc-swift-2. (#578)" (#588)
This reverts commit 7ffe6d2ed5.
2026-03-17 13:46:28 -07:00
Dmitry Kovba 8df7ce78d7 Enforce progress event value types (#579)
Enforces progress event value types.
2026-03-17 09:23:45 -07:00
Danny Canter a35b168888 LinuxContainer/LinuxPod: Add support for NoNewPrivileges (#581)
Basically just a direct mapping to the prctl/OCI spec field.
2026-03-14 11:23:22 -07:00
Danny Canter 55c2a0a961 Integration: Sysctl tests (#582) 2026-03-13 13:32:17 -07:00
J LoganandDanny Canter 7ffe6d2ed5 Upgrade vminitd API to use grpc-swift-2. (#578)
- No real notable API changes. The largest change code-wise is in
Vminitd. The connection loop is set up immediately in the new API by
calling runConnections() on the client, and this blocks until either the
task it's running on is cancelled or beginGracefulShutdown is called.
Because of this, either we'd have to modify our API to have
VirtualMachineAgent implementations call some run() method, or we just
put runConnections in an internal task on Vminitd. This change uses the
latter approach as it's simpler.
- Updated dependencies to pick up latest protobuf and grpc-swift-2
fixes.
- ClientBootstrap.withConnectedSocket(fd).wait() registers the vsock fd
with epoll/kqueue immediately. vminitd sends its HTTP/2 SETTINGS frame
right away upon accepting the connection, so those bytes can arrive on
the fd — and be read by NIO — before the gRPC pipeline is installed.
With a bare pipeline, NIO has nowhere to send the bytes and discards
them.
- Buffer until ClientConnectionHandler is in the pipeline so it can
process the SETTINGS frame and fire .ready, then schedule delivery of
the buffered data with assumeIsolatedUnsafeUnchecked().execute.
- To help produce more accurate merged logs, defines a
`StderrLogHandler` in the vminitd Application.swift that writes
timestamps to the boot log with millisecond precision and format
identical to that of the log files created using the `--log-root` arg on
`container`.
- Updates hawkeye to latest version (v6.5.1).

---------

Co-authored-by: Danny Canter <danny_canter@apple.com>
2026-03-13 12:26:09 -07:00
Manoj Mahapatra 735dad6e5f fix: incorrect API usage for symlink entry (#577)
### Summary

`rootfs` create writes proc/self/exe as a symlink, but currently passes
the previous regular file buffer to `ArchiveWriter.writeEntry`. This
change switches that symlink entry to nil, which matches archive writer
expectations.

### Test

Archive tests pass.
2026-03-13 04:24:47 -07:00
Dmitry Kovba 28f1c5a9b5 Apply sysctls from the OCI spec (#580)
Applies sysctls from the OCI spec.
2026-03-12 20:46:16 -07:00
Dmitry Kovba 622d102b8e Fix a potential filesystem corruption on virtio block devices (#576)
Enable the caching mode for virtio block devices to fix a potential
filesystem corruption. Also see
https://github.com/apple/container/pull/1041.
2026-03-12 20:17:30 -07:00
Aditya Ramani d3ff56e5dd Use libarchive provided archive open/write/close/free callback methods (#573)
ContainerizationArchive internally used a `FileArchiveWriterDelegate`
type that defined callback methods which were handed to
`archive_write_open2` from libarchive

```
int archive_write_open2(struct archive *, void *,
		     archive_open_callback *, archive_write_callback *,
		     archive_close_callback *, archive_free_callback *);
```

Turns out those methods were at the very least partly broken, when used
alongside gzip compression.

Utilities like gnutar and gunzip couldn't entirely process the archives
produced by them, leading to errors like
```
➜ gtar -tvzf rootfs.tar.gz
...
drwxr-xr-x 0/0               0 2026-03-07 11:24 sbin/
-rwxr-xr-x 0/0       122451504 2026-03-07 11:24 sbin/vminitd
-rwxr-xr-x 0/0       121138856 2026-03-07 11:24 sbin/vmexec
gzip: (stdin): trailing garbage ignored
..
gtar: Child returned status 2
gtar: Error is not recoverable: exiting now
```

libarchive provides alternate APIs, `archive_write_open_filename` and
`archive_write_open_fd` where these callbacks are defined within the
library.

Lets use those instead and let the library handle this / future edge
cases (in this particular case it was adding some padding at the end of
the gzipped compressed file)
2026-03-08 09:11:05 -07:00
Danny Canter 1be13d1d76 LinuxContainer: Support copying directories (#571)
Now that the static linux SDK we use has libarchive linked against it,
we can finally live our dream (/s) of supporting copying directories
in/out a little easier. This was.. kind of annoying. I think the very
simple route of writing archive to guest/host -> streaming over grpc is
simplest, but on the guest end we have a couple problems:

1. The VMs rootfs is read only today always, which is a good thing to me
and I don't want to change if we don't have to.
2. Writing the archive to the containers rootfs temporarily could work,
but it's a bit weird, and the user can make the containers rootfs
readonly which would screw that plan.
3. We could write it to /run or /tmp, but they're tmpfs and dealing with
the headache of the user possibly tarring an enormous dir is one I don't
want to care about.

So, that leaves us with the (truthfully better to me) approach of trying
to write the tar data directly to the host and skipping grpc which kinda
forces us to have a temp spot. Because of that, I made it such that we
pass a port number from host<->guest, and transfer the actual data
(either the single file or tarred dir contents) over the vsock port
instead. The stream is kinda clunky, but it just serves as a means to
exchange metadata and a "we're done" signifier.
2026-03-06 15:30:00 -08:00
Danny Canter 7064cbab40 vminitd: Bump Swift version to 6.3-snapshot (#570)
Closes #221

This contains (in the static linux sdk but the swift version and the sdk
must match) libarchive support and mimalloc! This also (unrelated to the
sdk bump it seems) raises the amount of retries we do when dialing
vminitd. It seems CI on rare occasions recently has timed out on some
tests. We could also explore just lowering the concurrency on the
integration suite.
2026-03-04 19:11:46 -08:00
J Logan eff935e35f Adds access group to keychain helper APIs. (#553)
- Will be used by the fix for apple/container#1253.
- We use a common keychain ID between the `container CLI and
`container-core-images`, but right now keychain entries created by the
CLI must be opted-in for `container-core-images`.
- Using an access group with a notarized application should give both
apps automatic access to the keychain.
2026-03-04 16:48:27 -08:00
Danny Canter 6f9ae02933 LinuxContainer/LinuxPod: Fix UDS proxy if target is symlink (#568)
Closes #256

If the target of the uds proxy goes through a symlink (/var/run) we had
the same bug we had with mounts previously where we'd follow this and if
the resolved path existed in the root of the VM we'd end up mounting
there. Fix this by plopping the sockets in a holding spot and then bind
mounting them in (which has the correct resolution logic).
2026-03-03 10:41:28 -08:00
J Logan f1195fead5 GH actions: do not interpolate template variables in run blocks. (#567) 2026-03-02 12:04:36 -08:00