Commit Graph
183 Commits
Author SHA1 Message Date
Danny Canter df2425ef7f vminitd: Wait for execvpe to return to continue (#275)
Today, because we don't wait for execvpe to finish to continue onwards,
it's possible that if you did an exec quick enough after starting an
init process for a container, that you could join the init processes
namespaces before pivot_root has taken place which is quite fun. Let's
wait for exec to finish (or an error to occur) to prevent this.
2025-08-26 09:34:13 -07:00
Danny Canter 48e2f412b3 vminitd: Log spec for exec processes (#274)
We had a log for the initial oci runtime spec, but we don't log anything
for execed processes. This makes it hard to look into issues that may be
due to just a mistake in the spec and nothing wrong with the actual
logic of the program.
2025-08-25 12:26:35 -07:00
Danny Canter 53021bec36 Cgroup2Manager: Various adjustments (#270)
Systemd loves to move the root cgroups processes to one it created named
/init.scope and then write the root cgs subtree_control file. Because of
this we can't just add exec processes to the cg we made for the
container anymore as we'll get EBUSY. We should follow where the init
processes cg is actually at (/proc/pid/cgroup) and add it there.
2025-08-19 17:31:51 -07:00
Danny Canter 2f32e36a0d Cgroup2Manager: Fix error log mistake (#269)
I accidentally made the creation log error level. Additionally adds a
log to deletion of the cg.
2025-08-18 12:19:55 -04:00
Dmitry Kovba c3f5816353 Handle the same file name in the fetchBlob method (#258)
With the suggested change, when a file exists, we'll verify whether it
has the same content before skipping it.
2025-08-15 14:02:22 -04:00
Michael Crosby 54980872d9 add ability to export initfs as block (#268)
This refactors the rootfs command to produce an image and have the
ability to create an ext4 formatted block of the init filesystem
directly from the command.

closes #220

Signed-off-by: crosbymichael <michael_crosby@apple.com>
2025-08-15 00:12:14 -07:00
Michael Crosby e08b0d4fb4 add kernel support section to readme (#267)
closes #224

Signed-off-by: crosbymichael <michael_crosby@apple.com>
2025-08-14 15:15:43 -07:00
Danny Canter 531ccd6205 vminitd: Rename CgroupManager -> Cgroup2Manager (#266)
To be more explicit.
2025-08-13 20:16:03 -04:00
Danny Canter 79e07b43ce vminitd: Add init and execs to cgroup (#265)
We currently weren't doing any cgroup setup whatsoever. For the most
part this doesn't matter too much, however certain images that may fool
around with cgroups don't like this :). Lets do the bare minimum these
expect which is to at least have the process running in a nested cg and
not apart of the root cg.
2025-08-13 12:58:49 -04:00
Dmitry Kovba 50500276e2 Update allocations in Allocator (#264)
The `allocations` property in the nested `Allocator` structure wasn't
updated. This PR resolves the problem by using mutating methods and
keeping the original types as structs.
2025-08-13 12:50:23 -04:00
Danny Canter 985dac83e5 vminitd: Proper pty setup / mount /dev/console (#248) 2025-08-12 20:03:27 -04:00
Tim Sneath 5a1975a3bf Clarify macOS version support and minor style tweaks (#263)
Clarify that container is only supported on macOS 26, and remove
language that implies that it's also designed for macOS 15.

This change also includes a couple of minor textual changes to improve
readability.
2025-08-11 13:35:38 -07:00
Danny Canter 87541cbe65 Agent: Add and implement writeFile (#259)
This change adds in a new rpc that we probably should swap to for the
underlying implementation of a couple rpcs we currently have. This new
rpc simply writes to an existing or new file some data. This is useful
for guest (and container) setup for things like /etc/hosts,
/etc/resolv.conf, writing to one-off cgroup files and so on.

Currently I've just implemented subtree_control toggling for the root cg
in standardSetup with this new change, but in the future I'd like to
swap the implementations of our /etc/hosts and /etc/resolv.conf logic
with this.
2025-08-11 12:33:30 -04:00
Dmitry Kovba 7b00f39140 Close a handle inside a lock (#257)
Improves https://github.com/apple/containerization/pull/245. A potential
deadlock risk was not proven. This PR moves the closing operation inside
the lock to prevent leaking an unclosed handle in case of an error.
2025-08-11 12:26:31 -04:00
Danny Canter 259c841591 ContainerizationExtras: Timeout adjustments (#254)
Three things:

1. Timeout.run today didn't allow a throwing closure.
2. Add a new constructor for Timeout that takes in a Duration directly
so we can be more granular than seconds.
3. Add unit tests because we all love those :)
2025-08-07 14:34:45 -04:00
Danny Canter adf5bd1866 LinuxContainer: Support pause/resume (#217)
This allows pausing the (really VM) container and any processes running
inside.
2025-08-07 13:12:11 -04:00
Danny Canter 88aeffe4db Add /dev/rtc symlink (#252)
Closes #251

We use devtmpfs today so our pal /dev/rtc0 is there. It's typical to
have a /dev/rtc symlink to /dev/rtc0.
2025-08-07 13:09:57 -04:00
Dmitry Kovba 14482784db Ensure mutable properties aren't accessed outside their intended thread-safe usage patterns (#247)
This PR modifies the access level of certain mutable properties to
ensure their thread-safe usage. It doesn't address
https://github.com/apple/containerization/issues/246 at this time.
2025-08-06 18:44:27 -07:00
Dmitry Kovba 36a5cd505a Replace public computed properties with locks in setters (#242)
This PR replaces public computed properties with setters in the
`NATNetworkInterface` class with constants to avoid using locks in the
setters. A new instance of `NATNetworkInterface` should be created to
change these values.
2025-08-06 18:29:07 -07:00
Dmitry Kovba bfc34e0da4 Eliminate race windows in the Socket class (#245)
While individual accesses were properly mutex-protected, the logical
operations were not atomic, leading to a potential inconsistency in a
multi-threaded environment. Multiple separate `state.withLock` calls
created race windows. With the proposed changes, single atomic
operations check and update the state together.
2025-08-06 18:22:54 -07:00
Danny Canter b2b2d41d77 Revert "Vminitd: Remove special cased /run mount (#233)" (#253)
This reverts commit 5f7dcd2a16. Rosetta is
setup at /run because the guest rootfs is ro, and unfortunately this
happens prior to LinuxContainer getting to mount any of this. I'm not
super happy about this, but we can figure something out later.

Additionally this adds a rosetta flag to cctl so we can quickly
spotcheck things like this again.
2025-08-06 17:34:00 -07:00
Danny Canter 4d2f73d300 LinuxContainer: Allow reuse after being stopped (#240)
After the container is stopped it's a bit odd how we don't allow the
object to be restarted. If someone wanted to continuously rerun the same
container they'd need to make a new object every time even though all
guest state is blown away on stop() so it's a clean slate.

This change makes it so that you can create+start again after stop
(although create stands out like a sore thumb now as stop -> create is
just strange).
2025-08-06 09:24:07 -07:00
Eric Ernst 14239b02c3 ContainerizationOS: minor fixes (#241)
While reviewing test coverage, I noticed a couple of minor issues:
 - 0 is non-negative - allow for zero memory
 - we should likely use lstat instead of stat for file info
 - we should check for empty name parameter

---------

Signed-off-by: Eric Ernst <eric_ernst@apple.com>
2025-07-31 23:32:10 -07:00
Danny Canter ab37e574a0 ContainerManager: Make root/imagestore suppliable (#228)
We should be able to supply an ImageStore if the user wants a different
ContentStore, or a different path.
2025-07-29 15:41:54 -04:00
Dmitry Kovba d512fcb7cc Transition to actors (#225)
Due to the reduced use of the macro, we can now fully transition to
`Mutex`.
2025-07-29 08:10:48 -04:00
Dmitry Kovba 95978185fd Standardize property names in ReadStream (#213)
This PR only changes names of private properties to align them with the
naming standards.
2025-07-28 12:26:09 -04:00
Danny Canter 71a5765d7f LinuxContainer: Remove IOHandler (#235)
Is unused after the config rework.
2025-07-28 12:15:23 -04:00
Kathryn Baldauf 41c3e4a2c3 Update xcode developer dir to new regularly updated symlink (#234)
The Xcode installation on the runners is regularly updated to the latest
release. A symlink at /Applications/Xcode-latest.app points to the most
recent installation. We should not rely on a specific version path.

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-07-25 11:38:55 -07:00
Danny Canter 5f7dcd2a16 Vminitd: Remove special cased /run mount (#233)
Revisiting this, I'm not a huge fan of having /run be special cased for
some reason
2025-07-25 09:43:48 -07:00
Danny Canter 032dcee131 Chore: Simplify AttachedFilesystem constructor (#232)
The type copy is the exact same on any of the types, just move it
outside of the cases like we have for options and destination.
2025-07-24 16:40:32 -07:00
Danny Canter a5937a8b13 Misc. capitalization/comment adjustments (#231)
The VirtualMachineInstance comment is not entirely true. It just
represents a single VM.
2025-07-24 16:40:21 -07:00
Danny Canter a73541e393 Netlink: Change logging to trace level (#229)
There's 82KiB of logs on every container launch for netlink, that may be
a bit excessive 😄.
2025-07-24 11:36:53 -07:00
Danny Canter 6071a9fe1f LinuxContainer: Remove SendableProperty usage (#223)
The state updates because of the way the macro works weren't actually
being performed under the lock.
2025-07-22 15:41:29 -07:00
Michael Crosby 0a4ff1b737 Add ContainerManager (#200)
A ContainerManager is a type that handles more of the required resource
needed to create and run a container.

---------

Signed-off-by: crosbymichael <michael_crosby@apple.com>
2025-07-22 11:53:52 -07:00
Danny Canter 636099970e LinuxContainer/LinuxProcess: Rework supplying configuration (#219)
This is a fairly large reworking, but it gets rid of something that has
plagued this since release which is the properties needing to be locked
to be Sendable compliant. This was somewhat of a copout because we
mostly know there's not a great deal of ways to have misused the setup
today, but alas we'd need to either mark the type as `@unchecked` or
just find a different route for setting the configuration. This change:

Exposes the underlying Configuration type that today only housed things
that aren't on the OCI spec. I'd love to just expose the OCI spec, but
we don't (and possibly never will) support everything on the spec, so
exposing it to be freely modified would be a bit odd. Now everything
related to the container is configured on this type, and the same goes
for execs.
2025-07-22 12:14:57 -04:00
Danny Canter fcd198e968 ContainerizationOS: Speed up fd closes (#222)
Instead of looping through from minimum fd -> rlimit max, we can
close_range(2) or read /proc/self/fd on Linux, and read /dev/fd on
macOS.
2025-07-22 10:30:10 -04:00
Danny Canter 8b93a2083a LinuxContainer: Fix build break (#218)
Crummy rebase that didn't pickup the Mutex changes
2025-07-18 08:44:16 -07:00
Danny Canter c4b6b68ce7 LinuxContainer: Add /etc/hosts writing functionality (#207)
Closes #206 

Much like we have support for supplying DNS configurations and writing
out /etc/resolv.conf, this adds a way to write out /etc/hosts for a
given container.
2025-07-18 00:54:18 -07:00
Danny Canter 3cc638624f KeychainHelper: Simplify lookup (#214) 2025-07-17 09:37:59 -07:00
YR Chen 402339e248 Add a com.apple.containerization.index.indirect annotation to distinguish synthesized index (#198)
In general I believe it's clever to synthesize an index for
single-platform image manifest, but we still need a way to distinguish
it. Add a dedicated annotation is the slightest change I've come up
with, and it's also OCI compliant. With this change come in, we can work
around https://github.com/apple/container/issues/212 and imitate the
behavior of other runtime with `container`.

Note that since `cctl` is meant to be a dedicated tool for inspecting
the Containerization framework itself, I didn't apply the indirection
for it, and it will be as-is with the genuine storage.
2025-07-16 10:24:18 -07:00
Dmitry Kovba 41d41e4ffe Check for supported types in the @SendableProperty macro (#212)
- The `@SendableProperty` macro now checks for supported types to
prevent a misuse with unsupported types like structs, dictionaries, and
arrays
- The new `@SendablePropertyUnchecked` can be used with classes and
enums
2025-07-14 15:08:08 -07:00
Kathryn Baldauf ab559752b8 Handle keychain query errors in keychain helper lookup (#211)
This allows us to handle errors from lookup with only the keychain
helper error types which simplifies the logic

related https://github.com/apple/container/pull/331

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-07-14 11:40:30 -07:00
Dmitry Kovba 197e9b63a9 Use Mutex for thread-safe access to structs (#208)
Changes in this PR prevent a race caused by an implicit call to a
computed property getter when updating the property value.
2025-07-11 15:45:27 -07:00
Kathryn Baldauf 133e7804c8 Make KeychainQuery errors type public (#210)
There have been a few issues filed in container
[here](https://github.com/apple/container/issues/254) and
[here](https://github.com/apple/container/issues/321), where people are
unable to pull or push to registries despite a successful login to that
registry.

Making this enum public so that we can get the error in container and
handle it correctly.

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-07-11 15:45:17 -07:00
Danny Canter f254f48bfc LinuxContainer: Add ability to close stdin (#201)
This allows the user the ability to raise an EOF for the containers
stdin. Today there's no way to close stdin so something as simple as
"cat" and relying on EOF to move the process forward doesn't work
2025-07-08 18:38:04 -07:00
Raj ad219fecf1 Make MTU configurable for Netlink (#204)
Here we add the implementation to make MTU value configurable instead of
hardcoding in `linkSet`.
2025-07-08 15:54:57 -07:00
Michael Crosby d16893d7b9 guard arch around Rosetta API (#203)
While this only supports AS, xcode's default will build all arches, so
this presents a bit nicer default for Archiving an xcode application
that utilizes containerization.

Fixes #179

Signed-off-by: crosbymichael <michael_crosby@apple.com>
2025-07-08 11:55:27 -07:00
Ed Singleton 6dc5489bbe Handle spaces in current dir by quoting paths (#199)
Added "" around some paths so that spaces in directory names will work
2025-07-07 18:27:26 -07:00
Joseph Heck 28b97f2917 update SPI manifest to build on 6.2 only (#196)
adds configuration to SwiftPackageIndex manifest to request builds
happen explicitly on Swift 6.2 vs whatever the current default it
2025-07-04 11:12:19 -07:00
Dmitry Kovba 969703d9ad Replace NSLock with Mutex (#193)
This PR replaces `NSLock` with `Mutex`. Thanks @dcantah for the idea!
2025-07-03 16:11:38 -07:00