Commit Graph
272 Commits
Author SHA1 Message Date
Danny Canter 3de29338e1 Integration: Add stdio ingest test (#385)
Add a test to ingest 200MiB of data across stdout/stderr. Useful to test
how fast we can ingest stdio. The timing will always be a tad off as it
times between start and wait returning, and there's quite a lot in the
way.. but it's a good enough metric.
2025-11-07 11:08:01 -08:00
Danny Canter 619354ef74 Don't ignore possible errors from dup(2) (#382)
Everytime we grab a vsock connection we dup the conn and close the
original, otherwise we'd need to carry around the vsock connection type
everywhere as it closes the fd in its destructor. We weren't checking
the return value of dup however, so if it did fail we'd have a useless
filehandle with an fd of -1.
2025-11-06 15:48:02 -08:00
Raj 52ed5b542c Revert "Add filesystem notification (FSNotify) support" (#384)
Reverts apple/containerization#294. This is causing the CI to break
because of concurrency issues with tests. Let's revert while we
investigate.
2025-11-05 15:06:24 -08:00
Raj 80e84a9ce1 Add filesystem notification (FSNotify) support (#294)
Addresses apple/container#141, where containers don't receive filesystem
events on mounted volumes, preventing incremental rebuilds and other
file-watching features. This PR implements the guest-side components for
FSNotify. Host-side implementation in the container repo will complete
the pipeline.

Summary:
- Add gRPC protocol definitions for filesystem event notifications
- Implement guest-side event handler that generates Linux inotify events
- Add CLI testing tool (`cctl fsnotify`) and integration test
infrastructure
2025-11-05 12:20:15 -08:00
Danny Canter bec1008f4d VsockConnectionStream: Conform to AsyncSequence (#380)
I didn't like how we expose the asyncstream via a public connections
field. We should have the type conform to AsyncSequence and then hide
the underlying stream. This also stops listening on the stdio ports
after we get the initial connection.
2025-11-03 14:09:56 -08:00
Danny Canter 8b39713a00 EXT4: Optimize unpack (#378)
Optimize unpack a little by trying to reduce allocations in the hot
path. Today for every file we read the entire file into memory and then
pass the data blob to the ext4 writer to eventually be written to the
sparse file. Before being written to the sparse file the data is copied
*again* to a temp buffer before finally hitting write(2) in FileHandle.

This change moves things around such that we can pass an optional buffer
to the ext4 create() (so we can reuse a buffer for file writes), as well
as stops reading entire files into memory by passing the archive entry
itself (wrapped in a ReaderStream object albeit) down to the writer.

Testing with unpacking every platform for
`docker.io/jenkins/jenkins:lts` on an M1 Max:

Old Avg (5 runs): 7.43s
New Avg (5 runs): 5.31s
2025-11-03 12:22:38 -08:00
Danny Canter f3d998975c LinuxContainer: Add new constructor (#377)
Add a constructor that allows just passing in a configuration without
doing the closure dance.
2025-10-31 14:27:39 -07:00
Dmitry Kovba 0177505c58 Improvements to Protobuf.Makefile (#356)
Improvements to `Protobuf.Makefile`. Also see
https://github.com/apple/container/pull/821.
2025-10-30 11:13:31 -07:00
Danny Canter 07325561f3 Integration: Add UDS test (#374) 2025-10-30 01:00:54 -07:00
Danny Canter df8b97a9f7 Chore: Use guestVsockPorts (#373)
This was a funny oversight. We have two port spaces, one for listening
sockets on the host, and one for vsock proxies in the guest, but only
the host "allocator" was being used. This didn't really matter as the
ports in the guest would still be unique, but would still be good to
fix.
2025-10-29 16:44:28 -07:00
Dmitry Kovba 8682365800 Make pid an optional (#372)
Makes `pid` an optional to avoid killing the process with pid 0.
2025-10-29 16:31:06 -07:00
Dmitry Kovba 5696732315 Improvements to the logs (#371)
Improvements to the logs.
2025-10-29 15:39:17 -07:00
Dmitry Kovba aa591a4801 Improvements to Makefile (#370)
Improvement to `Makefile`. Also see
https://github.com/apple/container/pull/822.
2025-10-29 15:38:49 -07:00
Mark Baseggio d7814e4421 Make Index.mediaType optional to comply with OCI spec (#368)
The `mediaType` field in the `Index` struct was defined as a required
field, but according to the [OCI Image Index
Specification](https://github.com/opencontainers/image-spec/blob/main/image-index.md),
this field is optional.

This caused failures when loading OCI archives where the `index.json`
omits the top-level `mediaType` field, which is valid per the spec.
Tools like skopeo can generate such archives.

## Error before fix
```
keyNotFound(CodingKeys(stringValue: "mediaType", intValue: nil))
```

## Changes
- Changed `Index.mediaType` from `String` to `String?`
- Updated initializer to accept optional `mediaType` parameter
- Added comment documenting that field is optional per OCI spec

## Testing
Verified that OCI archives without a top-level `mediaType` field in
`index.json` now load successfully.

Fixes https://github.com/apple/container/issues/330
2025-10-29 01:46:16 -07:00
Danny Canter cc66529b59 VirtualMachineManager: Take in EventLoopGroup directly (#367) 2025-10-28 02:24:53 -07:00
Danny Canter 02fa190aeb Always close agent connections (#365) 2025-10-27 21:19:48 -07:00
Danny Canter eb1b8741b5 LinuxContainer/Pod: Remove pause/resume (#366) 2025-10-27 17:33:49 -07:00
Danny Canter 939108b27a VZVirtualMachineInstance: Move some extensions around (#364)
Move the implemention of VirtualMachineInstance to a standalone
extension and all the other helper methods outside of this.
2025-10-27 09:28:25 -07:00
Danny Canter 1b10836c41 VZVirtualMachineInstance: Remove sandbox references (#363)
This type used to be named Sandbox iirc. Remove these references now
that this is no longer the case.
2025-10-27 09:26:05 -07:00
Dmitry Kovba 9623b4b6d3 Position nested types and initializers on top (#355)
Position nested types and constructors on top in the parent types.
2025-10-27 09:22:47 -07:00
Dmitry Kovba a829fdcdfd Improve log and error messages (#352)
Improved log and error messages.
2025-10-27 09:21:54 -07:00
J Logan 3897e578c3 Use exact permissions for socket mount into guest. (#362)
- Closes #361.
2025-10-25 22:19:06 -07:00
Kathryn Baldauf 1165faabd8 Use correct flag size in Mount for glibc (#360)
The mount flags are defined as `Int`s for musl but as `Int32`s for
glibc, despite the mount methods expecting `Int32` for both. This was
leading to build errors when building with glibc like:

```
 |         "async": .init(true, MS_SYNCHRONOUS),
 |                              `- error: cannot convert value of type 'Int' to expected type 'Int32'
```

This PR allows for different Int sizes based on if we're building for
glibc or not to avoid this build error.

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-10-24 17:32:35 -07:00
Kathryn Baldauf 41eda106e3 Only load epoll file if we can import musl (#359)
This class does not work for glibc due to missing flags and methods.
This PR removes the ability to load the `Epoll` class when using glibc
for now.

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-10-24 16:48:25 -07:00
Kathryn Baldauf a27fefbb59 Add custom decoder inits for various oci types that use omitempty (#347)
Many fields on the various OCI types use "omitempty" for encoding and
decoding the json representation in golang. This PR adds custom json
decoder functions to allow for behavior similar to "omitempty".

---------

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-10-24 15:05:40 -07:00
Danny Canter 0297605ef8 Bump ctr-example to 0.12.0 (#357)
It takes a pinned dependency on cz and was quite a bit behind.
2025-10-24 14:48:39 -07:00
Danny Canter f697215e54 LinuxContainer: Stop all relays on create failure (#358)
If create fails we don't cleanup the relays we may have setup.
2025-10-24 14:48:26 -07:00
Dmitry Kovba c7af5b8222 Rename process to command (#354)
Rename `process` to `command` (assuming we agree on the change).
2025-10-24 13:27:56 -07:00
J Logan 6f7601e475 Handle EOF on one side of a UnixSocketRelay. (#323)
- Current implementation shuts down everything as soon as EOF is
detected on DispatchSourceRead for the relay. This is problematic for,
say an HTTP request where the client makes a request, and calls
`shutdown(fd, SHUT_WR)` to close the send side, but it expects to be
able to keep calling `recv()` to get the response.
- Changed cancel handlers so that the one that sees that both sources
have been cancelled then closes both the UDS and vsock fds.
- Updated vminitd VsockProxy to also do `shutdown(fd, SHUT_WR)` for read
hangup or EOF, and only close the underlying fds and unwire pollers on
full hangup, broken pipe, error, or when both sides half-close.
2025-10-24 13:13:13 -07:00
Dmitry Kovba 57ad7ad629 Throw an error in StandardIO.resize() (#350)
Throw an error in `StandardIO.resize()`, which is unsupported.
2025-10-24 12:52:58 -07:00
Dmitry Kovba 2dbba786d2 Use a protocol type instead of the concrete type (#353)
Use a protocol type instead of the concrete type.
2025-10-24 12:49:03 -07:00
Dmitry Kovba 9f5aaf247a Remove an unnecessary function (#351)
Remove an unnecessary function to simplify the code.
2025-10-24 11:48:55 -07:00
Dmitry Kovba a405d88e6d Throw an error for an empty array (#349)
Throw an error for an empty array before accessing the first element.
2025-10-24 11:19:25 -07:00
Danny Canter ca657f5009 Always provide a serial console (#346) 2025-10-23 14:32:56 -07:00
Danny Canter dc4284a149 Introduce new experimental LinuxPod type (#343)
Closes #319

Introduces a new type capable of running > 1 container in the guest. The
API mostly follows LinuxContainer, and each individual container can be
addressed via any of the methods that require you to pass the
containerID as the first param. Today there's no support for namespace
sharing, but that shouldn't be terrible to support.
2025-10-23 13:59:58 -07:00
Dmitry Kovba 3d7bb7bb5c Fix log metadata when starting a process (#345) 2025-10-23 13:28:21 -07:00
Danny Canter 22f7b6ac13 LinuxContainer: Add bootlog as configuration field (#344)
Closes #227

Previously, the bootlog was supplied once in the constructor to
VZVirtualMachineManager which meant that if you used this same manager
for multiple ctrs that all logs would end up going to the same file,
which becomes quite cumbersome to follow..

This change moves bootlog to be a container configuration param and also
moves it to be a VMConfiguration param, so it can be threaded through
from LinuxContainer -> vmm.create() and be truly container unique now.
The largest driver for this was the integration tests which today every
single test spits out logs to a singular file, making guest
investigations tricky to actually look into.

Result after:
```
➜  containerization git:(bootlog-per-ctr) ✗ ls -alh bin/bootlogs
total 1520
drwxr-xr-x@ 24 dcantah  staff   768B Oct 22 17:34 .
drwxr-xr-x@  8 dcantah  staff   256B Oct 22 17:34 ..
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-cat-mount.log
-rw-------@  1 dcantah  staff    22K Oct 22 17:34 test-cgroup-limits.log
-rw-------@  1 dcantah  staff   249K Oct 22 17:34 test-concurrent-processes-output-stress.log
-rw-------@  1 dcantah  staff   167K Oct 22 17:34 test-concurrent-processes.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-container-devconsole.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-container-hostname.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-container-hosts-file.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-container-manager.log
-rw-------@  1 dcantah  staff    22K Oct 22 17:34 test-container-reuse.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-container-statistics.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-container-stdin.log
-rw-------@  1 dcantah  staff     0B Oct 22 17:34 test-nested-virt.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-pause-resume-io.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-pause-resume-wait.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-pause-resume.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-process-custom-home-envvar.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-process-echo-hi.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-process-false.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-process-home-envvar.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-process-true.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-process-tty-envvar.log
-rw-------@  1 dcantah  staff    38K Oct 22 17:34 test-process-user.log
```
2025-10-23 03:27:24 -07:00
Danny Canter 1fa051bb69 VZVirtualMachineInstance: Move event loop shutdown slightly up (#342)
This and the work on it should likely be gone before vm shutdown.
2025-10-22 14:35:18 -04:00
Danny Canter 056a909081 VirtualMachineManager: Rework protocol (#341)
Today this protocols create method is just odd. Our only implementation
of it immediately casts to LinuxContainer, failing if it cannot do so. I
think what might make more sense is to pass in a configuration itself
with core parameters that we expect every vmm to be able to support, and
then in a specific implementation they can continue to cast this type to
a specific one to possibly extract some extra configuration values
(rosetta for VZ for example).

This rework will also make it simpler to support a Pod type, as the vm
setup is identical and simple.
2025-10-21 01:23:00 -07:00
Danny Canter 4f996d3509 LinuxContainer: Move Process type out of Configuration (#340)
As a first step to making a pod type, move the nested process
configuration out of LinuxContainer.Configuration.Process and into a
standalone LinuxProcessConfiguration type.
2025-10-20 10:52:48 -07:00
Melissa Kilby 26dcd68340 chore: restrict GitHub workflow permissions - future-proof (#339)
See https://github.com/swiftlang/github-workflows/issues/167 for
additional context

This approach aligns with security best practices, as detailed in the
following documentation:

-
https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions
-
https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#defining-access-for-the-github_token-scopes
-
https://openssf.org/blog/2024/08/12/mitigating-attack-vectors-in-github-workflows/


The default GITHUB_TOKEN permissions are defined at the repository
level. This PR modifies the workflow-level overrides to conform to
OpenSSF best practices -> defense in depth.

Allow me to quote OpenSSF:

https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions

> The highest score is awarded when the permissions definitions in each
workflow's yaml file are set as read-only at the top level and the
required write permissions are declared at the run-level.”

> Remediation steps
> - Set top-level permissions as read-all or contents: read as described
in GitHub's documentation.
> - Set any required write permissions at the job-level. Only set the
permissions required for that job; do not set permissions: write-all at
the job level.


Compare to the LLVM project:

Top-level: contents read, e.g.
https://github.com/swiftlang/llvm-project/blob/next/.github/workflows/build-ci-container-windows.yml#L3-L4
-> this makes it future-proof

Job-level: Allow write permissions as needed, e.g.
https://github.com/swiftlang/llvm-project/blob/next/.github/workflows/build-ci-container-windows.yml#L53-L58

Signed-off-by: Melissa Kilby <mkilby@apple.com>
2025-10-17 15:00:03 -07:00
Kathryn Baldauf 09da9205c6 Make vmm create protocol async (#338)
The `vmm.create` call is already made within an async function. This PR
updates the protocol to allow other vmm implementations more flexibility
in `create`.

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-10-17 14:54:57 -07:00
Kathryn Baldauf a14fd26a24 Add fallback to use lstat to get file permissions in archive writer (#337)
Allow different path for getting file permissions in archive writer,
gated by OS check

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-10-16 16:04:00 -07:00
Kathryn Baldauf fa3c348bfe Add close method to IO writer protocol (#336)
Add close method to IO writer protocol and update testing BufferWriter
to conform to the protocol

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-10-16 14:23:39 -07:00
Kathryn Baldauf 61049408dc Make some image/mounting related functions public (#335)
Make some image/mounting related functions public for use outside of
this repo

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-10-16 14:03:23 -07:00
Kathryn Baldauf a0f860822a Allow runtime options for generic mounts (#334)
Make generic mounts more flexible by passing in runtime options and
making the init function public

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-10-16 11:52:45 -07:00
Danny Canter 21d0c799b8 Add runc process launch wrapper (#333)
Somewhat simple and missing events and some other bits I believe, but
it's a start. Maybe should use the async subprocess type as well instead
of our homegrown Command.
2025-10-16 14:24:25 -04:00
Danny Canter 8a34763e40 Socket: Add fd receiving (#330)
Via scm_rights. Useful for supporting spawning runc as an OCI runtime as
that's how the pty is passed to the client.
2025-10-14 15:59:56 -07:00
Danny Canter 91ef4009a3 Integration: Lower default concurrency (#331)
I only see a very small delta halving this (.6 seconds), and the default
will likely stress the CI machines a lot more. This change also swaps
the atomic increments to .relaxed, as there's no ordering required, just
need no torn writes.
2025-10-14 12:55:10 -07:00
Santosh Bhavani 87e8fd1673 Add configurable concurrent layer downloads (#311)
Adds `maxConcurrentDownloads` parameter to `ImageStore.pull()`.

Performance improvement: ~1.2-1.3x faster pulls for multi-layer images
with higher concurrency.

Signed-off-by: Santosh Bhavani <santosh.bhavani@live.com>
2025-10-13 22:29:12 -07:00