Squid Web Cache Wiki

Squid Web Cache 文档

🔗 绕过某些站点的身份验证

🔗 目录

转发代理设计中一个非常常见的设置是需要两种不同的访问类别

Squid 可以通过正确设置访问列表的顺序来实现这种设置。

🔗 Squid 配置文件

第一个建议是熟悉如何正确配置 Squid 进行身份验证的基本概念。相关文档可以在 Features/Authentication,以及 aclauth_paramhttp_accesshttp_access2http_reply_access 的手册页中找到。

您可能还想查看 ConfigExamples/Authenticate/KerberosConfigExamples/Authenticate/Ntlm 以获取特定身份验证方案的文档。

首先设置 Squid,使其对所有目标上的所有用户进行身份验证,一旦您对其工作方式满意,就可以按照类似此示例的方式修改配置文件

# protect the cache manager, Safe_ports, SSL tunnels, then after the section marked as

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#


acl whitelist dstdomain .whitelist.com .goodsite.com .partnerssite.com
acl http proto http
acl port_80 port 80
acl port_443 port 443
acl CONNECT method CONNECT
acl authenticated_users proxy_auth REQUIRED

# rules allowing non-authenticated users
http_access allow http port_80 whitelist
http_access allow CONNECT port_443 whitelist

# rules allowing authenticated users
http_access allow http port_80 authenticated_users
http_access allow CONNECT port_443 authenticated_users

# catch-all rule
http_access deny all

此配置片段允许任何能够通过您选择的身份验证机制成功进行身份验证的用户访问标准服务端口上的 http 和 https。

关键在于将所有允许未经身份验证的用户访问的 http_access 规则放在需要用户身份的 http_access 规则 **之前**。

🔗 更复杂的示例

前面的示例可以扩展到更复杂的场景。例如,您可能希望有两组不同的用户(我们称之为 GroupA 和 GroupB)和三类站点:一类必须对未经身份验证的用户可用,一类必须对 GroupA 中的用户可用,另一类必须对 GroupB 中的用户可用。请注意,没有任何限制阻止用户组或站点列表重叠。用户组保留在 Squid 配置本身中,使用辅助文件。

这可以通过使用 6 个配置文件来实现

*/etc/squid/groupa.txt*

    user1
    user2
    user3

*/etc/squid/groupb.txt*

    user1
    user4
    user5

*/etc/squid/sites.a.txt*

    .foo.example.com
    .bar.example.com

*/etc/squid/sites.b.txt*

    .foo.example.com
    .gazonk.example.com

*/etc/squid/sites.whitelist.txt*

    .public.example.com

*/etc/squid/squid.conf*

    # protect the cache manager, Safe_ports, SSL tunnels, then after the section marked as
    
    #
    # INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
    #
    
    
    acl whitelist dstdomain "/etc/squid/sites.whitelist.txt"
    acl UsersGroupA proxy_auth "/etc/squid/groupa.txt"
    acl SitesGroupA dstdomain "/etc/squid/sites.a.txt"
    acl UsersGroupB proxy_auth "/etc/squid/groupb.txt"
    acl SitesGroupB dstdomain "/etc/squid/sites.b.txt"
    acl http proto http
    acl port_80 port 80
    acl port_443 port 443
    acl CONNECT method CONNECT
    acl authenticated_users proxy_auth REQUIRED
    
    # rules allowing non-authenticated users
    http_access allow http port_80 whitelist
    http_access allow CONNECT port_443 whitelist
    
    # rules allowing authenticated users
    http_access allow http port_80 SitesGroupA UsersGroupA
    http_access allow CONNECT port_443 SitesGroupA UsersGroupA
    http_access allow http port_80 SitesGroupB UsersGroupB
    http_access allow CONNECT port_443 SitesGroupB UsersGroupB
    
    # catch-all rule
    http_access deny all

此示例配置将允许任何用户访问白名单站点而不要求身份验证,A 组中的用户将能够访问 A 列表中的站点,B 组中的用户将能够访问 B 组中的站点,而其他人将无法访问任何其他内容。

🔗 高级配置

http_access 子句的顺序很重要,每个 http_access 子句中定义的 acl 的顺序也很重要:这是因为一旦 Squid 决定一组条件不满足,它就不会评估接下来的条件。这可能导致非常细微的行为差异。

让我们关注第二个示例中的几行(ACL 定义保持不变)

    http_access allow http port_80 whitelist
    http_access allow http port_80 SitesGroupA UsersGroupA
    http_access allow http port_80 SitesGroupB UsersGroupB
    # catch-all rule
    http_access deny all

并进行小小的更改

    http_access allow http port_80 whitelist
    http_access allow http port_80 SitesGroupA UsersGroupA
    http_access allow http port_80 SitesGroupB UsersGroupB
    # catch-all rule
    http_access deny authenticated_users

此更改的效果是访问权限保持不变:groupA 将获得 sitesA,groupB 将获得 sitesB。区别在于当有人尝试访问既不在 sitesA 也不在 sitesB 中的站点时会发生什么:在前面的示例中,他们会得到一个直接的访问拒绝,而通过此更改,他们将被要求提供密码。他们仍然无法访问,但被拒绝的方式不同。

另一个可能的更改是

    http_access allow http port_80 whitelist
    http_access allow UsersGroupA http port_80 SitesGroupA
    http_access allow UsersGroupB http port_80 SitesGroupB
    # catch-all rule
    http_access deny all

行为再次改变:用户访问白名单站点将不需要身份验证。一旦他们离开白名单站点,他们就会被要求身份验证(以前只有在他们尝试访问受保护资源时才会被要求)。


⚠️ Disclaimer: Any example presented here is provided "as-is" with no support
or guarantee of suitability. If you have any further questions about
these examples please email the squid-users mailing list.

类别: ConfigExample

导航:站点搜索站点页面分类🔼 向上