iTranslated by AI
A Collection of Squid Tips
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.
Setting up BASIC Authentication
Specify using auth_param basic.
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
user1:$xxxxxxxxxxxxxxxxxxxxxxxxxxxx
user2:$xxxxxxxxxxxxxxxxxxxxxxxxxxxx
user3:$xxxxxxxxxxxxxxxxxxxxxxxxxxxx
It is recommended to issue passwords using the pwgen command.
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:
# 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.
user1
user3
Example of the domains file
Specify domain names using regular expressions.
^intra\.example\.com$
Allowing access only to specific ports
Allow access only to specific ports at the destination connected from the proxy.
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.
Remove HTTP headers that might reveal you are using Squid.
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.
# 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.
That's all 😌
Discussion