Skip to content

Commit 24c18df

Browse files
dhhcodex
andcommitted
Temporarily remove automatic printer discovery
cups-browsed is the daemon that watches the network and creates print queues by itself. Hardening it took a root daemon with a predictable cache down to a confined service account, but a daemon that turns anything advertising itself on the network into a print queue is a lot of exposure for a convenience, so it comes out of the default install while that is reworked. Only the discovery half: CUPS itself stays and printing keeps working, with each printer added by hand in Print Settings. The migration disables the unit before removing the package because that is the only order that works: pacman deletes the unit file but not the enable symlink, and once the unit is gone systemd can no longer resolve it by name to clean that up. It then removes the queues discovery generated. cups-browsed keeps those when it stops, since KeepGeneratedQueuesOnShutdown defaults to Yes, and they route through its own implicitclass backend, which goes with the package, so they cannot print again. Idle ones go. A queue with jobs on it is left alone and named: implicitclass only needs cups-browsed to choose a destination, so a job already past that point finishes on its own, and deleting the queue would abort it. One printer's job does not hold up the removal. A printer added by hand has an ipp:// or usb:// device and is left where it is. A queue whose jobs cannot be asked about is left alone rather than assumed idle, including one named so that lpstat would misread it -- "all" is its word for every destination, and a leading dash or a comma reads as another option or a list. Where CUPS does not answer at all, or a queue will not delete, discovery is still stopped but the package stays and no marker is written. omarchy-migrate records a migration for the user as soon as it exits zero, so that is where the machine stays until someone removes the package by hand, and the message says so rather than implying a retry. The queue list is read under LC_ALL=C because lpstat translates "device for", and captured rather than piped, so a cupsd it cannot reach is reported instead of reading like a machine with nothing to clean up. It removes with plain pacman -R rather than omarchy-pkg-drop, which passes -n and would discard /etc/cups/cups-browsed.conf instead of keeping it as a .pacsave. A removal meant to be temporary should not delete the machine's copy of its own configuration. Without -s either, so it only ever removes the package it names: sweeping newly unneeded dependencies is nothing today, but it is not a promise a rolling dependency graph can keep. Queue names come off the network, since cups-browsed names its queues after what the printer advertised. CUPS allows every printable character but space, tab, / and #, and lpstat and lpadmin take a destination as an option value, so a name with a leading dash or a comma is reported rather than passed to them and guessed at. Migration state is per user, so a machine-wide marker records the one removal. Without it, an account whose first migration run came after someone deliberately reinstalled discovery would quietly take it back out again. The install-time override for cups-browsed.conf now waits for cups-browsed rather than for CUPS. Guarding it on a file CUPS still ships would write a configuration file for a package nothing installed, and pacman would later land the package's own copy beside it as a .pacnew. The hardened configuration stays in the tree. omarchy-settings still ships the cups-browsed.conf override, the sysusers account and the service drop-in, so they are what discovery returns onto. Co-Authored-By: Codex XHigh <noreply@openai.com>
1 parent 0b3f1b7 commit 24c18df

9 files changed

Lines changed: 564 additions & 68 deletions

File tree

‎bin/omarchy-upgrade-to-quattro‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,6 @@ EOF
13641364
as_root systemctl disable docker.service >/dev/null 2>&1 || true
13651365

13661366
enable_system_service cups.service
1367-
enable_system_service cups-browsed.service
13681367
enable_system_service avahi-daemon.service
13691368
enable_system_service linux-modules-cleanup.service
13701369
enable_system_service docker.socket

‎install/config/enable-services.sh‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# Enable services only. Installs are followed by reboot, so don't start/reload
22
# daemons mid-install. UFW and hardware-gated services stay in their own scripts.
33
systemctl enable cups.service
4-
systemctl enable cups-browsed.service
54
systemctl enable avahi-daemon.service
65
systemctl enable linux-modules-cleanup.service
76
systemctl enable docker.socket
87
systemctl enable systemd-resolved.service
98
systemctl enable NetworkManager.service
10-
# Don't let network-online.target (pulled in by cups-browsed) hold up
11-
# graphical.target waiting for DHCP/Wi-Fi association. Nothing in the session
12-
# needs to block on the network. Mirrors the systemd-networkd-wait-online mask
13-
# in install/hardware/network.sh.
9+
# Don't let network-online.target hold up graphical.target waiting for
10+
# DHCP/Wi-Fi association. Nothing in the session needs to block on the network.
11+
# Mirrors the systemd-networkd-wait-online mask in install/hardware/network.sh.
1412
systemctl mask NetworkManager-wait-online.service
1513
systemctl enable power-profiles-daemon.service
1614
systemctl enable sddm.service

‎install/omarchy-base.packages‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ chromium
1717
clang
1818
cliamp
1919
cups
20-
cups-browsed
2120
cups-filters
2221
cups-pk-helper
2322
ddcutil

‎install/post-install/pacman.sh‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33
cp -f "$OMARCHY_PATH/default/pacman/pacman-${OMARCHY_MIRROR:-stable}.conf" /etc/pacman.conf
44
cp -f "$OMARCHY_PATH/default/pacman/mirrorlist-${OMARCHY_MIRROR:-stable}" /etc/pacman.d/mirrorlist
55

6-
# omarchy-settings skips these overrides until CUPS is actually present to
7-
# avoid pacman creating .pacnew files during ISO package installation.
8-
if [[ -f $OMARCHY_PATH/etc-overrides/cups-cups-browsed.conf && -f /etc/cups/cups-files.conf ]]; then
6+
# Each override waits for the package that owns the file it replaces, the way
7+
# omarchy-settings does, so pacman does not turn it into a .pacnew during ISO
8+
# package installation.
9+
if [[ -f $OMARCHY_PATH/etc-overrides/cups-cups-files.conf && -f /etc/cups/cups-files.conf ]]; then
10+
install -m 0640 -o root -g cups "$OMARCHY_PATH/etc-overrides/cups-cups-files.conf" /etc/cups/cups-files.conf
11+
rm -f /etc/cups/cups-files.conf.pacnew
12+
fi
13+
14+
# cups-browsed is no longer part of the default install, so this waits for a
15+
# machine that adds discovery back by hand. Writing the override before then
16+
# would leave a configuration file for a package nothing installed, and pacman
17+
# would later land the package's own copy beside it as a .pacnew.
18+
if [[ -f $OMARCHY_PATH/etc-overrides/cups-cups-browsed.conf && -f /etc/cups/cups-browsed.conf ]]; then
919
systemd-sysusers /etc/sysusers.d/omarchy-cups-browsed.conf
1020
cp -f "$OMARCHY_PATH/etc-overrides/cups-cups-browsed.conf" /etc/cups/cups-browsed.conf
11-
install -m 0640 -o root -g cups "$OMARCHY_PATH/etc-overrides/cups-cups-files.conf" /etc/cups/cups-files.conf
12-
rm -f /etc/cups/cups-browsed.conf.pacnew /etc/cups/cups-files.conf.pacnew
21+
rm -f /etc/cups/cups-browsed.conf.pacnew
1322
fi
1423

1524
source "$OMARCHY_INSTALL/hardware/pacman.sh"

‎manual/46-faq.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ The plain open source Chromium build doesn't ship with the OAuth credentials tha
4444

4545
### How do I add a printer?
4646

47-
Printing is set up and running out of the box, so a printer on your network is usually already discovered. Launch _Print Settings_ from the app launcher (`Super + Space`) to see what's there, add one by hand, or set the default. Printing to a PDF file works without any printer at all.
47+
Printing is set up and running out of the box, and you add each printer yourself from _Print Settings_ in the app launcher (`Super + Space`).
48+
49+
Choose _Add_, and give it a moment to look: a printer plugged in over USB, and most network printers, are found for you. If yours isn't in the list, pick _Network Printer > Internet Printing Protocol (ipp)_ and enter its address — the printer's own display or its web page will tell you what that is, usually something like `192.168.1.50` with a queue of `ipp/print`. _Forward_ then offers a driver, where a modern printer works best on the driverless _IPP Everywhere_ profile and an older one wants the model's own driver.
50+
51+
Right-click a printer and choose _Set as Default_ to pick which one your apps reach for first, and _Properties_ to set paper size, duplex and quality.
52+
53+
Automatic discovery, where printers on the network appear without being added, is temporarily switched off while it's reworked, which is why the first step above is yours rather than automatic. Printing to a PDF file works without any printer at all.
4854

4955
### How do I change where screenshots or screenrecordings are saved?
5056

‎migrations/1788009111.sh‎

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
echo "Temporarily remove automatic printer discovery"
2+
3+
# cups-browsed is the daemon that watches the network and creates print queues
4+
# by itself. Hardening it (1787815267) took a root daemon with a predictable
5+
# cache down to a confined service account, but a daemon that turns anything
6+
# advertising itself on the network into a print queue is a lot of exposure for
7+
# a convenience, so it comes out of the default install while that is reworked.
8+
# Temporarily, and only the discovery half: CUPS itself stays, printing keeps
9+
# working, and a printer is added by hand in Print Settings instead of
10+
# appearing on its own.
11+
machine_marker="${OMARCHY_CUPS_BROWSED_REMOVAL_MARKER:-/var/lib/omarchy/migrations/1788009111}"
12+
13+
[[ ! -e $machine_marker ]] || exit 0
14+
15+
# Nothing to do on a machine that never had it. Checked before any sudo so those
16+
# runs never prompt for a password, and before the marker so no machine pays a
17+
# password prompt for a removal it does not need.
18+
omarchy-pkg-present cups-browsed || exit 0
19+
20+
# Ask pacman whether the removal is possible before touching the service. If
21+
# something here depends on cups-browsed, the alternative is a machine whose
22+
# discovery daemon has been stopped and whose package removal then failed --
23+
# broken rather than removed.
24+
if ! pacman -R --print cups-browsed >/dev/null 2>&1; then
25+
echo " Something else on this machine still depends on cups-browsed, so it is staying installed."
26+
exit 0
27+
fi
28+
29+
# Disable before removing, and this is the only window in which it works.
30+
# pacman deletes the unit file but not the enable symlink systemd wrote under
31+
# /etc, and once the unit is gone `systemctl disable` refuses it by name and
32+
# leaves the symlink dangling with nothing left that can clean it. Stopping is
33+
# part of the same step: a daemon whose executable has been unlinked keeps
34+
# running until it is told not to. A masked or already-disabled unit reports
35+
# not-enabled and is left alone. Doing it before the queue list is read also
36+
# means the list cannot grow a new entry while it is being acted on.
37+
if systemctl is-enabled --quiet cups-browsed.service 2>/dev/null; then
38+
sudo systemctl disable --now cups-browsed.service
39+
elif systemctl is-active --quiet cups-browsed.service 2>/dev/null; then
40+
sudo systemctl stop cups-browsed.service
41+
fi
42+
43+
# cups-browsed keeps the queues it generated when it stops --
44+
# KeepGeneratedQueuesOnShutdown defaults to Yes and nothing here overrides it --
45+
# and those queues route through its own implicitclass backend, which goes with
46+
# the package, so none of them can print again. The idle ones are removed rather
47+
# than left in Print Settings looking like printers; the ones with jobs on them
48+
# are handled below. Only queues on that backend: a printer added by hand has an
49+
# ipp:// or usb:// device and is left alone.
50+
#
51+
# LC_ALL=C because lpstat translates "device for", and on a German or French
52+
# machine the untranslated pattern would match nothing and read exactly like a
53+
# machine that had no queues to clean up. Captured rather than piped so that
54+
# failing to reach cupsd is distinguishable from finding nothing. The name is
55+
# matched greedily because CUPS allows a colon in a queue name but never a
56+
# space, so the last ": implicitclass://" is the separator and an earlier colon
57+
# belongs to the name.
58+
if ! queue_report=$(LC_ALL=C lpstat -v 2>/dev/null); then
59+
echo " Could not ask CUPS which queues discovery had created."
60+
echo " Discovery is off, but cups-browsed stays installed; remove it by hand once CUPS answers."
61+
exit 0
62+
fi
63+
64+
generated_queues=$(printf '%s\n' "$queue_report" |
65+
sed -n 's|^device for \(.*\): implicitclass://.*|\1|p')
66+
67+
unremoved=0
68+
69+
while IFS= read -r queue; do
70+
[[ -n $queue ]] || continue
71+
72+
# A queue name is whatever the printer advertised, put through cups-browsed's
73+
# own sanitizer. `lpstat -o` takes its destination as an optional argument, so
74+
# a leading dash reads as the next option and a comma as a list separator, and
75+
# "all" is its word for every destination. The jobs on such a queue cannot be
76+
# asked about, so it is left alone and named. Never a reason to keep the
77+
# package, though: that would hand a printer that picked its own name a veto
78+
# over the removal.
79+
if [[ $queue == -* || $queue == *,* || $queue == "all" ]]; then
80+
echo " Cannot safely ask about jobs on the queue named '$queue'; remove it in Print Settings."
81+
continue
82+
fi
83+
84+
# Removing a queue aborts what is printing on it. The implicitclass backend
85+
# only needs cups-browsed to pick a destination, so a job already past that
86+
# point finishes on its own even though the daemon has stopped -- and a job
87+
# that has not is one this cannot route anyway. Either way the queue is left
88+
# for the person whose job it is, and named so they know to remove it.
89+
if job_report=$(LC_ALL=C lpstat -o "$queue" 2>/dev/null); then
90+
if [[ -n $job_report ]]; then
91+
echo " $queue still has jobs, so it is being left alone."
92+
echo " Once they finish or are cancelled, remove it in Print Settings; it cannot print again."
93+
continue
94+
fi
95+
else
96+
echo " Could not check for jobs on $queue, so it is being left alone."
97+
continue
98+
fi
99+
100+
if ! sudo lpadmin -x "$queue"; then
101+
echo " Could not remove the queue $queue."
102+
unremoved=1
103+
fi
104+
done <<<"$generated_queues"
105+
106+
# A queue that would not delete is a CUPS that is not answering as expected, so
107+
# the package stays rather than deleting the backend out from under it. Discovery
108+
# is stopped either way, which is the half that mattered. omarchy-migrate records
109+
# this migration for the user as soon as it exits zero, so this is where the
110+
# machine stays until someone removes the package by hand -- said plainly rather
111+
# than dressed up as a retry.
112+
if ((unremoved)); then
113+
echo " Leaving cups-browsed installed. Discovery is off; remove the package by hand once those queues are gone."
114+
exit 0
115+
fi
116+
117+
# Raw pacman rather than omarchy-pkg-drop, which passes -n: that discards the
118+
# files pacman has marked as backups instead of renaming them .pacsave, and
119+
# /etc/cups/cups-browsed.conf is one of them. A removal meant to be temporary
120+
# should leave the machine's copy of its own configuration behind. Plain -R
121+
# rather than -Rs, so this only ever removes the one package it names: -s also
122+
# sweeps dependencies that have become unneeded, which is nothing today but is
123+
# a promise the dependency graph of a rolling distribution cannot keep.
124+
# pacman's systemd hook reloads the system manager once the unit file goes.
125+
sudo pacman -R --noconfirm cups-browsed
126+
127+
# Migration state is per user, so every account on this machine runs every
128+
# migration. Without machine-wide state, an account whose first run comes after
129+
# someone deliberately reinstalled cups-browsed would quietly take it back out
130+
# again. This records that the machine has had its one removal.
131+
sudo install -Dm644 /dev/null "$machine_marker"

‎test/acceptance.d/system-test.sh‎

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ verify_services() {
4747
local unit
4848

4949
for unit in \
50-
avahi-daemon.service cups.service cups-browsed.service docker.socket \
50+
avahi-daemon.service cups.service docker.socket \
5151
NetworkManager.service power-profiles-daemon.service sddm.service \
5252
systemd-resolved.service ufw.service; do
5353
systemctl is-enabled --quiet "$unit" || fail "core system services are enabled" "$unit is not enabled"
@@ -65,69 +65,32 @@ verify_services() {
6565
}
6666

6767
verify_printing_security() {
68-
local cups_browsed_pid lpinfo_output printer_name printer_process printer_tmp
68+
local lpinfo_output
6969

7070
! pacman -Q cups-pdf >/dev/null 2>&1 || fail "CUPS-PDF is absent"
7171
pass "the root CUPS-PDF backend is not installed"
7272

73-
getent passwd cups-browsed >/dev/null || fail "the cups-browsed service account exists"
74-
[[ $(systemctl show -P User cups-browsed.service) == "cups-browsed" ]] ||
75-
fail "cups-browsed runs as its service account"
76-
[[ $(systemctl show -P Group cups-browsed.service) == "cups-browsed" ]] ||
77-
fail "cups-browsed runs as its service group"
78-
systemctl is-active --quiet cups-browsed.service || fail "cups-browsed is running"
79-
80-
cups_browsed_pid=$(systemctl show -P MainPID cups-browsed.service)
81-
[[ -r /proc/$cups_browsed_pid/status ]] || fail "cups-browsed has a readable process status"
82-
[[ $(awk '/^Uid:/{print $2}' "/proc/$cups_browsed_pid/status") != 0 ]] ||
83-
fail "cups-browsed does not run with root UID"
84-
[[ $(awk '/^CapEff:/{print $2}' "/proc/$cups_browsed_pid/status") == "0000000000000000" ]] ||
85-
fail "cups-browsed has no effective Linux capabilities"
86-
87-
[[ $(stat -c '%a %U:%G' /var/cache/cups-browsed) == "750 cups-browsed:cups-browsed" ]] ||
88-
fail "cups-browsed has an isolated cache" "$(stat -c '%a %U:%G' /var/cache/cups-browsed)"
89-
[[ " $(id -nG cups-browsed) " != *" cups "* ]] ||
90-
fail "cups-browsed is separate from the print-filter group"
73+
# Automatic discovery is temporarily out of the default install: a daemon that
74+
# turns anything advertising itself on the network into a print queue is more
75+
# exposure than the convenience is worth while it is reworked. CUPS itself
76+
# stays, so what a stock machine proves here is that printing runs and that
77+
# the desktop user still cannot administer it without authenticating.
78+
! pacman -Q cups-browsed >/dev/null 2>&1 || fail "automatic printer discovery is not installed"
79+
! systemctl is-enabled --quiet cups-browsed.service 2>/dev/null ||
80+
fail "no discovery service is enabled"
81+
! systemctl is-active --quiet cups-browsed.service 2>/dev/null ||
82+
fail "no discovery service is running"
83+
pass "automatic printer discovery is absent from a stock install"
84+
85+
systemctl is-active --quiet cups.service || fail "CUPS is running"
9186

9287
if lpinfo_output=$(LC_ALL=C timeout 10 lpinfo -v </dev/null 2>&1); then
9388
fail "the desktop user cannot administer CUPS without authentication"
9489
elif [[ $lpinfo_output != *"Forbidden"* ]]; then
9590
fail "CUPS explicitly denies unauthenticated desktop administration" "$lpinfo_output"
9691
fi
9792

98-
pass "CUPS discovery is isolated from root, filters, and passwordless desktop administration"
99-
100-
# A live driverless printer proves the non-root daemon can still discover and
101-
# create queues without the CAP_NET_BIND_SERVICE Ubuntu carries downstream.
102-
printer_name="OmarchyAcceptancePrinter"
103-
printer_tmp=$(mktemp -d)
104-
printf '#!/bin/bash\nexit 0\n' >"$printer_tmp/command"
105-
chmod 0700 "$printer_tmp/command"
106-
mkdir -m 0700 "$printer_tmp/spool"
107-
108-
ippeveprinter -p 18631 -d "$printer_tmp/spool" -c "$printer_tmp/command" "$printer_name" \
109-
>"$printer_tmp/ippeveprinter.log" 2>&1 &
110-
printer_process=$!
111-
112-
printing_test_cleanup() {
113-
kill "$printer_process" >/dev/null 2>&1 || true
114-
wait "$printer_process" >/dev/null 2>&1 || true
115-
rm -rf "$printer_tmp"
116-
}
117-
trap printing_test_cleanup EXIT
118-
119-
for _ in {1..30}; do
120-
lpstat -v "$printer_name" 2>/dev/null | grep -q "implicitclass://$printer_name/" && break
121-
sleep 1
122-
done
123-
124-
lpstat -v "$printer_name" 2>/dev/null | grep -q "implicitclass://$printer_name/" ||
125-
fail "non-root cups-browsed discovers a driverless IPP printer" "$(<"$printer_tmp/ippeveprinter.log")"
126-
127-
printing_test_cleanup
128-
trap - EXIT
129-
130-
pass "non-root cups-browsed still creates driverless IPP queues without capabilities"
93+
pass "CUPS runs with passwordless desktop administration still denied"
13194
}
13295

13396
verify_runtime_tools() {

0 commit comments

Comments
 (0)