SDB:CUPS and SANE Firewall settings

Jump to: navigation, search

This article is rather old and was written with only traditional IPv4 networking in mind.

With nowadays IPv6 networking certain things are rather different so what was true for traditional IPv4 networking could be no longer true for nowadays IPv6 networking.


Situation

You like to use printers and scanners in your network and you like to have firewall protection against unwanted access.

Using printers and scanners via network is likely to happen in particular in home networks and small office networks. Therefore this article provides at first basic information regarding firewall and network security.

In particular when you use your computer both in trusted internal/private networks and in non-trusted external/public networks like the Internet (e.g. when you have a laptop which you use while traveling but also in trusted networks in the office and at home) and if you are not interested in basic information regarding firewall and network security, you may like to stay ignorant and just skip to the "make it just work" section at the end.

CUPS and SANE are systems for using and managing printers and scanners respectively.

CUPS is the acronym for Common Unix Printing System. For basic information how to set up CUPS see SDB:CUPS in a Nutshell and YaST_Printer and regarding CUPS server security see http://www.cups.org/documentation.php/security.html

SANE is the acronym for Scanner Access Now Easy. It provides standardized access to scanner hardware (e.g. a flatbed scanner) and a SANE network daemon that allows remote clients to access scanners which are connected to the local host. For basic information how to set up SANE see SDB:Configuring Scanners and regarding the SANE network daemon see http://www.sane-project.org/man/saned.8.html

For openSUSE Leap 42.3 (and prior versions) SuSEfirewall2 was the default firewall iptables-based front-end with rules generated according to the /etc/sysconfig/SuSEfirewall2 configuration file.

For openSUSE Leap 15.0 onwards, firewalld is the default firewall front-end (which still uses the Linux kernel's netfilter framework), and can be configured using the 'firewall-cmd' CLI interface or the graphical 'firewalld-config' utility.

In this article "the firewall" usually means the SuSEfirewall2, in particular the examples are about SuSEfirewall2 unless otherwise noted. Other firewall software (e.g. firewalld) is configured in a different way, and third party firewalls (e.g. a firewall in an Internet "router-box" device) may work quite differently.

Security: Make Things Not Just Work

The intended purpose of security measures is to make things not "just work" which means security causes some kind of annoyance for the user when things do not "just work" out of the box. If everything would "just work" by default, it would be totally insecure.

Things should only work for authorized users. To distinguish authorized users from others, a person who works with a computer must somehow authenticate to be an authorized user which usually happens via a password dialog. Alternatively physical location can be used to distinguish authorized users from others. For example a person who works directly locally at the computer can be automatically logged in as authorized user while in contrast a person who works from remote via network needs to authenticate via password dialog. Additionally the location in the network (i.e. the network environment) can be used to distinguish legitimate access via network from unwanted access. Basically the firewall allows access via network or rejects it by partitioning the network environment into so called "zones" that are used to distinguish legitimate access in one zone from unwanted access in another zone.

In this context security means that in particular access from remote via network must not "just work" by default. Any kind of desired access from remote via network must be explicitly allowed by an authorized user.

General Information About openSUSE Firewalls

For openSUSE Leap 42.3 (and prior), refer to the documentation of the SuSEfirewall2 package in the /usr/share/doc/packages/SuSEfirewall2/ directory and the comments in its configuration file /etc/sysconfig/SuSEfirewall2 and the online documentation about SuSEfirewall2. Additionally, refer to the "Masquerading and Firewalls" chapter in the openSUSE "Security" manual which is installed as a opensuse-manual package, for example /usr/share/doc/manual/opensuse-manual_en/manual/index.html in the opensuse-manual_en package.

For openSUSE Leap 15.0 onwards, the current documentation can be found online here.

Basic Information How the Firewall Works

The firewall is used to protect your host against unwanted access via network.

To access your host via network, at least one server process must run on your host. Each kind of server process is accessible via a particular network port. For example a web server process (e.g. the Apache web server) is accessible via the HTTP port 80 and the CUPS print server process is accessible via the IPP port 631 and the Avahi DNS-SD server process is accessible via the mDNS port 5353.

If no server process is running on your host, your host is not accessible via network so that you do not need the firewall. Nevertheless to be on the safe side you should not switch off the firewall because it will protect your host against unwanted access via network when an unintended server process was started by accident.

If one or more server processes are running on your host and you open their matching ports in the firewall, you remove any firewall protection from your host because you only need the firewall to protect running server processes against unwanted access via network.

On the other hand for server processes which should be accessible you must open the matching ports in the firewall. This means that there cannot be firewall protection for those server processes which should be accessible via network. Server processes which are accessible via network must provide sufficient security on their own. This is the reason why you must apply security updates for server processes which are accessible via network plus security updates for all what is related to such server processes (in particular system libraries that are used by your server processes and things like that).

If your host is connected only to a trusted internal network where a dedicated firewall machine protects the whole internal network, you may switch off the firewall on your host.

For example assume you have a server machine where a web server for your web site runs. Additionally the CUPS server process runs because there is a printer connected which you need once in a while to print something directly on the server machine.

Of course any user should be able to view your home page and whatever else you provide via your web site from any location in the Internet.

But on the other hand nothing else on your server machine should be accessible by arbitrary users from the Internet. In particular arbitrary users out there should not waste your paper and print on your printer.

Therefore you let the firewall pass any network traffic to HTTP port 80 (i.e. port 80 is open in the firewall) to allow arbitrary users to access the web server.

On the other hand you let the firewall prevent any network access for any other port (i.e. all other ports are closed in the firewall) so that in particular the CUPS server is not accessible via network and as a consequence your printer is protected against unwanted access via network.

Plain opening and closing ports in the firewall is sufficient for such kind of simple "all or nothing" configuration (allow any network access to the web server but none at all to the CUPS server).

Now assume you have again a server machine with a running web server and a running CUPS server but now the locally connected printer should be accessible by the users of a trusted internal network.

A trusted network means that you trust all users who can access this network. A user who can connect a computer to a network (e.g. a laptop where the user can work as "root") can send and receive any network traffic. Such a user can eavesdrop on the network and he can also fake any server machine in the network (except additional network switch hardware with an appropriate setup limits the user's network access).

Plain opening and closing ports in the firewall is no longer sufficient because if the IPP port for CUPS would be opened without further restrictions in the firewall, also arbitrary users out there from the Internet could waste your paper by printing on your printer.

The crucial point to apply further restrictions in the firewall is to distinguish whether or not network traffic happens in your trusted internal network.

Therefore your trusted internal network traffic must be separated from the other non-trusted network traffic. The best way to get different kind of network traffic separated is when different networks are used. The simplest and most secure solution to maintain separated networks is when separated network hardware is used.

Therefore the network hardware for your trusted internal network should be separated from the network hardware for the rest. In this case you have usually two network interface cards in your server machine, one where your trusted internal network is connected and the other one for the Internet connection. Consequently your network configuration has two network interfaces named for example "eth0" and "eth1".

Finally assume you have again a server machine with a network interface for the Internet connection and a second network interface for your trusted internal network. On the server machine a web-server and a CUPS server are running and the locally connected printer should be accessible only by the trusted users of your internal network.

In this case you would first and foremost assign the network interface for the Internet connection to the external (EXT) zone of the firewall and the network interface for the internal network to the internal (INT) zone of the firewall.

By default the firewall prevents any network access via the network interface which belongs to the external zone but it lets any network traffic pass via the network interface which belongs to the internal zone.

Access direction is crucial: The firewall prevents access of your host from the Internet but not the other way round. Therefore you can still access servers in the Internet from your host. In particular you can access all those web servers which run out there in the Internet with your browser program. For example you can access the web server which runs on www.opensuse.org to get the openSUSE home page from it or access a mail server web frontend to get your e-mail even when the firewall prevents access of your host from the Internet. Have in mind that this way all what you request from the Internet gets delivered to your system. The firewall does not protect you when you visit a malicious web server with your browser program which will get its malicious web pages, see in particular the Wikipedia article http://en.wikipedia.org/wiki/Drive-by_download about "Drive-by download" and the firewall does not protect you when you get for example malicious e-mails. Furthermore you can submit any data to all those servers which are accessible out there in the Internet. The firewall does not protect you when you submit private or confidential data to a wrong server, see in particular the Wikipedia article http://en.wikipedia.org/wiki/Phishing about "Phishing". If you cannot trust the network you must not type in your authentication credentials into arbitrary web interfaces which are "just accessible" for you. If you cannot trust the network you must not submit private or confidential data to arbitrary servers which are "just accessible" for you. If you cannot trust a network you must not release private or confidential data into the network - except you had set up in advance sufficient encryption and authentication to ensure that only your intended recipient can decode your data regardless that others in the network could have also received your encrypted data.

As a result you can still browse the Internet without restrictions but no server process on your server machine is accessible from the Internet while all your server processes are accessible from your internal network.

As a second step you open HTTP port 80 for the external zone in the firewall to allow arbitrary users to access your web server from any location in the Internet.

In the end the web server is accessible for anybody from anywhere (i.e. from the Internet and from the internal network) but the CUPS server is only accessible for users in the trusted internal network.

As another example assume you have a laptop which you use while travelling but also in trusted networks in the office and at home.

When the laptop has a single network interface card, trusted and non-trusted network traffic will mix up. Therefore you assign the network interface to the external firewall zone to protect the laptop against unwanted access via any network. Usually it does not make sense to have any server process running on the laptop because when the laptop is moved from one network to another network, the server process becomes suddenly unavailable in the one network but available in the other network which results an unpredictable behaviour for the users which use your server. But when no server process is running on the laptop, it is not accessible via network so that no firewall is needed. Nevertheless to be on the safe side you should not switch off the firewall because it will protect the laptop against unwanted access when whatever kind of server process was started by accident.

Assume you must run whatever server process on the laptop. Now you need to get trusted and non-trusted network traffic separated. You could use a wireless network interface card for all kind of untrusted network connections while travelling and an additional network interface card with a traditional wired network cable connection which you use only in the office and at home. You would assign the network interface for the wireless card (e.g. "wlan0") to the external firewall zone and the network interface for the office and at home (e.g. "eth0") to the internal firewall zone. This way it would be actually fool-proof to keep the laptop protected against unwanted access via network: As long as the connection to a trusted network exists (there is no firewall protection for the wired network because it belongs to the internal firewall zone) you cannot move the laptop into a non-trusted network environment. Before you can do this you must unplug the traditional wired network cable which instantly makes the laptop no longer accessible because the firewall protects the wireless network (because it belongs to the external firewall zone).

In this article a trusted network means that you trust all users who can access this network so that you can open particular ports for particular server processes in the firewall for this network.

From the firewall point of view there is no such thing as "partially trusted" for a particular network because one cannot "partially open" a port in the firewall. Either the port is open for a particular network or not. Accordingly either you trust all users to access a server process in a particular network or not.

Do not confuse what "trusted network" means here with a more general meaning of trust. You may have different networks where you let the users of each network access more or less sensitive server processes. For example a trusted internal network with access to an internal print server where also confidential documents are printed on an internal printer device versus a separated network for guests with access to a separated print server plus a separated printer device where guests can print their documents. In each of the two networks you trust all the users to access the same kind of server process but both networks do not have the same level of trust from a general point of view. The simplest and most secure solution to maintain security is also used here: Separated hardware. Separated networks with separated print sever machines plus separated printer devices. Why separated printer devices? You may Google for "network printer security risk" (and see below).

When Network Security is Likely to be Doomed

The basic idea to increase likelihood that your network security is doomed is to mix up trusted and non-trusted network traffic in one same network environment.

Save money and use the same network hardware for trusted and non-trusted network traffic and as a consequence pay with an increased likelihood that your network security is doomed and pay with an increased effort to maintain your network security.

Use one same "router-box" device for both your trusted internal network and the connection to the Internet. In such a case the router-box device is the crucial point (in particular the crucial point of possible failure) regarding network security. Usually such router-box devices provide their own built-in firewall (which may work totally different than the firewall used in openSUSE). Carefully read the documentation for your particular router-box how to set up its built-in firewall and which kind of protection it provides. Often it supports separation of your internal network from the Internet via private IPv4 addresses like 192.168.xxx.xxx together with network address translation (NAT), also known as network masquerading. If your router-box has a built-in firewall and supports private IPv4 addresses together with NAT (and if there is no security flaw in the router-box), your hosts are in a trusted internal IPv4 network where the router-box is a dedicated firewall machine which protects your internal network. With nowadays IPv6 networking things are rather different. Usually each host gets a public IPv6 address so the hosts are no longer separated from the Internet. In this case the router-box built-in firewall (hopefully) protects the hosts against unwanted access from the Internet. To be more on the safe side additionally a firewall should be running on each host.

Another way to increase likelihood that your network security is doomed is to use wireless communication for your trusted internal network traffic. In this case arbitrary strangers within a certain proximity out of your building have physical access to the electromagnetic waves which belong to the network traffic of your trusted network. Those folks out there do have a particular kind of physical access to your internal network. Therefore your network security totally depends on the trustworthiness of the security protocol which is used for network traffic encryption like the insufficient and deprecated WEP (Wired Equivalent Privacy) and its successors like WPA (Wi-Fi Protected Access) and finally WPA2 also known as RSN (Robust Secure Network). As of this writing (January 2010), only WPA2/RSN is considered secure, provided there is no WPS (Wi-Fi Protected Setup) functionality enabled which is insecure (Google for "wpa2 wps crack"). But WPA2 may not work with some older wireless network cards. Meanwhile (September 2012) WPA2 might be no longer secure because it seems possible to figure out its NT hash. Additionally there are other non-standard successors of WEP which could be insecure. Carefully read the documentation for your wireless network devices how to set up network traffic encryption for each of them and keep yourself continuously up to date regarding security issues or do not use wireless communication for your trusted internal network traffic.

Of course the best way to increase likelihood that your network security is doomed is to do all your network traffic via one same wireless router-box device. In this case carefully read the documentation for your particular wireless router-box how to set up its built-in firewall and its network traffic encryption protocol. Furthermore you need to keep yourself continuously up to date regarding security issues with your particular wireless router-box and what you could do against such issues.

On the other hand this kind of network environment is common nowadays in particular for home networks and small office networks where unfortunately often inexperienced users must maintain their network security on their own.

Assume you have a wireless router-box device which provides the Internet access for a workstation at home to which a printer is connected. Additionally you have a laptop and it should be possible to use the printer from the laptop. The workstation and the laptop have only a wireless network interface card to access the router-box.

Plain opening of a port for the external zone in the firewall destroys your network security because it removes any firewall protection for the service which is accessed via this port. When the CUPS print server process is the only server process which runs on the workstation, opening its IPP port 631 removes effectively any firewall protection from the workstation.

Instead inspect your network configuration to find out if different network interfaces are used for the Internet connection and for your internal network. For example there might be a network interface like "dsl0", "ppp0" or "ippp0" for the Internet connection and another network interface like "eth0" or "wlan0" for the internal network. In this case assign the network interface for the Internet connection to the external (EXT) zone of the firewall and the network interface for the internal network to the internal (INT) zone of the firewall.

In particular regarding "Small home network" see the SuSEfirewall2 configuration examples /usr/share/doc/packages/SuSEfirewall2/EXAMPLES or /usr/share/doc/packages/SuSEfirewall2/EXAMPLES.html

If one same network interface like "eth0" or "wlan0" is used for the Internet connection and for the internal network, assign the network interface to the external (EXT) zone and specify the IP address of the trusted internal network via FW_TRUSTED_NETS in the firewall configuration.

Regarding FW_TRUSTED_NETS see the SuSEfirewall2 configuration example "Laptop in private network but with additional public IP addresses" which applies also for any host (regardless if it is a laptop, a workstation or a server) when the same network interface is used for trusted and non-trusted network traffic.

Note that FW_TRUSTED_NETS does not allow incoming UDP broadcast packages. To accept also UDP broadcast packages specify the matching UDP port(s) where UDP broadcast packages should be accepted via FW_ALLOW_FW_BROADCAST_EXT in the firewall configuration.

But a FW_TRUSTED_NETS setup can be only a best effort attempt to get some kind of network security because IP addresses could be spoofed and in case of FW_ALLOW_FW_BROADCAST_EXT also malicious UDP broadcast package on the specified port(s) would be accepted from any possibly malicious server in the Internet.

In this case you should change your network hardware so that your trusted internal network traffic becomes well separated from the non-trusted network traffic.

Basic Network Security versus Phishing

The above described measures for basic network security do usually not help against phishing attacks, cf. "Phishing" at Wikipedia https://en.wikipedia.org/wiki/Phishing

The reason is that phishing attacks happen via intentionally open channels to receive data from "the outer world" like incoming e-mails or other messaging systems but also SMS on mobile phones and traditional phone calls.

Usually such channels are intentionally open by default for any sender because it is intended that one can receive e.g. e-mails, other messages, SMS, and phone calls from anyone from "the outer world" (e.g. so that an old friend who lives now in a foreign country could still contact one) but this means that one can also get arbitrary unwanted things from possibly malicious senders.

There are also intentionally open channels to receive computer specific data from remote. Usually those open channels are intended to receive announcements (broadcasts/multicasts) from remote servers about available services that those remote servers provide in the network. For example remote print queues are announced this way by remote print servers in the network traditionally via the so called "CUPS Browsing" and/or nowadays via DNS-SD, see "print job phishing" below.

What is Specific Regarding Firewall Setup for Printing

The CUPS server process (the cupsd) is accessible via TCP via the IPP port 631 to accept print jobs. Additionally the cupsd could be accessible by default via UDP via IPP port 631 to accept any incomming information about remote print queues from any remote host.

By default the cupsd should be only accessible via the internal interface of the local host (lo) to accept print jobs. Therefore printing is usually only possible directly from the local host but not from any remote host via network. If the cupsd runs in its default mode, you do not need the firewall to protect the cupsd (and your printer if it is locally connected) against unwanted access. Nevertheless to be on the safe side you should not switch off the firewall because it will protect your CUPS server against unwanted access via network when the cupsd is not running in its default mode. For example for very old CUPS versions or for uncommonly built cups RPM packages the cupsd might be even generally accessible unless the firewall provides protection.

To protect your CUPS server against unwanted access:

Do not open the CUPS IPP port 631 for the external zone in the firewall.

On the other hand the firewall lets by default any network traffic pass via network interfaces which belong to the internal zone. Therefore when the network interface for the internal network is assigned to the internal firewall zone, client hosts in the internal network can access the CUPS server process and submit print jobs. Independent of the firewall setup the CUPS server must additionally be configured to accept print jobs from those client hosts (which is not the default, see above).

To make your CUPS server accessible:

Assign the network interface which belongs to the internal network to the internal zone of the firewall.

It is crucial to limit access to CUPS to trusted users

Printing documents lets the user access and contol the printer hardware because in the end the printer processes data which is basically a program that controls the printer machine.

Furthermore printing documents via CUPS lets the user access and contol various programs that run on the computer where CUPS runs (i.e. the CUPS server machine which can also be the local host).

Those programs process the print job data (e.g. a PostScript or PDF file) in various ways to produce in the end printer specific data that is finally sent to the printer device. That final printer specific data is the above mentioned program which controls the printer machine.

Those programs are the cupsd (which runs as 'root' on the CUPS server), various filtering programs (e.g. Ghostscript), arbitrary printer drivers, and various backends. The various programs that convert the initial print job data into printer specific data (the filtering programs) and send the result to the printer device (the backend) are usually run as user 'lp' on the CUPS server.

Those programs work with the data in various ways so that in the end all together lead to a zillion of ways how the data is processed (cf. "Background Information" at SDB:How to Report a Printing Issue and "Processing stages of a print job" at SDB:CUPS in a Nutshell).

Furthermore certain kind of print job data (in particular PostScript but also PDF to some extent) is actually a program.

PostScript is a general purpose Turing-complete programming language (cf. https://en.wikipedia.org/wiki/PostScript) that supports in particular file access on the system disk. When Ghostscript processes PostScript it runs a PostScript program as the user who runs Ghostscript (usually the user 'lp', see above). Furthermore when Ghostscript processes PDF it also runs a PostScript program because PDF interpreter, as currently supplied with Ghostscript, is written in PostScript where PDF features which have no equivalent in PostScript need to be implemented via special PostScript extensions that have proven to be a security problem. See https://artifex.com/blog/changes-to-the-pdf-interpreter that provides a lot of background information about Ghostscript's PDF interpreter and why it will be replaced by a new PDF interpreter that is written entirely in C. When Ghostscript processes an arbitrary PostScript or PDF file, the user who runs Ghostscript runs an arbitrary program which can do basically anything on the system where Ghostscript runs that this user is allowed to do on that system. To make it safer when Ghostscript runs a PostScript program the Ghostscript command line option '-dSAFER' disables certain file access functionality (for details see /usr/share/doc/ghostscript/*/Use.htm). When printing documents Ghostscript is normally run with the '-dSAFER' option set. Its name 'SAFER' says everything: It makes it 'safer' to let Ghostscript run a PostScript program, but it cannot make things completely safe.

Users who are allowed to submit print jobs are allowed to upload arbitrary data and even certain kind of programs onto the CUPS server.

In theory all those programs that run on the CUPS server are safe against misuse.

In practice there is an endless sequence of various kind of security issues that appear every now and then in this or that particular program which get fixed issue by issue ad infinitum (and ad nauseam).

In the end all that means:

Users who are allowed to submit print jobs to a CUPS server are allowed to upload arbitrary data onto the CUPS server and run arbitrary programs in arbitrary ways (usually as user 'lp') on the CUPS server and finally access and contol the printer hardware as they like.

CUPS cannot be used in an environment where one does not know who the persons are that submit print jobs or where one cannot trust the persons that submit print jobs because there are too many possibilities for users who are allowed to submit print jobs to let "bad things" happen on the CUPS server.

Even if all those programs that run on the CUPS server were safe against misuse, any user who is allowed to submit print jobs could still do some kind of denial of service attack: Either by submitting many small useless print jobs or a few huge nonsense print jobs which waste toner/ink and paper or by submitting specific tiny PostScript or specially crafted PDF print jobs which let PostScript or PDF processing software (like Ghostscript) or a printer's built-in PostScript interpreter do basically endless time consuming processing or even hang up in an endless loop. The latter may result in loss of print jobs on PostScript printers when subsequent jobs of other users were already sent into the printer's memory while the tiny PostScript job is blocking the printer's actual printing unit endlessly. If the blocking job can only be aborted by a printer reset, the other jobs in its memory are usually lost. If you think things like printer accounting would be an easy way out here, have a look at SDB:Printer Accounting and you may get "some new kind of headache regarding printing setup".

In parctice the most feasible way out is to limit access to CUPS to trusted users plus the next items:

It is crucial to limit access to network printer devices to trusted users

Usual network printer devices (printers with a built-in network interface, see SDB:Printing via TCP/IP network) are no longer only "dumb" printing units. Nowadays network printers are also real computers with full network capabilities. When it looks like a printer, acts like a printer, sounds like a printer, it could be a computer! A user who controls a network printer controls a printing unit plus a computer with network access. Therefore it is crucial to limit access to network printer devices to trusted users (Google for "network printer security risk" - see above). Those access restrictions must be set up in the network printer device itself. Read the documentation of your network printer device how to do that.

It is crucial to not accept remote printing information from untrusted hosts

Traditionally by default the CUPS server process is accessible via UDP via IPP port 631 to accept any incomming information about remote print queues from any remote host. A CUPS print server can publish information about its queues in the network by sending UDP broadcasts and/or regular UDP (unicast) packets. Accordingly the CUPS server processes which run on the client hosts accept by default incomming information about remote print queues.

In this way, the queues of the server are available on the clients without any CUPS-specific configuration on the client hosts. Users on the clients can browse the queues on various servers. Therefore the whole stuff is called "CUPS Browsing". See the section "Intrinsic design of CUPS <= 1.5 for printing in the network" at SDB:CUPS_in_a_Nutshell and note the section "CUPS 1.6 has major incompatible changes" therein.

Nowadays remote print queue annoucements and remote printer announcements happen via DNS-SD that is implemented by Avahi instead of and/or in addition to traditional "CUPS Browsing", cf. "Zero-configuration networking" at Wikipedia https://en.wikipedia.org/wiki/Zero-configuration_networking and "Avahi" at Wikipedia https://en.wikipedia.org/wiki/Avahi_(software)

Regardless what is used for remote printing services announcements:

It is crucial to not accept remote printing information from untrusted hosts.

Otherwise possibly confidential print jobs could be sent to untrusted printers or print servers.

See the "print job phishing" thread on the "cups" mailing list from August 2007 http://www.cups.org/pipermail/cups/2007-August/thread.html that reads in particular:

When printing in the network is done via
usual CUPS Browsing, on the other workstations
in the network all announced queues with
the same name build automatically a so called
"implicite class" so that a print job which
is sent to the destination with this name
is printed on an arbitrary printer in this class.
...
A malicious user ... can set up queues ... with
the same name as queues on the official CUPS server
and announce his queues in the network.
...
on the other workstations their users cannot
notice that duplicated queues exist so that the
malicious user could do "print job phishing".

If you wonder why this behaviour is the default, have in mind that CUPS is designed for use in an internal network where the usability and convenience benefits (no CUPS-specific configuration on the client hosts) outweigh the security risk in an external network where furthermore by default the firewall provides protection. See the above "print job phishing" thread which reads in particular:

To summarize:
1. Once a malicious user gains access to a network,
there are numerous ways to compromise that network.
2. CUPS browsing attacks are easy to detect.
3. Disabling key features of CUPS browsing does not
offer any added security while making printing
much less usable.
4. Adding a signing key for browse packets would
make CUPS browsing more secure but would require
active configuration of every system on the network
to be effective.
5. Using alternate protocols and/or manual
configuration of shared printers can offer improved
security at the expense of usability/convenience.

By default the firewall prevents any access via network interfaces which belong to the external zone and by default all network interfaces belong to the external zone. Therefore by default the firewall rejects or drops any remote printing information from any host so that client hosts are protected against "print job phishing".

In general if you cannot trust the network you must not submit your private or confidential print jobs to arbitrary printers (i.e. to arbitrary print queues) which are "just accessible" for you.

For example assume you are traveling with your laptop and in your hotel lobby there is a printer for guests. Here you accept remote printing information because you trust that well known reputable "Grand Hotel". You need to print out your admission ticket for a non-public congress that you got right now during a perfectly secure registration via Internet. You submit your print job to the "grand_hotel_lobby_printer" and - voila! - a few seconds later your admission ticket comes out of the printer at the hotel lobby information desk. What you do not know is that those friendly businessman next to you had sent you the "grand_hotel_lobby_printer" print queue information from his laptop so that he got your admission ticket and then (after copying it) forwarded it to the actual printer share of the hotel lobby printer so that you won't notice the deception. Instead of using a print queue that was "just accessible", you had better asked the clerk at the hotel lobby information desk how to correctly access the printer. Now it is too late and nobody may notice the one more listener at that congress. Because it had "just worked" you don't wonder why you didn't have to pay for using a printer at a public accessible location or what (if not money) you actually paid for that printout or even think about "cui bono?" when "the intended purpose of security measures is to make things not just work" (see above).

To protect your host against "print job phishing":

Do not accept DNS-SD information from untrusted (external) hosts.

Do not open the CUPS IPP port 631 for the external zone in the firewall.

On the other hand the firewall lets by default any network traffic pass via network interfaces which belong to the internal zone. Therefore when the network interface for the internal network is assigned to the internal firewall zone on the client hosts, remote print queues which are published by internal CUPS print servers will be available on the client hosts.

To make published remote print queues available:

Assign the network interface which belongs to the internal network to the internal zone of the firewall.

As example for an exceptional case assume you have a laptop which you use while traveling but also in trusted networks in the office and at home where you like to use published remote print queues.

When the laptop has only a single network interface, trusted and non-trusted network traffic is mixed up so that the network interface must be assigned to the external firewall zone to protect the laptop against unwanted access via any network.

In this case you cannot open the CUPS IPP port 631 for the external zone in the firewall because this removes the firewall protection from the laptop in any network.

You simply cannot use arbitrary information about remote print queues from arbitrary hosts when trusted and non-trusted network traffic is mixed up.

In particular you cannot use FW_ALLOW_FW_BROADCAST_EXT="631" in this case because this would open the CUPS IPP port 631 for UDP broadcasts for the external zone so that remote print queue information from untrusted (i.e. external) CUPS servers would be accepted.

Instead you must specify on the laptop the trusted CUPS servers (usually one server for the office and another one for at home) and poll the list of available print queues from the trusted CUPS servers via a so called "BrowsePoll" setting in the CUPS configuration of the laptop, see SDB:CUPS_in_a_Nutshell the section "Configuration of the clients", "Special cases".

Assume printing from the laptop happens only in the office where no locally connected printer is used but only one single CUPS server of the company. Then it is no longer needed to run a CUPS server process on the laptop. Instead a so called "client-only" configuration could be set up, see SDB:CUPS_in_a_Nutshell the section "Configuration of the clients", "Client-only configuration". A possible drawback is that application programs may be delayed for some time (until a timeout happens) when they try to access the CUPS server of the company in another network where it is actually not available (e.g. while traveling). Usually it is a host name resolution (DNS) timeout which causes the delay so that it may help to have a hardcoded entry for the CUPS server of the company in the /etc/hosts file.

Neither for "BrowsePoll" nor for a "client-only" configuration you need to open the CUPS IPP port 631 in the firewall.

What is Specific Regarding Firewall Setup for Using Scanners

For using scanners via network the SANE network daemon (the saned) is the server process which must run so that remote clients can access scanners which are connected (usually via USB) to the local host.

When you have a network printer scanner copier all-in-one device with a built-in network interface so that the device is directy accessible via network, it is usually used in a different way by "stand-alone scanning to e-mail" where no SANE software (in particular no saned) is involved (see the section "Scanning via Network" in SDB:Configuring Scanners).

The saned is used by the clients via two kind of network connections. In addition to a control connection (via port 6566) saned also uses a separated data connection (for the actual scanning data). The port of the data connection is selected by the operating system and could no be specified so that all ports above 1024 must have been accessible (i.e. open in the firewall) for connections from the clients. The newest saned version provides support to specify a range of ports for the data connection in the saned configuration file /etc/sane.d/saned.conf via an entry like "data_portrange = 30000 - 30100" so that only those ports would have to be open in the firewall. But the latter does not provide real better security because in the end the saned must be accessible for using scanners via network.

To protect your host against unwanted access:

Do not open the sane-port 6566 or any other port regarding using scanners for the external zone in the firewall.

On the other hand the firewall lets by default any network traffic pass via network interfaces which belong to the internal zone. Therefore when the network interface for the internal network is assigned to the internal firewall zone, client hosts in the internal network can access the SANE server process to access scanners which are connected to the server machine. Independent of the firewall setup the SANE server must additionally be configured to permit access from those client hosts (by default it does not permit access).

To make your SANE server accessible:

Assign the network interface which belongs to the internal network to the internal zone of the firewall.

Setup for SuSEfirewall2

Alternatively as a best effort setup when one same network interface is used for the Internet connection and for the internal network, assign the network interface to the external zone and specify the trusted internal network via FW_TRUSTED_NETS in the firewall configuration.

Example for FW_TRUSTED_NETS:

Assuming your trusted subnet is 192.168.0.0/24 the entry reads:

FW_TRUSTED_NETS="192.168.0.0/24,tcp,6566"

Saned needs additional ports besides 6566 for the actual data transfer (see above). It is recommend to use the same ports as ftp 30000 - 30100 for this (see Bug 551282#c39). Therefore the port range setting in /etc/sane.d/saned.conf should read:

data_portrange = 30000 - 30100

Instead of opening these ports in the firewall (cf. above "DO NOT ...") additional entries like the following are required (assuming your trusted subnet is 192.168.0.0/24) in the firewall configuration:

FW_TRUSTED_NETS="... 192.168.0.0/24,tcp,30000:30100"
FW_SERVICES_ACCEPT_RELATED_EXT="192.168.0.0/24,tcp,,30000:30100"

Furthermore the kernel module nf_conntrack_sane must be loaded (see this mail http://lists.opensuse.org/archive/opensuse/2011-05/msg00000.html) via the following additional entry for FW_LOAD_MODULES in the firewall configuration:

FW_LOAD_MODULES="... nf_conntrack_sane"

This shows that when trusted and non-trusted network traffic is mixed up there is increased effort (i.e. a more complicated configuration that results a more fragile way of operation) and less network security (i.e. only a best effort attempt to get some kind of network security).

A side note when the subnet is 192.168.0.0/24: Often "router-box" devices that support separation of an internal network from the Internet use by default 192.168.0.0/24 for the internal network so that the above examples match in this case. But 192.168.0.0/24 could cause conflicts when there is more than one internal network. For example when a virtual private network (VPN) should be used between two such internal networks that both have the same "router-box" default 192.168.0.0/24, see http://openvpn.net/index.php/open-source/documentation/howto.html#numbering

Setup for firewalld

As a similar measure to the SuSEfirewall2 setting of FW_TRUSTED_NETS, FW_SERVICES_ACCEPT_RELATED_EXT, and FW_LOAD_MODULES as described above the following approach for Firewalld is possible:

Create a "private" zone

firewall-cmd --permanent --new-zone=private
firewall-cmd --permanent --zone=private --add-source=192.168.0.0/24

on the SANE server and on the client.

Additionally on the server set

firewall-cmd --permanent --zone=private --add-service=sane

The sane helper loads a sane specific conntrack module which takes care of opening any required ports for transferring scanner data - no additional explicit opening of ports is necessary.

Summary

By default the SuSEfirewall2 prevents any network access via network interfaces which belong to the external zone but it lets any network traffic pass via network interfaces which belong to the internal zone.

Both CUPS and SANE provide network services that are designed for use in a LAN and not intended to be exposed to the Internet or other non-trusted networks.

To use printers and scanners in a trusted internal network and have firewall protection against unwanted access from the Internet, set up the SuSEfirewall2 as follows:

Do not open the CUPS IPP port 631 or the sane-port 6566 or any other port for the external zone.

If different network interfaces are used for the Internet connection and for the internal network, assign the network interface for the Internet connection to the external zone and the network interface for the internal network to the internal zone.

Alternatively as a best effort setup when one same network interface is used for the Internet connection and for the internal network, assign the network interface to the external zone and specify the trusted internal network via FW_TRUSTED_NETS (and FW_ALLOW_FW_BROADCAST_EXT in case of UDP broadcasts) in the firewall configuration.

Bottom Line

To use printers and scanners in a trusted internal network and be protected by the SuSEfirewall2 against unwanted access from the Internet, do first and foremost this one single fundamental setup to gain security plus convenience in your network:

Only assign the network interface which belongs to the internal network to the internal zone of the firewall.

Make It Just Work: Firewall Zone Switcher

Use the Firewall Zone Switcher to specify if a network interface belongs to a trusted internal/private network (i.e. the internal zone of the firewall) or to a non-trusted external/public network like the Internet (i.e. the external zone of the firewall).

The Firewall Zone Switcher is provided as RPM package "fwzs". It is not installed by default so that you have to install it manually.

To use the Firewall Zone Switcher launch its desktop tray applet program "fwzsapp" so that you can at any time switch firewall zones of your network interfaces according to your current needs.

Assume you have a laptop which you use while traveling but also in trusted networks in the office and at home. The default enabled SuSEfirewall2 protects you when connecting to any network while traveling, for example an anonymous WiFi network at a restaurant. But the very same firewall becomes annoying in the office or at home where it prevents your system from discovering network printers or from having remote print queues of a CUPS print server available on your laptop or from using scanners via network. With the Firewall Zone Switcher applet you can switch the firewall zone to 'internal/private' when you are in the office or at home. In an untrusted network you must set the firewall zone back to 'external/public' to be protected.

Firewall Zone Switcher is not meant to be some kind of 'Personal Firewall' that confuses the user with all kinds of low level stuff. It is neither a firewall configuration tool. That job is still left to admin tools like YaST. Firewall Zone Switcher settings are temporary and are reset to the system defaults on reboot to keep you on the safe side.

Further Information