Skip to content

Docker multi-arch build with sudo support - #6736

Open
axelfontaine wants to merge 5 commits into
omacom:quattrofrom
axelfontaine:docker-multiarch-sudo
Open

axelfontaine wants to merge 5 commits into
omacom:quattrofrom
axelfontaine:docker-multiarch-sudo

Conversation

@axelfontaine

@axelfontaine axelfontaine commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

qemu-user-static-binfmt registers its QEMU interpreters with flags FP. Setuid binaries such as sudo in an emulated-architecture Docker container only keep their credentials under binfmt_misc emulation when the registration carries C, which implies O. This adds O and C to the package's own flags, so FP becomes FPOC/POCF and P (argv[0] preserved) is kept.

How

  • omarchy-apply-binfmt (hidden, root) rebuilds /etc/binfmt.d/qemu-*-static.conf from the package's registrations in /usr/lib/binfmt.d, adding O and C.
    • Each file it writes starts with a "managed" comment. Files without it belong to the administrator and are never changed or removed.
    • It removes managed overrides whose package registration is gone.
    • It restarts systemd-binfmt when it changed a file, or when the live flags in /proc/sys/fs/binfmt_misc still differ. It skips the restart when binfmt_misc isn't mounted, as in the installer's chroot; the overrides load at first boot.
    • --check exits 1 when anything would change, without changing it or needing root.
  • 30-omarchy-binfmt.hook runs it after any transaction that installs, upgrades or removes a qemu binfmt registration, so overrides follow interpreter/magic/mask changes and added or dropped architectures. It sorts after systemd's 25-systemd-binfmt.hook. Packaged by Install the omarchy binfmt pacman hook omarchy-pkgs#820.
  • System setup (install/config/binfmt.sh) calls it.
  • Migration runs omarchy-apply-binfmt --check || sudo omarchy-apply-binfmt, so only users with pending changes get a sudo prompt, and a failure stays pending.

Setting C is machine-wide: QEMU then runs a root-owned setuid foreign-architecture binary with root's credentials anywhere on the host, not only inside Docker.

Reproducer

FROM alpine:latest

RUN apk add --no-cache sudo && \
    adduser -D appuser && \
    echo "appuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

USER appuser

CMD ["sudo", "whoami"]
docker build --platform linux/arm64 -t sudo-test . && docker run --platform linux/arm64 --rm sudo-test
Live flags sudo whoami sh -c 'echo $0'
PF (package default) sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set…
POCF (after omarchy-apply-binfmt) root sh

Tests

test/shell.d/binfmt-multiarch-test.sh covers adding flags without dropping existing ones, idempotency and --check, following changed/added/dropped registrations, leaving administrator overrides alone, the restart conditions, and the migration only escalating when changes are pending. config-test.sh checks the PKGBUILD installs the hook.

Not yet exercised: the hook firing on a real qemu upgrade, since it only installs once the package ships it.

Merge order

Merge this first, then omacom/omarchy-pkgs#820 (see its notes on the release PKGBUILD's pinned tag).

Supersedes #6074 and targets quattro.

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings August 12, 2026 08:40
@axelfontaine axelfontaine changed the title Register QEMU binfmt interpreters with OCF so sudo works under emulation Docker multi-arch build with sudo support Aug 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds QEMU binfmt overrides to support sudo in cross-architecture Docker containers.

Changes:

  • Generates binfmt overrides with credential/open-binary flags.
  • Applies configuration during installation.
  • Migrates existing installations and reloads binfmt registrations.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
install/config/binfmt.sh Generates QEMU binfmt overrides.
install/config/all.sh Runs binfmt configuration during installation.
migrations/1786521494.sh Repairs existing installations and restarts binfmt.
Suppressed comments (1)

install/config/binfmt.sh:9

  • Replacing the entire suffix drops the package's existing P flag from its FP registrations. P preserves the emulated program's original argv[0]; removing it changes execution semantics for every QEMU-launched binary, beyond the intended credential fix. Preserve the package-supplied flags and add O/C instead, then make the migration's completion check accept the resulting flag set.
  sed -E 's/:[A-Za-z]*$/:OCF/' "$conf" >"/etc/binfmt.d/$(basename "$conf")"

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread migrations/1786521494.sh Resolved
Comment thread install/config/binfmt.sh Resolved
Copilot AI review requested due to automatic review settings August 12, 2026 14:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Suppressed comments (1)

test/shell.d/binfmt-multiarch-test.sh:34

  • These expectations encode the unintended removal of the source registration's P flag. Assert an output that adds O and C while retaining F and P, so the test catches regressions in the package's argv0-preservation behavior.
grep -qFx ':qemu-aarch64:M::magic:mask:/usr/bin/qemu-aarch64-static:OCF' "$dest_dir/qemu-aarch64-static.conf" ||
  fail "binfmt config overrides aarch64 flags with OCF"
grep -qFx ':qemu-arm:M::magic:mask:/usr/bin/qemu-arm-static:OCF' "$dest_dir/qemu-arm-static.conf" ||
  fail "binfmt config overrides arm flags with OCF"

Comment thread install/config/binfmt.sh Resolved
Comment thread migrations/1786521494.sh Resolved
@omarchybot omarchybot added bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review labels Sep 27, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at a0730ad and run on a disposable Omarchy worker (x86_64, qemu-user-static-binfmt 11.1.1, Docker 29.7.2), with a second opinion from Codex Medium.

The bug is real, and this fixes it. With the package's FP flags, your reproducer prints sudo: effective uid is not 0. After this PR's migration it prints root. With the overrides removed again, it fails again. test/shell.d/binfmt-multiarch-test.sh passes 7/0 and ./test/cli is green at this head. Merged onto current quattro, the only ./test/cli failure is a vscode theme test that fails the same way on quattro alone.

Dropping P isn't needed for the fix, and it changes every emulated program. You said this was intended in reply to Copilot, but it's worth reconsidering, because the measurements show what it costs:

flags sudo in arm64 container sh -c 'echo $0' in arm64 container
FP (package) fails sh
OCF (this PR) root /bin/sh
POCF root sh

C is what makes sudo work. Without P, every emulated program receives its full path as argv[0] in place of the name it was called by, and a native container prints sh either way. Anything that dispatches on its invocation name, or a login shell started as -sh, behaves differently under emulation than it does natively. The migration's grep -q ':OCF$' (migrations/1786521494.sh:23) also treats a working POCF registration as stale and rewrites it to OCF. On the worker I set every registration to POCF by hand and ran the migration, and it stripped the P. Keeping the package's own flags and adding O and C would fix sudo without that change. If there is a case where P breaks something, please say what it is, so the reason can go in the comment.

Further points from Codex that I checked against the source:

  • install/config/binfmt.sh:13 copies whole registrations into /etc/binfmt.d, where each one shadows the package file of the same name. From then on, a qemu update that changes an interpreter path, magic or mask stays hidden behind the old copy. An architecture the package adds later keeps FP, because the migration only runs once. An architecture it removes leaves an orphan behind. The comment's promise that later architectures "stay covered" holds only at install time. A pacman hook on the qemu registrations would keep the overrides in step. That's a design choice for the maintainer, so I'm raising it rather than changing it.
  • The comment at install/config/binfmt.sh:3-5 credits O with making the interpreter work against a container's different rootfs. In the kernel's binfmt_misc documentation that is F. O passes the binary to the interpreter as an open file, and C already implies O.
  • If systemctl restart systemd-binfmt.service fails on the first run, the files already end in OCF, so the next run exits early without restarting and the migration is marked complete. A reboot applies the files anyway, so this is minor.

Setting C machine-wide is also a policy decision for the maintainer. QEMU then runs with the credentials of any root-owned setuid foreign-arch binary on the host, not only inside Docker.

Nothing was pushed to your branch, because keeping or dropping P is your call and the maintainer's, not a defect for me to override. This is labelled verified, and it now waits on you: either restore P, or give the reason for dropping it.

axelfontaine added a commit to axelfontaine/omarchy that referenced this pull request Oct 5, 2026
The config script replaced each registration's entire flags field with
the literal string OCF, silently dropping the package's P flag
(preserve-argv0) and any other flag a later package update might add.
That's a system-wide side effect -- this writes to /etc/binfmt.d/, not
something Docker-scoped -- beyond what fixing sudo under QEMU needs.
Only C is required for that; O lets the interpreter work against a
differing rootfs. Measured by @omarchybot on PR omacom#6736: FP alone fails
sudo, OCF fixes sudo but changes argv[0] system-wide, POCF fixes sudo
and keeps argv[0] correct.

Add O and C to whatever flags are already there instead, and update
the migration's completion check and the test's expectations to
match.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Critical impact] The PR appears safe to merge with the documented companion packaging change.

Summary

Adds omarchy-apply-binfmt to preserve existing QEMU flags while adding O and C for cross-architecture sudo.

  • Emulated Docker builds can run setuid tools with their credentials.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[System setup] --> D[omarchy-apply-binfmt]
  B[Migration check finds pending work] --> D
  C[QEMU package files change] --> D
  D --> E[Preserve administrator files]
  E --> F[Write or remove managed overrides]
  F --> G{Files or live flags differ?}
  G -->|Yes, binfmt_misc mounted| H[Restart systemd-binfmt]
  G -->|No| I[Leave service alone]
  G -->|Not mounted| J[Load overrides at boot]
Loading

Reviews (4) · Last reviewed commit: "Merge remote-tracking branch 'upstream/q..." · Reviewed by Greptile

Comment thread migrations/1786521494.sh Resolved
Comment thread migrations/1786521494.sh Resolved
Comment thread migrations/1786521494.sh Resolved
Comment thread install/config/binfmt.sh Resolved
@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 5, 2026
axelfontaine and others added 4 commits October 6, 2026 14:38
qemu-user-static-binfmt ships FP flags by default. Docker cross-arch
builds run emulated-architecture containers via QEMU, and setuid
binaries like sudo only keep their privilege escalation under
binfmt_misc emulation when the C (credentials) flag is set; O
(open-binary) lets the interpreter run against a container whose
rootfs differs from the host's. Override with OCF, derived from the
package's own registrations, and add a migration for existing installs.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…t aarch64

Add OMARCHY_BINFMT_SOURCE_DIR/OMARCHY_BINFMT_DIR overrides to the config
script and migration so both can be tested without touching /etc or
/usr/lib. Writing the test surfaced a real gap: the migration's
already-fixed check only grepped qemu-aarch64-static.conf, so a
partially-fixed install or an architecture qemu-user-static-binfmt adds
later would be missed. It now checks every qemu-*-static.conf the
package registers.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The config script replaced each registration's entire flags field with
the literal string OCF, silently dropping the package's P flag
(preserve-argv0) and any other flag a later package update might add.
That's a system-wide side effect -- this writes to /etc/binfmt.d/, not
something Docker-scoped -- beyond what fixing sudo under QEMU needs.
Only C is required for that; O lets the interpreter work against a
differing rootfs. Measured by @omarchybot on PR omacom#6736: FP alone fails
sudo, OCF fixes sudo but changes argv[0] system-wide, POCF fixes sudo
and keeps argv[0] correct.

Add O and C to whatever flags are already there instead, and update
the migration's completion check and the test's expectations to
match.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Replace the one-time copy into /etc/binfmt.d with omarchy-apply-binfmt, run
from a post-transaction hook on the qemu registrations, from system setup and
once from the migration. It follows changed, added and removed registrations,
only touches overrides it marked as managed, and restarts systemd-binfmt
whenever the running registrations still differ.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@axelfontaine

Copy link
Copy Markdown
Contributor Author

@greptile-apps Update your confidence score now that you have reviewed and agreed to the replies to your latest concerns.

@omarchybot omarchybot removed the bug Something isn't working label Oct 7, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Looked again at 8b1ec1f. The branch was rewritten since the review at a0730ad, so the verified label from that review came off when the head moved. Nothing was run on a worker at this head.

The classification is unsettled, so this waits on the maintainer. Two models classified this head separately. I read it as a bug fix: sudo in an emulated-architecture container fails under the package's FP flags, and that was reproduced on a worker at the previous head. Codex Medium read it as an enhancement: it changes binfmt behaviour for the whole machine on purpose, and it adds a new command (omarchy-apply-binfmt) and a pacman hook. Both readings hold up, so I have taken the bug label off rather than pick one. Once the maintainer decides what this is, it can be verified again at this head.

Earlier findings, read against this head but not run:

  • P is kept. bin/omarchy-apply-binfmt adds O and C to the package's own flags rather than replacing them.
  • The overrides now follow qemu updates. 30-omarchy-binfmt.hook reruns the script whenever a usr/lib/binfmt.d/qemu-*-static.conf changes, and the script removes managed overrides whose registration has gone. It sorts after 25-systemd-binfmt.hook, which is the name systemd ships on Arch.
  • The comment now credits F with handling a container's different rootfs.
  • A failed restart is no longer marked done. The script compares the live flags in /proc/sys/fs/binfmt_misc and restarts while they differ.

Two things are still for the maintainer. qemu-user-static-binfmt is in install/omarchy-base.packages, so C would apply to every Omarchy install, not just machines that run cross-arch Docker builds. And the hook only installs once omacom/omarchy-pkgs#820 ships it.

@osde8info

Copy link
Copy Markdown

@omarchybot consider switching from docker to podman

@omarchybot omarchybot added the enhancement New feature or request label Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants