Squid Web Cache Wiki

Squid Web Cache 文档

🔗 使用 Kerberos 对 Active Directory 进行身份验证的 Squid 服务器配置

原著 Adrian Chadd,James Robertson 于 2012 年 1 月 19 日更新,Christopher Schirner 于 2014 年 11 月 11 日更新

集成 Active Directory 的另一种方法是通过 Samba 和 NTLM

🔗 简介

此 wiki 页面涵盖了 Squid 代理的设置,该代理将使用 Kerberos、NTLM 和基本身份验证(适用于未通过 Kerberos 或 NTLM 进行身份验证的客户端)无缝集成到 Active Directory 中。

:warning: 文件路径和帐户用户名/组名将取决于特定的操作系统设置

🔗 示例环境

将使用以下示例,您应根据需要更新所有配置示例中的客户端域、主机名、IP 地址等。

🔗 先决条件

客户端 Windows 计算机需要在Internet 选项 ⇒ 高级设置中勾选启用集成 Windows 身份验证

🔗 DNS 配置

在 Windows DNS 服务器上为代理服务器的主机名添加一个新的 A 记录条目,并确保也创建并运行相应的 PTR(反向 DNS)条目。检查代理是否正在使用 Windows DNS 服务器进行名称解析,并相应地更新 /etc/resolv.conf

根据您的网络编辑文件。

domain example.local
search example.local
nameserver 192.168.0.1
nameserver 192.168.0.2

ping 内部和外部主机名以确保 DNS 正常运行。

ping dc1.example.local -c 4 && ping google.com -c 4

从 Windows DNS 检查您是否可以反向查找 Windows 服务器和本地代理 IP。

dig -x 192.168.0.1
dig -x 192.168.0.10

答案部分应包含 dc1.example.localsquidproxy.example.local 的 DNS 名称。

:information_source: 重要提示:如果任何一个查找失败,请在修复之前不要继续,否则身份验证可能会失败。

🔗 NTP 配置

时间需要与 Windows 域控制器同步才能进行身份验证,配置代理从它们那里获取时间并进行测试以确保它们按预期工作。

🔗 安装和配置 Kerberos

安装 Kerberos 软件包 - 在 Debian 上是 krb5-user libkrb53

编辑文件 /etc/krb5.conf,用您的域和服务器替换变量。

:information_source: 重要提示:如果您只有一个域控制器,请从 [realms] 部分删除额外的 kdc 条目,或添加任何其他 DC。

根据您的域控制器操作系统版本,取消注释相关的 Windows 200X 部分并注释掉相对的部分。

[libdefaults]
    default_realm = EXAMPLE.LOCAL
    dns_lookup_kdc = no
    dns_lookup_realm = no
    ticket_lifetime = 24h
    default_keytab_name = /etc/squid3/PROXY.keytab

; for Windows 2003
    default_tgs_enctypes = rc4-hmac des-cbc-crc des-cbc-md5
    default_tkt_enctypes = rc4-hmac des-cbc-crc des-cbc-md5
    permitted_enctypes = rc4-hmac des-cbc-crc des-cbc-md5

; for Windows 2008 with AES
;    default_tgs_enctypes = aes256-cts-hmac-sha1-96 rc4-hmac des-cbc-crc des-cbc-md5
;    default_tkt_enctypes = aes256-cts-hmac-sha1-96 rc4-hmac des-cbc-crc des-cbc-md5
;    permitted_enctypes = aes256-cts-hmac-sha1-96 rc4-hmac des-cbc-crc des-cbc-md5

[realms]
    EXAMPLE.LOCAL = {
        kdc = dc1.example.local
        kdc = dc2.example.local
        admin_server = dc1.example.local
        default_domain = example.local
    }

[domain_realm]
    .example.local = EXAMPLE.LOCAL
    example.local = EXAMPLE.LOCAL

:information_source: 重要通知:应使用“Windows 2008 with AES”(如果可用)。这不仅对安全很重要,而且在使用 Squid 服务器的 DNS 名称而不是 IP 地址时也可能遇到问题。

有关此问题的示例如错误消息可能如下所示

ERROR: Negotiate Authentication validating user. Error returned 'BH gss_accept_sec_context() failed: Unspecified GSS failure.  Minor code may provide more information.'

🔗 安装 Squid 3

我们现在安装 squid 3,因为我们需要 squid3 目录。Squid 配置在身份验证配置之后进行。在 Debian 上安装 squid3 ldap-utils 软件包。

🔗 认证

该代理使用 4 种方法来验证客户端:Negotiate/Kerberos、Negotiate/NTLM、NTLM 和基本身份验证。Markus Moellers 的 negotiate_wrapper 用于 2 种 Negotiate 方法。

🔗 Kerberos

Kerberos 使用 msktutil,一个 Active Directory keytab 管理器(我推测这个名字是“Microsoft Keytab Utility”的缩写)。我们需要安装 msktutil 所需的一些软件包。在 Debian 上安装 libsasl2-modules-gssapi-mit libsasl2-modules

安装 msktutil - 您可以在这里找到 msktutil “http://fuhm.net/software/msktutil/releases/

以管理员权限启动到服务器的 kerberos 会话,以便向 AD 添加对象,并在必要时更新用户名。msktutil 将使用它在 Active Directory 中创建我们的 kerberos 计算机对象。

kinit administrator

它应该会成功返回,没有错误。您可以使用以下命令查看是否成功获取了 ticket

klist

现在我们配置代理的 kerberos 计算机帐户和服务主体,方法是运行 msktutil(记住用您的值更新)。

:warning: 重要提示:关于 msktutils 的 –computer-name 参数,有两个重要的注意事项:- -computer-name 不能超过 15 个字符,因为 netbios 名称有限制。有关更多信息,请参阅此链接和此链接。 - -computer-name 必须与代理的主机名不同,这样 NTLM 和 Kerberos 的计算机帐户密码更新才不会冲突,有关更多信息,请参阅此链接。本指南使用 -k 附加到主机名。

按如下方式执行 msktutil 命令

msktutil -c -b "CN=COMPUTERS" -s HTTP/squidproxy.example.local -k /etc/squid3/PROXY.keytab \
    --computer-name SQUIDPROXY-K --upn HTTP/squidproxy.example.local --server dc1.example.local --verbose

:information_source: 如果您使用的是 Server 2008 域,则在命令末尾添加 --enctypes 28

请注意命令的输出以确保成功,因为我们使用的是 –verbose 输出,所以您应该仔细审查它。

设置 keytab 的权限,以便 squid 可以读取它。

chgrp proxy /etc/squid3/PROXY.keytab
chmod g+r /etc/squid3/PROXY.keytab

销毁用于创建帐户的管理员凭据。

kdestroy

在 Windows 服务器上,通过右键单击 SQUIDPROXY-K 计算机对象并选择“重置帐户”来重置 AD 中的计算机帐户,然后运行 msktutil 如下,以确保 keytab 按预期更新并且 keytab 正确地由 msktutil 从 /etc/krb5.conf 获取。这并非完全必要,但有助于确保 msktutil 按预期工作。然后运行以下命令

msktutil --auto-update --verbose --computer-name squidproxy-k

:information_source: 即使帐户是大写字母,msktutil 中的 --auto-update 也需要 --computer-name 为小写。

如果找不到 keytab,请尝试在命令中添加 -k /etc/squid3/PROXY.keytab 以查看是否有效,然后进行故障排除直到解决,否则用户将无法使用 Squid 进行身份验证。

将以下内容添加到 cron,以便它能够自动更新 Active Directory 中的计算机帐户(通常为 30 天)。将其通过 logger 管道,以便我可以在 syslog 中看到任何错误(如果需要)。如前所述,msktutil 使用默认的 /etc/krb5.conf 文件作为其参数,因此如果您决定对其进行任何更改,请注意这一点。

00 4  *   *   *     msktutil --auto-update --verbose --computer-name squidproxy-k | logger -t msktutil

编辑 squid3 的 init 脚本以导出 KRB5_KTNAME 变量,以便 squid 知道从哪里找到 kerberos keytab。

在 Debian 上,最简单的方法如下

将以下配置添加到 /etc/default/squid3

KRB5_KTNAME=/etc/squid3/PROXY.keytab
export KRB5_KTNAME

🔗 NTLM

安装 Samba 和 Winbind。在 Debian 上安装 samba winbind samba-common-bin

停止 samba 和 winbind 守护进程并编辑 /etc/samba/smb.conf

workgroup = EXAMPLE
security = ads
realm = EXAMPLE.LOCAL

winbind uid = 10000-20000
winbind gid = 10000-20000
winbind use default domain = yes
winbind enum users = yes
winbind enum groups = yes

现在将代理加入域。

net ads join -U Administrator

启动 samba 和 winbind 并测试对域的访问。

wbinfo -t

此命令应输出类似以下内容

checking the trust secret for domain EXAMPLE via RPC calls succeeded

wbinfo -a EXAMPLE\\testuser%'password'

输出应与此类似。

plaintext password authentication succeeded
challenge/response password authentication succeeded

设置权限,以便代理用户帐户可以读取 /var/run/samba/winbindd_privileged

gpasswd -a proxy winbindd_priv
  • :warning: 在 Debian 和 Ubuntu 系统上,winbind 和 ntlm_auth 工具还可能创建具有 root 所有权的 /var/lib/samba/winbindd_privileged 目录。该文件夹的组需要更改为与 /var/run/samba/winbindd_privileged 位置匹配。

将以下内容添加到 cron 中,以定期更改计算机帐户密码(Samba 可能会自动执行此操作,请检查 Samba 文档)

    05  4  *   *   *     net rpc changetrustpw -d 1 | logger -t changetrustpw

🔗 基本

为了通过 LDAP 使用基本身份验证,我们需要创建一个帐户来访问 Active Directory。

在 Active Directory 中创建一个名为“Squid Proxy”的用户,登录名为 squid@example.local

确保在创建帐户时满足以下条件

创建一个由 squid 用于 ldap 访问的密码文件并保护文件权限(将下面的“squidpass”替换为您的密码)。

echo 'squidpass' > /etc/squid3/ldappass.txt
chmod o-r /etc/squid3/ldappass.txt
chgrp proxy /etc/squid3/ldappass.txt

🔗 安装 negotiate_wrapper

首先,我们需要安装 negotiate_wrapper。在 Debian 上安装必要的构建工具,安装 build-essential linux-headers-$(uname -r) 然后编译和安装。

cd /usr/local/src/
wget "http://downloads.sourceforge.net/project/squidkerbauth/negotiate_wrapper/negotiate_wrapper-1.0.1/negotiate_wrapper-1.0.1.tar.gz"
tar -xvzf negotiate_wrapper-1.0.1.tar.gz
cd negotiate_wrapper-1.0.1/
./configure
make
make install

🔗 squid.conf

然后设置 squid 及其关联的配置文件。

将以下内容添加到您的 squid.conf

仔细研究并更新以下文本,将示例内容替换为您的网络配置 - 如果您弄错了,您的代理将无法工作。

### /etc/squid3/squid.conf Configuration File ####

### negotiate kerberos and ntlm authentication
auth_param negotiate program /usr/local/bin/negotiate_wrapper -d --ntlm /usr/bin/ntlm_auth --diagnostics --helper-protocol=squid-2.5-ntlmssp --domain=EXAMPLE --kerberos /usr/local/bin/squid_kerb_auth -d -s GSS_C_NO_NAME
auth_param negotiate children 10
auth_param negotiate keep_alive off

### pure ntlm authentication
auth_param ntlm program /usr/bin/ntlm_auth --diagnostics --helper-protocol=squid-2.5-ntlmssp --domain=EXAMPLE
auth_param ntlm children 10
auth_param ntlm keep_alive off

### provide basic authentication via ldap for clients not authenticated via kerberos/ntlm
auth_param basic program /usr/local/bin/squid_ldap_auth -R -b "dc=example,dc=local" -D squid@example.local -W /etc/squid3/ldappass.txt -f sAMAccountName=%s -h dc1.example.local
auth_param basic children 10
auth_param basic realm Internet Proxy
auth_param basic credentialsttl 1 minute

### acl for proxy auth and ldap authorizations
acl auth proxy_auth REQUIRED

### enforce authentication
http_access deny !auth
http_access allow auth
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

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