Skip to content

Harden CUPS printer discovery - #8627

Merged
ryanrhughes merged 5 commits into
omacom:quattrofrom
mdisec:security/harden-cups-browsed
Aug 29, 2026
Merged

ryanrhughes merged 5 commits into
omacom:quattrofrom
mdisec:security/harden-cups-browsed

Conversation

@mdisec

@mdisec mdisec commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Issue summary

Omarchy’s default printing configuration exposed two passwordless paths from ordinary desktop-user code execution to host root.

The provisioned desktop user belongs to wheel, while CUPS configured wheel as a SystemGroup and enabled PeerCred. Consequently, any process running in the user’s desktop session could silently perform privileged CUPS administration without a password or Polkit prompt.

Two root-escalation paths were demonstrated:

  1. The preinstalled CUPS-PDF backend ran as root and accepted a job-controlled post-processing command while trusting the submitter’s claimed username. A desktop process could create a CUPS-PDF
    queue, submit a job claiming to be root, and cause an arbitrary program to execute as UID 0.
  2. cups-browsed ran as root and stored predictable cache files under /var/cache/cups, which was writable by the account used for print filters. Passwordless CUPS administration allowed a command-bearing Foomatic queue to execute as that filter account, redirect a cups-browsed cache entry through a symlink, and cause the root daemon to write attacker-controlled metadata into a root-consumed configuration file.

These printing issues turn any desktop-user code execution into silent host-root compromise. They were also used as the privilege-escalation stage of the reported Aether one-click chain: a crafted Aether theme first obtained user-session code execution, after which the default CUPS configuration provided root access without sudo, a password, or an elevation prompt.

This PR addresses the CUPS side of that chain. It removes the vulnerable CUPS-PDF backend, eliminates passwordless CUPS administration for wheel, separates cups-browsed state from the print-filter account, and runs cups-browsed as a confined unprivileged service account.

Actions

Harden Omarchy’s CUPS printer discovery while retaining automatic driverless IPP/AirPrint printer support.

  • Remove cups-pdf and replace it with cups-pk-helper for authenticated interactive printer administration through Polkit.
  • Run cups-browsed as a locked, dedicated system user instead of root.
  • Give only the cups-browsed group noninteractive CUPS administration through PeerCred.
  • Remove wheel from CUPS SystemGroup, eliminating passwordless printer administration for every desktop process.
  • Isolate daemon state in /var/cache/cups-browsed with mode 0750.
  • Apply a focused systemd sandbox without granting CAP_NET_BIND_SERVICE.
  • Replace the unsupported CreateRemotePrinters directive with explicit driverless-only discovery policy.
  • Add an idempotent migration for existing installations.
  • Add focused shell tests and live acceptance coverage.

Discovery policy

CacheDir /var/cache/cups-browsed
CreateIPPPrinterQueues Driverless
CreateRemoteCUPSPrinterQueues No

This preserves modern driverless IPP/AirPrint discovery while preventing automatic queue creation for printers exported by legacy remote CUPS servers.

Service confinement

The service now runs with:

User=cups-browsed
Group=cups-browsed
CacheDirectory=cups-browsed
CacheDirectoryMode=0750
UMask=0027
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
RestrictSUIDSGID=yes

No ambient network capability is added.

Existing-system migration

The migration:

  1. Removes cups-pdf.
  2. Installs cups-pk-helper when CUPS is installed.
  3. Stops an active root-running cups-browsed before changing authorization.
  4. Creates the locked service account.
  5. Atomically removes wheel from SystemGroup, adds cups-browsed, and enables PeerCred.
  6. Reloads CUPS and restarts cups-browsed only if it was previously active.
  7. Uses a machine-wide completion marker so privileged work is not repeated for every user.

Custom CUPS system groups and inline comments are preserved. Symlinked privileged configuration files are refused.

Validation

  • Focused CUPS hardening tests pass.
  • Bash syntax checks and git diff --check pass.
  • Verified on an Omarchy VM with CUPS 2.4.19 and cups-browsed 2.1.1.
  • cups-browsed runs as UID/GID 961 with zero effective Linux capabilities.
  • Its cache is 0750 cups-browsed:cups-browsed.
  • The desktop user receives lpinfo: Forbidden without authentication.
  • A live driverless IPP printer was discovered and its implicit queue created in five seconds without CAP_NET_BIND_SERVICE.
  • The temporary queue disappeared after the printer advertisement stopped.
  • No warning-level cups-browsed journal entries were produced.

The broader shell suite includes unrelated host-dependent failures caused by unavailable dependencies such as Lua and the sibling omarchy-iso checkout; the new CUPS test passes. A fresh-ISO
acceptance run remains pending because that checkout is unavailable in this environment.

Attribution

Reported-By: Erik Hunstad (Bad Sector Labs)

Copilot AI balanced review requested due to automatic review settings August 27, 2026 16:51

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

Hardens CUPS printer discovery by removing passwordless desktop administration and confining cups-browsed.

Changes:

  • Replaces cups-pdf with Polkit-backed administration.
  • Runs cups-browsed as a dedicated, sandboxed account.
  • Adds migration and security-focused tests.

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 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
etc/cups/cups-browsed.conf Restricts discovery and isolates cache state.
etc/systemd/system/cups-browsed.service.d/10-omarchy.conf Sandboxes the discovery daemon.
etc/sysusers.d/omarchy-cups-browsed.conf Declares its dedicated system account.
install/config/all.sh Runs printing configuration during setup.
install/config/printing.sh Rewrites CUPS authorization settings.
install/omarchy-base.packages Replaces cups-pdf with cups-pk-helper.
migrations/1787815267.sh Migrates existing installations.
test/acceptance.d/system-test.sh Adds live printing-security validation.
test/shell.d/cups-hardening-test.sh Tests configuration and migration behavior.

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

Comment thread test/acceptance.d/system-test.sh Resolved
Comment thread install/config/printing.sh Resolved
Run cups-browsed as a locked service account with a dedicated cache and a focused systemd sandbox. Restrict automatic queues to driverless IPP printers, remove wheel from passwordless CUPS administration, replace cups-pdf with Polkit-backed setup, and migrate existing systems safely.

Reported-By: Erik Hunstad (Bad Sector Labs)

Co-Authored-By: Daybreak Blue <[email protected]>
@mdisec
mdisec force-pushed the security/harden-cups-browsed branch from 5648346 to 5c33688 Compare August 27, 2026 17:00
omabot and others added 3 commits August 27, 2026 19:47
…unning

The migration recomputed whether cups-browsed was active at the start of every run, after an earlier run may already have stopped it. A run interrupted between that stop and the completion marker left the service down, and the retry that followed read it as inactive, skipped the restart, and wrote the marker anyway: printer discovery stayed off until the next reboot with no migration left to bring it back. Keying the restart to whether the unit is enabled survives the interruption, and reports not-enabled for a unit the user masked or disabled, which restarting would fail on and abort the migration short of its marker.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Codex XHigh <[email protected]>
cupsd compares directive names with _cups_strcasecmp, so a hand-edited "systemgroup sys root wheel" is live configuration, but matching $1 against the canonical spelling skipped it and appended a second directive at the end of the file. parse_groups accumulates the groups of every SystemGroup directive it reads rather than replacing them, so both lines took effect and wheel kept the passwordless administration this is meant to remove, with the migration reporting success.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Codex XHigh <[email protected]>
The username prompt already refuses the service accounts a desktop user must not claim, cups and lp among them. A user who took cups-browsed would get a primary group of that name, and the CUPS authorization written here puts that group in SystemGroup, handing that desktop user the passwordless administration the rest of this change removes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Codex XHigh <[email protected]>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed by Claude Opus 5 in Claude Code, with an independent Codex XHigh second opinion. Three defects found and fixed; the commits are pushed to this branch. The change is sound and the premise holds — I pulled Arch's cups 2:2.4.19-1 from a mirror rather than trusting the description, and SystemGroup sys root wheel, PeerCred on, the 0666 socket and the 0770 root:cups cache are all really there, while the desktop user gets wheel and never sys. Removing wheel genuinely closes the path.

Pushed

521f1ae9 — the migration recomputed whether cups-browsed was active at the start of every run, after an earlier run may already have stopped it. A run interrupted between that stop and the completion marker left the service down, and the retry read it as inactive, skipped the restart, and wrote the marker anyway: discovery stayed off until the next reboot with no migration left to bring it back. The restart is now keyed to systemctl is-enabled, which survives the interruption and also leaves a masked or disabled unit alone — restarting a masked unit fails, and that would abort the migration short of its marker.

68fc0cf6 — cupsd compares directive names with _cups_strcasecmp (scheduler/conf.c:3772), so a hand-edited systemgroup sys root wheel is live configuration. Matching $1 against the canonical spelling skipped it and appended a second directive, and parse_groups (conf.c:2544-2564) accumulates the groups of every SystemGroup directive rather than replacing them — so both lines took effect, wheel kept passwordless administration, and the migration reported success. Now matched with tolower().

b07374f0 — install/provisioning/setup-form.sh already refuses the service account names a desktop user must not claim, cups and lp among them. A user who took cups-browsed would get a primary group of that name, which this change puts into SystemGroup, handing that user the administration the rest of the change removes. Added to the reserved list.

Each fix carries a regression test, and each was proven by reverting the fix and watching its own test fail.

What was checked

./test/all on a disposable VM, never on the review machine: 205 of 207 files pass. ascii-test.sh and branding-about-animation-test.sh fail identically on origin/quattro — I ran them there on the same VM to be sure — so they are not yours. Against the installed cups-browsed 2.1.1 I confirmed CacheDir, CreateIPPPrinterQueues Driverless and CreateRemoteCUPSPrinterQueues No are real and parse as you intend, that CreateRemotePrinters does not exist in the binary so the line you replaced was indeed a no-op, that CacheDir moves all three state files, and that cups-browsed makes no root assumption in its source. The acceptance additions in test/acceptance.d/ were read, not run.

Codex ran at xhigh but hung and never wrote its report, so I harvested its reasoning from its log; two of the three defects above started as its leads. Its independence is not guaranteed here — its log shows it reading the reviewing session's own scratch directory.

Left open, for a maintainer rather than for you

The systemd drop-in and the new cups-browsed.conf arrive with the omarchy-settings package, but the matching SystemGroup edit only when the migration runs, and omarchy update upgrades packages first. A reboot in between — an interrupted update, a direct pacman -Syu, a dismissed migration notification — starts cups-browsed unprivileged with no CUPS administration rights, so discovery creates no queues and says so only in the journal. The account itself is fine, since systemd-sysusers.service creates it at boot; it is the authorization that lags. Closing that is a design call rather than a patch, so I left it alone.

Two smaller ones, also left: install/config/printing.sh no-ops silently when /etc/cups/cups-files.conf is absent, and the migration then records the machine as done; and the symlink refusal returns a bare false, which propagates into omarchy-migrate under set -euo pipefail and would wedge that migration and every later one at every login. Failing closed on a security-critical file is right — the wedge is the part worth a second look.

Dropping cups-pdf and setting CreateRemoteCUPSPrinterQueues No are user-visible behaviour changes rather than defects: a print-to-PDF queue, and auto-discovery of printers shared by another CUPS server. Those are the maintainer's to sign off.

Waiting on the maintainer for the upgrade-ordering question above; nothing is blocked on you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants