Fail fast when a container machine image lacks /sbin/init - #2025
Open
Jobikinobi wants to merge 1 commit into
Open
Fail fast when a container machine image lacks /sbin/init#2025Jobikinobi wants to merge 1 commit into
Jobikinobi wants to merge 1 commit into
Conversation
The machine boot process hands off to the image's init system via `exec /sbin/init`. Creating a machine from an image without one (e.g. `ubuntu:latest` or most application images) succeeded, but the machine could never boot: the boot failure surfaced later as the misleading "cannot exec: container is not running", and the unbootable machine record was left behind (apple#1669, apple#1685, apple#1689). - Validate the cloned root filesystem in `MachinesService.create` with `EXT4Reader.exists("/sbin/init", followSymlinks: true)` and throw an actionable error naming the image and the requirement. The existing cleanup path deletes the partial bundle, so no machine record remains. - Add unit tests covering regular-file, symlink, missing, and dangling symlink cases in a new MachineAPIServiceTests target. - Add an integration test that `machine create` rejects an init-less image and leaves no machine behind. Fixes apple#2024. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AdcR7a6p56wrAihqNnxeWN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2024.
Problem
container machine createsucceeds for images that contain no/sbin/init(e.g.ubuntu:latestand most application images), but the resulting machine can never boot: the guest init script'sexec /sbin/initdies immediately, the user-visible error is the misleadinginvalidState: "cannot exec: container is not running"from the follow-up user-setup exec, and the permanently unbootable machine record remains incontainer machine ls. Several users have hit this and needed community help to diagnose it (#1669, #1685, #1689).Change
MachinesService.createnow validates the cloned root filesystem right aftersetMachineRootFs(cloning:), usingEXT4Reader.exists("/sbin/init", followSymlinks: true)fromContainerizationEXT4(already a dependency of the server target). On failure it throws an actionableinvalidArgumenterror naming the image and pointing at the machine image requirements. The check runs inside the existingdo/catch, so the partial bundle is deleted and no machine record is left behind./sbin/init -> /bin/busybox, e.g. plain alpine) still validate and boot as before — verified empirically. A dangling/sbin/initsymlink is rejected.New error:
Tests
MachineAPIServiceTestsunit-test target:validateMachineRootfsis exercised against small ext4 fixtures built withEXT4.Formatter— regular-file/sbin/init, symlink to an existing file, missing entirely, and dangling symlink. All pass locally (test-first: watched them fail before implementing).testCreateRejectsImageWithoutInit:machine createwithdocker.io/library/hello-world:latest(smallest init-less image) must fail, mention/sbin/init, and leave no machine behind. Written to match the surrounding suite patterns; ran the unit suite locally, relying on CI for the integration suite.ghcr.io/linuxcontainers/alpine:3.20, which ships/sbin/initand passes the new validation (verified against the real image).🤖 Generated with Claude Code
https://claude.ai/code/session_01AdcR7a6p56wrAihqNnxeWN