Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 8. Squid Caching Proxy
Squid is a high-performance proxy caching server for web clients, supporting FTP, Gopher, and HTTP data objects. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages.[6]
In Red Hat Enterprise Linux, the squid package provides the Squid Caching Proxy. Run the
rpm -q squid
command to see if the squid package is installed. If it is not installed and you want to use squid, run the following command as the root user to install it:
yum install squid
~]# yum install squid
8.1. Squid Caching Proxy and SELinux
When SELinux is enabled, squid runs confined by default. Confined processes run in their own domains, and are separated from other confined processes. If a confined process is compromised by an attacker, depending on SELinux policy configuration, an attacker's access to resources and the possible damage they can do is limited. The following example demonstrates the squid processes running in their own domain. This example assumes the squid package is installed:
- Run the
getenforce
command to confirm SELinux is running in enforcing mode:getenforce
~]$ getenforce Enforcing
Copy to Clipboard Copied! Thegetenforce
command returnsEnforcing
when SELinux is running in enforcing mode. - Run the
service squid start
command as the root user to startsquid
:service squid start
~]# service squid start Starting squid: [ OK ]
Copy to Clipboard Copied! - Run the
ps -eZ | grep squid
command to view thesquid
processes:ps -eZ | grep squid
~]$ ps -eZ | grep squid unconfined_u:system_r:squid_t:s0 2522 ? 00:00:00 squid unconfined_u:system_r:squid_t:s0 2524 ? 00:00:00 squid unconfined_u:system_r:squid_t:s0 2526 ? 00:00:00 ncsa_auth unconfined_u:system_r:squid_t:s0 2527 ? 00:00:00 ncsa_auth unconfined_u:system_r:squid_t:s0 2528 ? 00:00:00 ncsa_auth unconfined_u:system_r:squid_t:s0 2529 ? 00:00:00 ncsa_auth unconfined_u:system_r:squid_t:s0 2530 ? 00:00:00 ncsa_auth unconfined_u:system_r:squid_t:s0 2531 ? 00:00:00 unlinkd
Copy to Clipboard Copied! The SELinux context associated with thesquid
processes isunconfined_u:system_r:squid_t:s0
. The second last part of the context,squid_t
, is the type. A type defines a domain for processes and a type for files. In this case, thesquid
processes are running in thesquid_t
domain.
SELinux policy defines how processes running in confined domains, such as
squid_t
, interact with files, other processes, and the system in general. Files must be labeled correctly to allow squid access to them.
When
/etc/squid/squid.conf
is configured so squid
listens on a port other than the default TCP ports 3128, 3401 or 4827, the semanage port
command must be used to add the required port number to the SELinux policy configuration. The following example demonstrates configuring squid
to listen on a port that is not initially defined in SELinux policy configuration for squid
, and, as a consequence, squid
failing to start. This example also demonstrates how to then configure the SELinux system to allow squid
to successfully listen on a non-standard port that is not already defined in the policy. This example assumes the squid package is installed. Run each command in the example as the root user:
- Run the
service squid status
command to confirmsquid
is not running:service squid status
~]# service squid status squid is stopped
Copy to Clipboard Copied! If the output differs, run theservice squid stop
command to stop the process:service squid stop
~]# service squid stop Stopping squid: [ OK ]
Copy to Clipboard Copied! - Run the
semanage port -l | grep -w squid_port_t
command to view the ports SELinux allowssquid
to listen on:semanage port -l | grep -w -i squid_port_t
~]# semanage port -l | grep -w -i squid_port_t squid_port_t tcp 3401, 4827 squid_port_t udp 3401, 4827
Copy to Clipboard Copied! - Edit
/etc/squid/squid.conf
as the root user. Configure thehttp_port
option so it lists a port that is not configured in SELinux policy configuration forsquid
. In this example,squid
is configured to listen on port 10000:Squid normally listens to port 3128
# Squid normally listens to port 3128 http_port 10000
Copy to Clipboard Copied! - Run the
setsebool
command to make sure thesquid_connect_any
Boolean is set to off. This ensures squid is only permitted to operate on specific ports:setsebool -P squid_connect_any 0
~]# setsebool -P squid_connect_any 0
Copy to Clipboard Copied! - Run the
service squid start
command to startsquid
:service squid start
~]# service squid start Starting squid: .................... [FAILED]
Copy to Clipboard Copied! An SELinux denial similar to the following is logged:localhost setroubleshoot: SELinux is preventing the squid (squid_t) from binding to port 10000. For complete SELinux messages. run sealert -l 97136444-4497-4fff-a7a7-c4d8442db982
localhost setroubleshoot: SELinux is preventing the squid (squid_t) from binding to port 10000. For complete SELinux messages. run sealert -l 97136444-4497-4fff-a7a7-c4d8442db982
Copy to Clipboard Copied! - For SELinux to allow
squid
to listen on port 10000, as used in this example, the following command is required:semanage port -a -t squid_port_t -p tcp 10000
~]# semanage port -a -t squid_port_t -p tcp 10000
Copy to Clipboard Copied! - Run
service squid start
again to startsquid
and have it listen on the new port:service squid start
~]# service squid start Starting squid: [ OK ]
Copy to Clipboard Copied! - Now that SELinux has been configured to allow
squid
to listen on a non-standard port (TCP 10000 in this example),squid
starts successfully on this port.