Commit Graph
151 Commits
Author SHA1 Message Date
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
Luis David Garcia 885db858a5 Updated documentation link in README (#161)
## Description of Change

- I updated the documentation link in the README: [Documentation
Tab](https://github.com/apple/containerization?tab=readme-ov-file#documentation)
- The original link (`open http://localhost:8000/documentation/`) was
returning a **404 error**, as shown in the screenshot below.
- I fixed the issue by updating the link to: `open
http://127.0.0.1:8000/containerization/documentation/`, which works
correctly.

## Screenshot of the 404 Error and the Fix

Here’s the screenshot showing the error and the fix:

![404 Error Shown and 200
Fix](https://github.com/user-attachments/assets/4198d381-80de-4bca-a9f4-5455eee887f6)
2025-06-27 15:14:33 -04:00
Kathryn Baldauf 73097b795c Remove use of triage label (#180)
Tags on the repo should be a way to classify an item instead of denoting
workflow or status of the item. Remove the addition of the triage label
on bug and feature issues.

Related to https://github.com/apple/container/pull/262

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-06-27 14:08:01 -04:00
Danny Canter c7763c76cf vmexec: Set perms on stdio (#174)
We don't chown the container's stdio today.
2025-06-27 11:03:21 -04:00
Danny Canter 059ff4033f Makefile: Revert recent reworking (#177)
Reverts f9198d6ff7

We can explore better approaches to some of the targets, but for now
lets revert as it interferes with being able to build even if we have
local changes.
2025-06-26 19:31:46 -04:00
Aditya Ramani 638bb96e3f Better error message for image pull failures (#175)
Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-06-26 15:47:35 -07:00
Danny Canter e274a79123 Pin Swift 6.2 version and Linux SDK (#178)
Until 6.2 officially releases lets pin to a static version of the 6.2
snapshots. The Linux SDK and swift version must be aligned so this
should be less fickle than using `6.2-snapshot` as this is a friendly
identifier to choose the latest uploaded snapshot.
2025-06-26 14:20:26 -07:00
Elijah Wright 538ea78c33 run cleanupRelay only once in TerminalIO and StandardIO (#153) 2025-06-26 12:03:17 -04:00
Kathryn Baldauf 958a83b23b Switch to using issue types for bugs and features (#170)
Matches https://github.com/apple/container/pull/258

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-06-25 17:09:53 -07:00
Mike Drob f9198d6ff7 Provides explicit makefile targets for files (#167)
fixes #165

`init` depends on `vminitd/bin/vminitd`, `vminitd/bin/vmexec`, and
`bin/cctl`
`integration` depends on `bin/containerization-integration`
`bin/*` get generated via `make containerization`
2025-06-25 13:53:35 -07:00
Danny Canter 5559dd5a3d VZVirtualMachineInstance: Rework installRosetta flow (#169)
Because we were installing rosetta directly in the constructor for
VZVirtualMachineInstance, and we'd prefer to not have the constructor
async as it pollutes so much more, we had devised this gnarly callback
approach for the install that is a bit of an eyesore. This changes focus
is on moving the install flow to a method that is already async so we
can piggyback off of it, and removing the install logic from the config
-> VZConfig conversion. Now the install will occur during start() if
rosetta is not installed.
2025-06-25 14:11:23 -04:00
Danny Canter 2dfabeb4f9 Vminitd: Rework ManagedContainer (#168)
This gets rid of some design decisions that I was not fond of. This
changes the process start for both execs and the init process to happen
internally in the object, as well as makes it so that all exec
functionalities can happen on the container object itself. This allows
us to get rid of the `if request.id == containerID` branches in the
rpcs, and handle this entirely in the object itself using its internal
state.

The existing integration tests should stress this just fine I believe.
2025-06-25 14:07:31 -04:00
Dmitry Kovba 4bacf4c578 Remove the support for CURRENT_SDK (#164)
This PR removes the no longer needed support for `CURRENT_SDK`.
2025-06-25 12:30:06 -04:00
Dmitry Kovba b626d32a48 Fix compilation warnings (#163)
This PR fixes compilation warnings observed in:
```
swift -v --version
Apple Swift version 6.2-dev (LLVM 5fbc818cf26c90b, Swift 2e1897356956e43)
Target: arm64-apple-macosx26.0
/Users/Dmitry/Library/Developer/Toolchains/swift-6.2-DEVELOPMENT-SNAPSHOT-2025-06-17-a.xctoolchain/usr/bin/swift-frontend --version
Apple Swift version 6.2-dev (LLVM 5fbc818cf26c90b, Swift 2e1897356956e43)
Target: arm64-apple-macosx26.0
Build config: +assertions
```
2025-06-24 13:15:44 -07:00
Dmitry Kovba ebcaf74f42 Regenerate documentation on make docs (#160)
This PR allows using `make docs` without manually removing the existing
`_site` folder.
2025-06-24 13:09:20 -07:00
Dmitry Kovba f2a2bd7fa5 Add a link to the container repository (#157)
This PR adds a link to the container repository on top of the
`README.md`:

<img width="877" alt="Screenshot 2025-06-20 at 7 54 46 PM"
src="https://github.com/user-attachments/assets/3aff3c13-b0ed-4bf6-b2c8-bb4e8ad64355"
/>
2025-06-24 12:48:28 -07:00
Dmitry Kovba 910992e4d8 Update Static Linux SDK to the latest version (#162)
Currently, when a user runs `make cross-prep`, we install the latest
version of Swift. This requires installing the latest version of Static
Linux SDK, which we should update as a new version is released.
2025-06-24 12:44:42 -07:00
Dmitry Kovba 5da0125228 Redirect to the documentation from the homepage (#159)
This PR fixes the homepage at https://apple.github.io/containerization/
2025-06-23 10:19:16 -07:00
Satyam Singh 22f2efd8d1 fix: correct release condition in GitHub Actions and globalize enviro… (#127)
# Refactor GitHub Actions Workflow: Containerization Build
## 🛠 Summary
This PR introduces several important improvements and cleanups to the
build-containerization-template GitHub Actions workflow for better
maintainability, correctness, and readability.

### 🔧 Changes Made
#### 1.  Fix invalid conditional syntax
- **!= is not supported in expressions** with **if**: in GitHub Actions.

- Only logical operators like !, &&, || are valid.

#### 2.  Globalized environment variables
- Moved CURRENT_SDK and DEVELOPER_DIR to the job-level env: block to:

- Avoid redundancy across steps

- Make the workflow more maintainable

### 3.  Replaced `secrets.GITHUB_TOKEN` with `github.token`
- Prefer github.token for GitHub-provided auth token to improve clarity
and scoping.

@katiewasnothere
2025-06-23 09:26:50 -07:00
Dmitry Kovba a339606068 Fix the Swiftly bin path (#158)
This PR resolves the following error for new users:

```
% make cross-prep
Installing Swiftly...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 8549k  100 8549k    0     0  14.7M      0 --:--:-- --:--:-- --:--:-- 14.8M
installer: Package name is 
installer: Installing at base path /Users/Dmitry
installer: The install was successful.
Welcome to swiftly, the Swift toolchain manager for Linux and macOS!

Please read the following information carefully before proceeding with the installation. If you
wish to customize the steps performed during the installation process, refer to 'swiftly init -h'
for configuration options.

Swiftly installs files into the following locations:

/Users/Dmitry/.swiftly - Directory for configuration files
/Users/Dmitry/.swiftly/bin - Links to the binaries of the active toolchain
/Users/Dmitry/Library/Developer/Toolchains - Directory hosting installed toolchains

These locations can be changed by setting the environment variables
SWIFTLY_HOME_DIR, SWIFTLY_BIN_DIR, and SWIFTLY_TOOLCHAINS_DIR before running 'swiftly init' again.

For your convenience, swiftly will also attempt to modify your shell's profile file to make
installed items available in your environment upon login. This can be suppressed with the
'--no-modify-profile' option.

Proceed? (Y/n): 

Installing swiftly in /Users/Dmitry/.swiftly/bin/swiftly...
Error: The file “swiftly” couldn’t be opened because there is no such file.
make[1]: *** [swiftly] Error 1
make: *** [cross-prep] Error 2
```
2025-06-20 20:02:23 -07:00
Aditya Ramani 016c80fac0 Better parsing for www-authenticate headers (#155)
There was a bug where the `www-authenticate` header in the HTTP response
from a registry would not be parsed accurately.

Specifically, if the header value had more than one `<space>` character,
the entire header would be ignored. This PR fixes this bug and adds unit
test to detect this in the future.


Fixes https://github.com/apple/container/issues/240
And most likely fixes https://github.com/apple/container/issues/237

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-06-20 15:51:47 -07:00
Cornelius Roemer cad00de874 Fix typo in README (#54) 2025-06-18 17:31:58 -07:00
Danny Canter 2a96a0d447 Containerization: Always set TERM (#146)
Make sure we always set TERM for containers that ask for a tty. Right
now this handling was spread around in a bunch of spots, but I'd wager
setting it for the client on the host via LinuxContainer/Process is more
sane and already what we do for a lot of the other fields.
2025-06-18 17:00:00 -07:00