Online Book Reader

Home Category

Squid_ The Definitive Guide - Duane Wessels [50]

By Root 2089 0
always to end your access lists with explicit rules that either allow or deny all requests. To be perfectly clear, the previous example should be written this way:

acl All src 0/0

acl Bob ident bob

http_access allow Bob

http_access deny All

The src 0/0 ACL is an easy way to match each and every type of request.

Access List Style

Squid's access control syntax is very powerful. In most cases, you can probably think of two or more ways to accomplish the same thing. In general, you should put the more specific and restrictive access controls first. For example, rather than:

acl All src 0/0

acl Net1 src 1.2.3.0/24

acl Net2 src 1.2.4.0/24

acl Net3 src 1.2.5.0/24

acl Net4 src 1.2.6.0/24

acl WorkingHours time 08:00-17:00

http_access allow Net1 WorkingHours

http_access allow Net2 WorkingHours

http_access allow Net3 WorkingHours

http_access allow Net4

http_access deny All

you might find it easier to maintain and understand the access control configuration if you write it like this:

http_access allow Net4

http_access deny !WorkingHours

http_access allow Net1

http_access allow Net2

http_access allow Net3

http_access deny All

Whenever you have a rule with two or more ACL elements, it's always a good idea to follow it up with an opposite, more general rule. For example, the default Squid configuration denies cache manager requests that don't come from the localhost IP address. You might be tempted to write it like this:

acl CacheManager proto cache_object

acl Localhost src 127.0.0.1

http_access deny CacheManager !Localhost

However, the problem here is that you haven't yet allowed the cache manager requests that do come from localhost. Subsequent rules may cause the request to be denied anyway. These rules have this undesirable behavior:

acl CacheManager proto cache_object

acl Localhost src 127.0.0.1

acl MyNet 10.0.0.0/24

acl All src 0/0

http_access deny CacheManager !Localhost

http_access allow MyNet

http_access deny All

Since a request from localhost doesn't match MyNet, it gets denied. A better way to write the rules is like this:

http_access allow CacheManager localhost

http_access deny CacheManager

http_access allow MyNet

http_access deny All

Delayed Checks

Some ACLs can't be checked in one pass because the necessary information is unavailable. The ident, dst, srcdomain, and proxy_auth types fall into this category. When Squid encounters an ACL that can't be checked, it postpones the decision and issues a query for the necessary information (IP address, domain name, username, etc.). When the information is available, Squid checks the rules all over again, starting at the beginning of the list. It doesn't continue where the previous check left off. If possible, you may want to move these likely-to-be-delayed ACLs near the top of your rules to avoid unnecessary, repeated checks.

Because these delays are costly (in terms of time), Squid caches the information whenever possible. Ident lookups occur for each connection, rather than each request. This means that persistent HTTP connections can really benefit you in situations where you use ident queries. Hostnames and IP addresses are cached as specified by the DNS replies, unless you're using the older external dnsserver processes. Proxy Authentication information is cached as I described previously in Section 6.1.2.12.

Slow and Fast Rule Checks

Internally, Squid considers some access rule checks fast, and others slow. The difference is whether or not Squid postpones its decision to wait for additional information. In other words, a slow check may be deferred while Squid asks for additional data, such as:

A reverse DNS lookup: the hostname for a client's IP address

An RFC 1413 ident query: the username associated with a client's TCP connection

An authenticator: validating the user's credentials

A forward DNS lookup: the origin server's IP address

An external, user-defined ACL

Some access rules use fast checks out of necessity. For example, the icp_access rule is a fast check. It must be fast, to serve ICP queries quickly.

Return Main Page Previous Page Next Page

®Online Book Reader