iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🦑

A Collection of Squid Tips

に公開
2022/06/19

Squid notes on things to remember when using it in production ✍
Specifically, I'll introduce cases where it's used as a simple forward proxy.

https://www.f5.com/ja_jp/services/resources/glossary/forward-proxy

Setting up BASIC Authentication

Specify using auth_param basic.

https://www.robata.org/docs/squid/Reference/squid3.4.0.3/auth_param.html

squid.conf
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/.htpasswd
auth_param basic children 5 startup=5 idle=1
auth_param basic realm hello
auth_param basic credentialsttl 1 minute
.htpasswd
user1:$xxxxxxxxxxxxxxxxxxxxxxxxxxxx
user2:$xxxxxxxxxxxxxxxxxxxxxxxxxxxx
user3:$xxxxxxxxxxxxxxxxxxxxxxxxxxxx

It is recommended to issue passwords using the pwgen command.

https://linuxfan.info/pwgen

username="user1"
pw="$(pwgen 16 1 | tr -d '\r\n')"
echo "password: $pw"
echo "$(htpasswd -nb "$username" "$pw" | tr -d '\r\n')" >> "/etc/squid/.htpasswd"

Allowing access only to specific domains

If you want to allow access to specific domains for specific user groups, use the following:

squid.conf
# groups
acl group1 proxy_auth "/etc/squid/groups/group1.txt"
acl group2 proxy_auth "/etc/squid/groups/group2.txt"
acl admin proxy_auth "/etc/squid/groups/admin.txt"

# domains
acl domains_domain1 dstdom_regex "/etc/squid/domains/domain1.txt"
acl domains_domain2 dstdom_regex "/etc/squid/domains/domain2.txt"

# allow
http_access allow admin
http_access allow domains_domain1 group1
http_access allow domains_domain1 group2
http_access allow domains_domain2 group2
http_access deny all

Example of the groups file
List the usernames specified when creating .htpasswd.

/etc/squid/groups/group1.txt
user1
user3

Example of the domains file
Specify domain names using regular expressions.

/etc/squid/domains/domain1.txt
^intra\.example\.com$

Allowing access only to specific ports

Allow access only to specific ports at the destination connected from the proxy.

https://blog.cybozu.io/entry/2017/02/03/080000

squid.conf
acl Safe_ports port 80
acl Safe_ports port 443
acl Safe_ports port 1025-65535
http_access deny !Safe_ports

Reducing information returned to the client

Avoid returning specific failure reasons in the event of an error.

https://www.robata.org/docs/squid/Reference/squid3.4.0.3/deny_info.html

Remove HTTP headers that might reveal you are using Squid.

https://www.robata.org/docs/squid/Reference/squid3.4.0.3/reply_header_access.html

squid.conf
acl errors http_status 400-599
deny_info TCP_RESET errors
http_reply_access deny errors

reply_header_access X-Squid-Error deny all
reply_header_access X-Cache deny all
reply_header_access X-Cache-Lookup deny all
reply_header_access Server deny all
reply_header_access Via deny all
reply_header_access Vary deny all
reply_header_access Mime-Version deny all
reply_header_access Content-Language deny all

Logs

Access logs are output to /var/log/squid/access.log.

access.log
# TCP_DENIED is output when a transfer is denied
1632751525.920      0 172.17.0.1 TCP_DENIED/403 4129 CONNECT xxx.intra.example.com:443 user1 HIER_NONE/- text/html

# It seems that TCP_TUNNEL or TAG_NONE indicates the request was transferred
1632751444.516 240848 172.17.0.1 TCP_TUNNEL/200 6661 CONNECT xxx.intra.example.com:443 user1 HIER_DIRECT/xxx.xxx.xxx.xxx -
1632751457.182 180026 172.17.0.1 TAG_NONE/503 0 CONNECT xxx.intra.example.com:443 user1 HIER_NONE/- -

Docker Image

When operating with Docker, it seems like a good idea to use this as a base.

https://hub.docker.com/r/ubuntu/squid

That's all 😌

Discussion