FS#56818 - [cups][cups-filters] wrong group ownership

Attached to Project: Arch Linux
Opened by Mantas Mikulėnas (grawity) - Friday, 22 December 2017, 06:35 GMT
Last edited by Andreas Radke (AndyRTR) - Wednesday, 01 December 2021, 15:27 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To Andreas Radke (AndyRTR)
Christian Hesse (eworm)
Sébastien Luttringer (seblu)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 2
Private No

Details

Currently the 'cups' and 'cups-filters' packages contain files owned by the "lp" group.

However, the "lp" group has been moved to sysusers.d a while ago, and the GID on my system (good old 7) clearly no longer matches the GID on the build system (automatically allocated).

As a result, my /etc/cups ends up with files owned by :systemd-coredump and such, just because they happen to have gid 999 etc. (Although the tarballs have both the username *and* the uid stored, pacman seems to always prefer the uid when extracting.)

$ bsdtar --numeric-owner -tvf cups-filters-1.18.0-1-x86_64.pkg.tar.xz | grep etc/cups/
drwxr-xr-x 0 0 999 0 Dec 21 19:37 etc/cups/
-rw-r--r-- 0 0 999 26002 Dec 21 19:37 etc/cups/cups-browsed.conf

$ bsdtar --numeric-owner -tvf cups-2.2.6-1-x86_64.pkg.tar.xz | grep etc/cups/
drwxr-xr-x 0 0 988 0 Nov 1 17:37 etc/cups/
-rw-r----- 0 0 988 6346 Nov 1 17:37 etc/cups/cupsd.conf
drwxr-xr-x 0 0 988 0 Nov 1 17:37 etc/cups/ppd/
-rw-r----- 0 0 988 142 Nov 1 17:37 etc/cups/snmp.conf.default

cups 2.2.6-1
cups-filters 1.18.0-1
This task depends upon

Closed by  Andreas Radke (AndyRTR)
Wednesday, 01 December 2021, 15:27 GMT
Reason for closing:  Fixed
Additional comments about closing:  2.4.0-3
Comment by Sébastien Luttringer (seblu) - Friday, 22 December 2017, 21:01 GMT
My understanding, is that cups is requiring a fixed gid, so the sysusers.d which define it should fix this gid. Currently, lp is defined in basics.conf (systemd package).
My suggestion is to either remove lp definition from basic and move it to cups package, or define our old gid of lp in basics.conf.

I'll add Christian to get his opinion on this.
Comment by loqs (loqs) - Friday, 22 December 2017, 21:42 GMT
You could add lp back to /etc/group so /usr/lib/sysusers.d/basic.conf could remain untouched
tmpfiles.d could fix the ownership permissions as another alternative
Comment by Sébastien Luttringer (seblu) - Friday, 22 December 2017, 23:38 GMT
The tmpfiles.d suggestion will lead to a competition between pacman and tmpfiles.d restoring the permission. We want to avoid that.

Adding back the lp to filesystem is an option, but will make the definition of lp on 2 packages (filesystem, systemd) instead of 1 (systemd).

I sent an email to systemd mailing list to get their lights.

Comment by loqs (loqs) - Saturday, 23 December 2017, 00:07 GMT
I would not have expected tmpfiles.d to compete with the file extraction stage of pacman as the hooks should not be triggered yet.
It would however lead to the pacman database storing incorrect ownership permissions.
Another solution would be pacman extracting based on names instead of ids but that is not an available option for now.
Comment by loqs (loqs) - Saturday, 23 December 2017, 02:56 GMT
$ grep lp -r /usr/lib/udev/rules.d/
Shows some udev rule matches for lp /usr/lib/udev/rules.d/99-systemd.rules and /usr/lib/udev/rules.d/50-udev-default.rules
So to avoid splitting those rules out leaving lp in /usr/lib/sysusers.d/basic.conf seems easier.

What actually breaks if --with-cups-group=lp \ was dropped from https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/cups#n69 ?
The group ownership as shipped is wrong but what does this actually stop cups from doing? The bug report does not indicate cups failing to operate in any way.
Comment by Andreas Radke (AndyRTR) - Saturday, 23 December 2017, 09:19 GMT
You can add users to the "lp" group to become printer admins and allow them to modify connected printers, print jobs and so on. You seem to loose this functionality here.

For more "man cupsd-conf", look for "group".
Comment by loqs (loqs) - Saturday, 23 December 2017, 11:26 GMT
From /etc/cups/cups-files.conf
# Default user and group for filters/backends/helper programs; this cannot be
# any user or group that resolves to ID 0 for security reasons...
#User daemon
#Group lp

# Administrator user group, used to match @SYSTEM in cupsd.conf policy rules...
# This cannot contain the Group value for security reasons...
SystemGroup sys root

Is that not the groups sys and root used for authentication and the group lp only used for calls to external executables?
Which would still be wrong if such an executable ever wanted to read one of cups config files.
Comment by loqs (loqs) - Saturday, 23 December 2017, 13:37 GMT
Overengineered solution add cups user/group to cups package with a set uid/gid. Add the cups user additionally to the lp group so it keeps access granted by udev on the lp group.
Adjust configure to --with-cups-user=cups --with-cups-group=cups.
Comment by Andreas Radke (AndyRTR) - Wednesday, 03 January 2018, 07:59 GMT
https://lists.freedesktop.org/archives/systemd-devel/2017-December/040042.html

@Seblu: What's your preferred solution? When are you going to implement it? filesystem 2017.12-2 wasn't touched for this bug.
Comment by Sébastien Luttringer (seblu) - Thursday, 04 January 2018, 18:07 GMT
@loqs: I would love too, have a way to tell pacman to untar based on strings and not id.

@Andreas:
Filesystem was not touched because the solution is not to find there; either in systemd or in cups.
I'm fine with both solution, although I have a preference for not patching systemd package to stick the lp gid because of cups.

If I understand correctly the «overengineered» solution proposed by loqs, it looks the easiest and cleanest:
- no systemd/filesystem update
- one sysusers files to create cups user/group and append cups to lp group (to manage direct attached printers)
- cups will not use the catch-all user «daemon» for its external program execution

I no objection, I'll move in that way soon.
Comment by Dave Reisner (falconindy) - Thursday, 04 January 2018, 18:17 GMT
>@loqs: I would love too, have a way to tell pacman to untar based on strings and not id.
agregory is working on this. libarchive supports a callback for resolving names to IDs at extraction time.
Comment by loqs (loqs) - Thursday, 04 January 2018, 20:56 GMT
cups-filter.patch:
add a sysusers.d entry for the user / group cups with ID 209 lowest available GID/UID pair according to https://wiki.archlinux.org/index.php/DeveloperWiki:UID_/_GID_Database
change ownership of /etc/cups from root:lp to root:cups
cups.patch:
replace --with-cups-user=daemon --with-cups-group=lp with --with-cups-user=cups --with-cups-group=cups
change ownership /etc/cups/ssl from root:lp to root:cups and the recursive chgrp of /etc/cups from lp to cups

One note on existing installs the directories /etc/cups /etc/cups/ssl and /etc/cups/ppd will not have their ownership changed as pacman does not change directory ownerships.
Edit:
The checksum for cups-filters.sysusers is a mismatch as I changed the ID from 200 to 209 in the patch but forgot to update the checksum.
Comment by Sébastien Luttringer (seblu) - Saturday, 06 January 2018, 15:11 GMT
Thanks for patches! Why are you defining cups user/group inside the cups-filter package instead of the cups?

I think we should add a post_install message to notice group change and suggest a chgrp run.
Do we agree that no user breakage are expected, as the cups is member of the lp group?

Is the maintainer ok with this?
Comment by Sébastien Luttringer (seblu) - Saturday, 06 January 2018, 15:14 GMT Comment by loqs (loqs) - Saturday, 06 January 2018, 18:04 GMT
I defined the user group inside cups-filters as that was a dependency of cups so when cups was being made I could use --with-cups-user=cups --with-cups-group=cups
otherwise it would need to be --with-cups-user=209 --with-cups-group=209. Agreed the intent is for no user breakage need testing to prove this is the case.
Comment by Andreas Radke (AndyRTR) - Sunday, 14 January 2018, 20:23 GMT
I've gone the latter way adding the sysuser in cups pkg and run a chgrp in cups post-upgrade:
if [[ $(vercmp 2.2.6-2 $2) = 1 ]]; then
chgrp -R 209 /etc/cups

This is what I get this way after a reboot:

andyrtr@laptop64:/home/andyrtr $ ls -lha /etc/cups/
insgesamt 156K
drwxr-xr-x 4 root nobody 4,0K 14. Jan 21:10 .
drwxr-xr-x 91 root root 12K 14. Jan 21:10 ..
-rw------- 1 root nobody 0 14. Jan 20:58 classes.conf
-rw-r--r-- 1 root cups 26K 22. Aug 17:32 cups-browsed.conf
-rw-r--r-- 1 root cups 15K 10. Jun 2016 cups-browsed.conf.bak_20160610
-rw-r--r-- 1 root cups 26K 14. Jan 21:06 cups-browsed.conf.pacnew
-rw-r----- 1 root nobody 2,9K 14. Jan 20:58 cups-files.conf
-rw-r----- 1 root cups 2,9K 14. Jan 20:58 cups-files.conf.default
-rw-r----- 1 root nobody 4,5K 20. Sep 2016 cupsd.conf
-rw-r----- 1 root cups 2,9K 30. Jul 2008 cupsd.conf.bak
-rw-r----- 1 root cups 6,2K 14. Jan 20:58 cupsd.conf.default
-rw-r----- 1 root cups 6,2K 14. Jan 20:58 cupsd.conf.pacnew
drwxr-xr-x 2 root nobody 4,0K 14. Jan 21:10 ppd
-rw------- 1 root nobody 130 14. Jan 21:10 printers.conf
-rw------- 1 root cups 130 14. Jan 20:08 printers.conf.O
-rw-r----- 1 root cups 142 14. Jan 20:58 snmp.conf
-rw-r----- 1 root cups 142 14. Jan 20:58 snmp.conf.default
drwx------ 2 root nobody 4,0K 27. Apr 2016 ssl
-rw-r----- 1 root lp 113 14. Jan 21:10 subscriptions.conf
-rw-r----- 1 root cups 113 14. Jan 20:08 subscriptions.conf.O

I wonder why the cups directory itself is owned by nobody and some other files inside also.
Comment by Andreas Radke (AndyRTR) - Thursday, 18 January 2018, 16:06 GMT
If there are no objections I'm going to push this to testing. I'm not sure if files owned by nobody cause any harm.
Comment by Sébastien Luttringer (seblu) - Thursday, 18 January 2018, 16:27 GMT
Could you push what you did in the svn trunk? I could review and test it.
Comment by Andreas Radke (AndyRTR) - Thursday, 18 January 2018, 16:32 GMT
I've uploded packages to testing. Ever cups server restart overwrites the persmission with group "nobody".
Comment by loqs (loqs) - Thursday, 18 January 2018, 18:40 GMT
Uncommenting #User 209 #Group 209 in /etc/cups/files.conf fixes that perhaps it is an issue with UID/GID 209 not being available at compile time which I missed because I had cups-filters create them.
Comment by Andreas Radke (AndyRTR) - Thursday, 18 January 2018, 18:56 GMT
Yes, that helps. Only file left with nobody permission is subscriptions.conf.
Comment by loqs (loqs) - Thursday, 18 January 2018, 19:25 GMT
chowning subsciptions.conf root:cups manually on this system then doing a cups restart it stays owned root:cups
Comment by Andreas Radke (AndyRTR) - Friday, 19 January 2018, 07:11 GMT
2.2.6-3 enables the new user/group by default and add some update msg. This seems to fully fix our permission issue. Please test it. I plan to move it soon to extra.
Comment by Bastian Beranek (totsilence) - Saturday, 20 January 2018, 10:36 GMT
I think the 2.2.6-3 update broke printing for me: Even though I made sure that all files in /etc/cups (including the folders) are owned by "root.cups", I cannot print (error "waiting for printer to become available") with my USB printer. Should I open a separate bug for that?
Comment by loqs (loqs) - Saturday, 20 January 2018, 11:55 GMT
Can you please follow https://wiki.archlinux.org/index.php/CUPS/Troubleshooting and attach the /var/log/cups/error_log for an attempted print with the new packages
Also the output of `id cups` please.
Comment by loqs (loqs) - Saturday, 20 January 2018, 12:24 GMT
@totsilence You noted you made sure all files were owned root:cups did you have to chown any of them or were they all owned root:cups?
Also did you update the config file /etc/cups/files.conf if needed?
Comment by Andreas Radke (AndyRTR) - Monday, 22 January 2018, 19:08 GMT
No response? Assuming this is not caused by this update I'm going to push it to the stable repos soon.
Comment by Bastian Beranek (totsilence) - Monday, 22 January 2018, 19:58 GMT
Sorry for not responding earlier. I think the problem is the permissions/ownership of

/dev/bus/usb/001/005

which I think is the device that cups needs to write to in order to print. It has owner "root.lp" and permissions 664.

crw-rw-r--+ 1 root lp 189, 4 Jan 22 20:49 /dev/bus/usb/001/005

So when cups is running with group cups it cannot write to this device. This is apparent already when trying to add the printer in the CUPS web interface. With cups in extra it finds the printer immediately and I can add it, with the one in testing I cannot. After running "sudo chown root.cups /dev/bus/usb/001/005" I can print again.

To answer your questions:

0) I think there is no error in /var/log/cups/error_log - it looks the same whether the print succeeds or not.
1) id cups prints: uid=209(cups) gid=209(cups) groups=209(cups),7(lp)
2) I didn't have to change ownership of any files in /etc/cups.
3) My /etc/cups/cups-files.conf is identical to /etc/cups/cups-files.conf.default.
Comment by Andreas Radke (AndyRTR) - Monday, 22 January 2018, 20:35 GMT
/usr/lib/sysusers.d/cups.conf
u cups 209 "cups helper user"
m cups lp

The cups user is part of lp group. Are you sure you have systemctl reload daemon and restart the cups server? Btw. is this a parallel printer?
Comment by Bastian Beranek (totsilence) - Monday, 22 January 2018, 22:26 GMT
Yes I agree, cups user is part of the lp group so something is not fully understood. All I can say is that chown root.cups for the /dev node fixes the problem. It also works if I change "Group 209" to "Group 7" in cups-files.conf and leave the /dev node as it is. Yes, I did 'systemctl daemon-reload' and 'systemctl restart org.cups.cupsd.service'. The issue also persists after a reboot. This is a USB printer (Canon Pixma MP520).
Comment by loqs (loqs) - Monday, 22 January 2018, 23:36 GMT
If you change Group 209 to Group cups any difference?
Comment by Bastian Beranek (totsilence) - Tuesday, 23 January 2018, 08:16 GMT
No difference.
Comment by Andreas Radke (AndyRTR) - Tuesday, 23 January 2018, 15:11 GMT
Can you please run cups with debug or even debug2 log level enabled. This might give a hint.
Comment by loqs (loqs) - Tuesday, 23 January 2018, 17:07 GMT
cups.debug2.3.txt Group 209 User 209 daemon/cups-deviced
cups.debug2.4.txt Group lp User daemon daemon/cups-deviced
cups.debug2.5.txt Group 209 User 209 cgi-bin/admin.cgi
For admin.cgi cups uses the expected uid for cups-deviced it uses uid 0 which should still work (is it hard coded to not use uid 0?)
Comment by loqs (loqs) - Tuesday, 23 January 2018, 18:48 GMT
Replacing /usr/lib/cups/backend/usb with a shell script chmodded 755 that contains

#!/bin/bash
id 2>&1 > /tmp/debug.txt
exec /usr/lib/cups/backend/usb.bin "$@"

# cat/tmp/debug.txt
uid=209(cups) gid=209(cups) groups=209(cups)

$ /usr/bin/id cups
uid=209(cups) gid=209(cups) groups=209(cups),7(lp)

So the usb driver as executed is only a member of the cups group
Comment by Andreas Radke (AndyRTR) - Tuesday, 23 January 2018, 19:01 GMT Comment by loqs (loqs) - Tuesday, 23 January 2018, 19:50 GMT Comment by Bastian Beranek (totsilence) - Tuesday, 23 January 2018, 19:54 GMT Comment by loqs (loqs) - Wednesday, 24 January 2018, 01:41 GMT
https://github.com/apple/cups/blob/9e44dfbe6cb61d44feb60a85b28abf9f5647c6e3/scheduler/util.c#L298
changed to the following sorry seems to work sorry no patch and code is dreadful but it seems to be targeting the right call now
if (!getuid() && user)
{
#include <pwd.h>
struct passwd * pwd = getpwuid(user);
if(initgroups(pwd->pw_name,pwd->pw_gid))
{
fprintf(stderr, "DEBUG: getpwuid failed\n");
exit(errno + 100);
}
setuid(user); /* Run as restricted user */
}
Comment by Andreas Radke (AndyRTR) - Wednesday, 24 January 2018, 06:30 GMT
loqs - can you please bring this upstream: https://github.com/apple/cups/issues.
Comment by loqs (loqs) - Wednesday, 24 January 2018, 09:21 GMT Comment by Sébastien Luttringer (seblu) - Thursday, 25 January 2018, 02:06 GMT
Great job loqs!

So far, my tests are good. It works without intervention on my setup after the first restart. Note that I use a remote printer via lpd.

However, two thoughts:
- We should use «--with-cups-user=cups» instead of «--with-cups-user=209» and «--with-cups-group=cups» instead of «--with-cups-group=209» in the configure. These values are used in «cups-files.conf» and are incorrect. Adding cups in makedepends would make this possible with the right uid/gid in the tarball.
- To not break setup with special user/group configuration, I would only changes group of files in /etc/cups when previous group was the default (lp) ; so use «find /etc/cups -group lp -exec chgrp cups {} \;» instead of «chgrp -R 209 /etc/cups».
Comment by loqs (loqs) - Friday, 26 January 2018, 12:09 GMT
Response from upstream https://github.com/apple/cups/issues/5236#issuecomment-360676407
Considering for a future CUPS release.
Comment by David McAdoo (geecroof) - Friday, 26 January 2018, 12:15 GMT
I wonder if it's better to go back to lp group and set it in /usr/lib/sysusers.d/arch.conf from filesystem package with fixed gid. Creating new uid/gid only for fixing breakages is quite hacky and not very scalable. It also uncovers subtle arch-specific upstream bugs like above. For existing users we can try fix this mess in post-install script.
Comment by Mantas Mikulėnas (grawity) - Friday, 26 January 2018, 12:55 GMT
geecroof: Actually most daemons have their own uid/gid nowadays (to isolate them from each other), so this is normal procedure. Cups might be the last one still using the generic "daemon" uid to this day.
Comment by David McAdoo (geecroof) - Friday, 26 January 2018, 14:48 GMT
Uh...I thought it already run unprivileged. Please ignore above then. Sorry.

@seblu
"To not break setup with special user/group configuration, I would only changes group of files in /etc/cups when previous group was the default (lp)"

This way we omit users with already broken config. In my case files in /etc/cups were owned by libvirt group.
Comment by Andreas Radke (AndyRTR) - Friday, 26 January 2018, 16:07 GMT
I'll apply loqs fix for now until upstream shows a better solution. A full chgrp is recommended for already broken systems.

It's still hacky and I'd prefer a fixed "lp" guid but this is not intentional by systemd upstream. I guess we are really forced to workaround our pacman limitations here.
Comment by David McAdoo (geecroof) - Friday, 26 January 2018, 17:07 GMT
@grawity I think cups will still run as root, those changes touch only some file permissions. From security perspective it's irrelevant if group ownership is lp,cups or whatever without special meaning.
Comment by loqs (loqs) - Friday, 26 January 2018, 20:12 GMT
Updated patch the change to cups-exec.c allows printing from local printers, in addition to the previous change to util.c that allowed locating local printers.
Have now tested printing successfully on this system from a local usb printer.
Comment by Andreas Radke (AndyRTR) - Saturday, 27 January 2018, 09:31 GMT
Pushed to testing cups 2.2.6-4 with updated patch.

@loqs - you may want to send it to the upstream bug as well.
Comment by Andreas Radke (AndyRTR) - Tuesday, 30 November 2021, 20:18 GMT
Our patch from https://github.com/apple/cups/issues/5236 needs an overhaul.
The 2.4.0 release introduces a major change here: https://github.com/OpenPrinting/cups/pull/274
The patch we use now breaks the build.

I'm going to upload 2.4.0 to testing with the patch disabled so assume the ownership breaking depending on your local setup.
Maybe someone is willing to fix our patch. @loqs?

But be aware the upcoming next major 3.0 release will drop all driver driven printing anyway. So I'm not sure if it's worth for now.
Comment by loqs (loqs) - Tuesday, 30 November 2021, 21:12 GMT
I think the breakage was caused by [1]. Fixed up patch attached.

Is there any solution for printers that require a driver with 3.0?

[1] https://github.com/OpenPrinting/cups/commit/1867a90df897b838c996252aec98bb0d14fd10b4
Comment by Andreas Radke (AndyRTR) - Tuesday, 30 November 2021, 21:51 GMT
Thanks for the quick fix.

For 3.0 and later check out upstream intention to either use driverless printers or use printer applications provided by the snap store. No further comment here. Feel free to bring this to our ml or better upstream.
See also https://openprinting.github.io/OpenPrinting-News-November-2021/
Comment by Jonas Witschel (diabonas) - Wednesday, 01 December 2021, 14:37 GMT
The updated guid.patch breaks the CUPS web frontend http://localhost:631/ on my system: every page apart from the front page (e.g. http://localhost:631/admin) throws a HTTP 500 server error (without any further useful debug information on the page) with cups 1:2.4.0-2. When removing the patch entirely, the frontend works as expected.
Comment by loqs (loqs) - Wednesday, 01 December 2021, 14:44 GMT
diabonas do you think it is worth trying to fix the patch?
Comment by Jonas Witschel (diabonas) - Wednesday, 01 December 2021, 15:12 GMT
I'm still reading through the comments, but my first impression is that the patch seems useful and worth keeping. It seems the only thing that is wrong with it is that it leaves a spurious "exit(errno + 100);" in scheduler/cups-exec.c and should look as attached to this comment instead. With the updated patch applied, the frontend works as expected.

Loading...