Add your comments


Squid ACL Primer

This is a crash course on Squid Access Control Lists (ACLs) in Squid. For more background on how to use Squid in your organisation, see chapter six, Performance Tuning.

There are two types of ACL objects in Squid: ACL elements and ACL rules. Both are used together to implement access control on your Squid cache. ACLs are specified in your squid.conf file. When you are finished making changes to your ACLs, you should run squid -k reconfigure. This causes Squid to reload the config file and use your new settings.

ACL elements

ACL elements are the basic building blocks of the access control features of Squid. They let you define elements that identify a request, such as IP addresses, port numbers, host names or user names.

The basic syntax of a ACL element is:

acl name type value1 value2 value3 ...

It is important to note that elements use OR logic to process the values. This means that as soon a match is found, the element will return true. It is possible to refer to the same element name on multiple lines, as well as on the same line. For example:

acl myinternalip 10.1.0.0/255.255.0.0 10.2.0.0/255.255.0.0

...is the same as:

acl myinternalip 10.1.0.0/255.255.0.0 
acl myinternalip 10.2.0.0/255.255.0.0

ACL elements can also be contained in external files. This makes it easy to manage a long list of values.

acl myinternalip "/etc/mynets"

This directs Squid to read /etc/mynets to populate the myinternalip element. Each value should be on its own line in the /etc/mynets file.

Some other useful ACL elements are:

acl aclname src [ip-address/netmask]

acl aclname dst [ip-address/netmask]

acl aclname dstdomain [domain-name]

acl aclname dstdom_regex [pattern]

acl aclname time [day] [hh:mm-hh:mm]

acl business_hours time MTWHF 8:00-18:00

acl aclname url_regex [pattern]

acl aclname urlpath_regex [pattern]

acl aclname port [number]

acl aclname proxy_auth [user names]

acl aclname proxy_auth_regex [pattern]

ACL rules

ACL rules combine ACL elements to control access to certain features of Squid. It is important to remember is that the ACL rules use AND logic. This means that all elements on line need to evaluate to true in order for the rule to execute. The rules are processed from the top down. As soon as a rule matches, the rule is executed and all subsequent rules using the same rule type will be ignored.

It is a very good idea to keep ACL rules of the same type together. It can be very easy to get confused if you have, for example, your http_access rules scattered all over your squid.conf file.

There are several ACL rule types. Here are some of the most commonly used rules.

http_access [allow|deny] [aclname]

You can precede any element with a ! to match anything that is not on the list. If none of the access lines match, then the default is to do whatever is the opposite of the last line in the list. It is a good idea to insert a deny all or allow all entry at the end of your access lists to avoid confusion.

icp_access [allow|deny] [aclname]

redirector_access [allow|deny] [aclname]

delay_access [delaypoolnumber] [allow|deny] [aclname]

Examples

Here are some examples of how to perform common ACL tasks in Squid.

Allow only local clients

Almost all Squid installations need to restrict access based on the client's IP address. This is one of the best ways to protect your cache from abuse and bandwidth theft. This example will only permit clients from MyNet to access the cache.

acl MyNet src 10.2.1.0/24 10.2.2.0/24
http_access allow MyNet
http_access deny All

Deny a list of sites

Add the list of sites you wish to block to the file specified by BadSites, with one site per line.

acl BadSites dstdomain "/usr/local/squid/etc/badsites"
http_access deny BadSites
http_access allow MyNet
http_access deny All

Block a few clients by IP address

acl BadPc src 10.1.2.4
http_access deny BadPc
http_access allow MyNet
http_access deny All

Allow access to the bad sites only after hours

acl workhours acl workhours time MTWHF 08:00-17:00
acl BadSites dstdomain "/usr/local/squid/etc/badsites"
http_access deny workhours BadSites
http_access allow MyNet
http_access deny All

Block certain users regardless of their IP address

acl Authenticated proxy_auth REQUIRED
acl BadUsers proxy_auth Richard John
http_access deny BadUsers
http_access allow MyNet
http_access deny All

Direct certain users to a delay pool

acl Authenticated proxy_auth REQUIRED
acl SlowUsers proxy_auth Richard John
http_access allow MyNet
http_access deny All
delay_access 2 allow SlowUsers
delay_access 2 deny # This so no other users match this pool
delay_access 1 allow all

For more information about ACLs, see the online Squid documentation at http://www.deckle.co.za/squid-users-guide/.


Add your comments


English/AppendixB (last edited 2006-10-14 00:28:13 by RobFlickenger)