Commit Graph
173 Commits
Author SHA1 Message Date
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
Danny Canter 9775528495 Vminitd: Rework ManagedProcess.IO protocols (#194)
I think the way these types were structured made reasoning about them a
bit difficult. I don't think this fully solves the problem, but this
change aims to make things a bit simpler by hoisting a lot of the logic
for the IO relays to a new IOPair type thats goal is to simply take in a
reader and writer and handle their resource cleanup after a relay
finishes. Bundled in with this is also the buffer we'll use to copy
between them.

This change:

- Alters ManagedProcess.IO `start` to take in the process to alter
instead of this just being a side effect of the constructors.
- Gets rid of `close()` in favor of `CloseStdin`. The IO will get closed
when the relays finish, which will naturally happen if the process exits
or just closes its side of the pipes/pty. This makes it so that the one
special case (a client wants to signal no more input is coming) is still
sane.
- Move all relay logic and resource cleanup to a new IOPair type that
takes in protocols that are easily conformable by all of our various io
types ( Socket, Terminal, FileHandle).
2025-07-03 14:11:29 -07:00
Danny Canter d3ca580a6d ContainerizationOS: Alter Terminal.close() (#195)
Change to calling close on the underlying FileHandle as it already has
logic to set the fd to an invalid value and prevent double closes.
2025-07-03 10:44:01 -04:00
Dmitry Kovba 8573b80fac Use a State struct for mutable properties in Sendable types (#191)
This PR introduces a pattern of grouping mutable properties within the
`Sendable` types, encapsulated within a `State` struct. This approach
enables simultaneous updates to multiple properties and serves as a tool
against reentrancy issues.
2025-07-03 01:19:55 -07:00
Danny Canter 633205f171 Vminitd: Change some process log levels (#192)
The two starting and exiting logs I feel are important enough to get
promoted to info level.
2025-07-02 13:01:28 -04:00
Aditya Ramani b24b72a7e4 Reference image via sha for test (#190)
CI was failing since the test image we use had a tag re-pushed. Pinning
the test to reference the image version by its sha

---------

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-07-01 17:58:40 -07:00
Danny Canter 61b01cc1ee LCShim: Add CZ prefixes/pidfd wrappers (#189)
We should namespace these a bit, and we need pidfd for some upcoming
terminal work. This also just gets rid of syscall2 and replaces with a
pivot_root wrapper.
2025-07-01 02:16:17 -07:00
Aditya Ramani bdba5b5740 Create unpacker protocol + ext4 unpacker (#151)
Creates a new Unpacker protocol that defines a single method

```
func unpack(_ image: Image, for platform: Platform, at path: URL, progress: ProgressHandler?) async throws -> Mount
```

This change also removes the `unpack(...)` method from the Image type.

Before
```
let mount = try await image.unpack(for: platform, at: path)
```
After
```
let unpacker = EXT4Unpacker(blockSizeInBytes: 2.gib())
let mount = try await unpacker.unpack(image, for: platform, at: path)
```

---------

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-06-30 11:06:38 -07:00
Danny Canter 631676b855 Remove preconcurrency from Virtualization import (#184)
I don't believe we need this for anything here (maybe we once did).
2025-06-30 12:39:12 -04:00
Dmitry Kovba 382c73ae78 Use a consistent capitalization in a bug report template (#181) 2025-06-27 15:51:47 -07:00
J Logan 1a59de82b0 Makes interface gateway configuration optional. (#156)
Here we implement the mechanism for ensuring that `container` doesn't
set up two default routes on containers that connect to multiple
networks. We'll implement the policy in apple/container#243.
2025-06-27 15:16:15 -04:00