将Squid配置为HTTPS转发代理?


9

这是关于我的问题的一些背景:

  • 我在Heroku上运行的Web服务带有一个动态IP地址。Heroku上的静态IP不是一个选项。
  • 我需要连接到防火墙后面的外部Web服务。操作外部Web服务的人员只会将其防火墙打开到特定的静态IP。

我尝试的解决方案是在具有静态IP的单独服务器上使用Squid,将来自Heroku的请求转发到外部服务。这样,外部服务将始终看到代理服务器的静态IP,而不是Heroku服务的动态IP。

由于我的代理服务器不能依赖IP地址进行身份验证(这就是开始的问题!),因此它必须依赖用户名和密码。此外,用户名和密码不能以明文形式传输,因为如果攻击者拦截该明文,则他们可以连接到我的代理并假装是我,使用我的代理的静态IP发出出站请求,从而逃避了外部Web服务的防火墙。

因此,Squid代理必须仅接受通过HTTPS(而不是HTTP)的连接。(到外部Web服务的连接可能是HTTP或HTTPS。)

我在CentOS 6.5.x上运行Squid 3.1.10,这是我squid.conf到目前为止的事情。仅出于故障排除的目的,我已临时启用HTTP和HTTPS代理,但我只想使用HTTPS。

#
# Recommended minimum configuration:
#
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7       # RFC 4193 local private network range
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines

acl SSL_ports port 443
acl Safe_ports port 80      # http
acl Safe_ports port 21      # ftp
acl Safe_ports port 443     # https
acl Safe_ports port 70      # gopher
acl Safe_ports port 210     # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280     # http-mgmt
acl Safe_ports port 488     # gss-http
acl Safe_ports port 591     # filemaker
acl Safe_ports port 777     # multiling http
acl CONNECT method CONNECT

# Authorization

auth_param digest program /usr/lib64/squid/digest_pw_auth -c /etc/squid/squid_passwd
auth_param digest children 20 startup=0 idle=1
auth_param digest realm squid
auth_param digest nonce_garbage_interval 5 minutes
auth_param digest nonce_max_duration 30 minutes
auth_param digest nonce_max_count 50

acl authenticated proxy_auth REQUIRED

#
# Recommended minimum Access Permission configuration:
#
# Only allow cachemgr access from localhost
http_access allow manager localhost
http_access deny manager

# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost

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

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
#http_access allow localnet
#http_access allow localhost
http_access allow authenticated

# And finally deny all other access to this proxy
http_access deny all

# Squid normally listens to port 3128
http_port 3128

https_port 3129 cert=/etc/squid/ssl/cert.pem key=/etc/squid/ssl/key.pem

# We recommend you to use at least the following line.
hierarchy_stoplist cgi-bin ?

# Disable all caching
cache deny all

# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /var/spool/squid 100 16 256

# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid

# Add any of your own refresh_pattern entries above these.
refresh_pattern ^ftp:       1440    20% 10080
refresh_pattern ^gopher:    1440    0%  1440
refresh_pattern -i (/cgi-bin/|\?) 0 0%  0
refresh_pattern .       0   20% 4320

使用此设置,HTTP代理可以正常工作,但HTTPS代理不能。

这是来自本地设备的HTTP代理请求:

$ curl --proxy http://my-proxy-server.example:3128 \
  --proxy-anyauth --proxy-user redacted:redacted -w '\n' \
  http://urlecho.appspot.com/echo?body=OK
OK

好,那是我所期望的。结果在一行/var/log/squid/access.log

1390250715.137     41 my.IP.address.redacted TCP_MISS/200 383 GET http://urlecho.appspot.com/echo? redacted DIRECT/74.125.142.141 text/html

这是另一个请求,这次使用HTTPS:

$ curl --proxy https://my-proxy-server.example:3129 \
  --proxy-anyauth --proxy-user redacted:redacted -w '\n' \
  http://urlecho.appspot.com/echo?body=OK

curl: (56) Recv failure: Connection reset by peer

access.log此之后什么都没有,但是在cache.log

2014/01/20 20:46:15| clientNegotiateSSL: Error negotiating SSL connection on FD 10: error:1407609C:SSL routines:SSL23_GET_CLIENT_HELLO:http request (1/-1)

更详细地说,这是上面的内容:

$ curl -v --proxy https://my-proxy-server.example:3129 \
  --proxy-anyauth --proxy-user redacted:redacted -w '\n' \
  http://urlecho.appspot.com/echo?body=OK
* Adding handle: conn: 0x7f9a30804000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7f9a30804000) send_pipe: 1, recv_pipe: 0
* About to connect() to proxy my-proxy-server.example port 3129 (#0)
*   Trying proxy.server.IP.redacted...
* Connected to my-proxy-server.example (proxy.server.IP.redacted) port 3129 (#0)
> GET http://urlecho.appspot.com/echo?body=OK HTTP/1.1
> User-Agent: curl/7.30.0
> Host: urlecho.appspot.com
> Accept: */*
> Proxy-Connection: Keep-Alive
> 
* Recv failure: Connection reset by peer
* Closing connection 0

curl: (56) Recv failure: Connection reset by peer

看起来像是SSL错误。但是,我正在重用一个子域通配符SSL证书,在上面的配置中显示为cert.pemkey.pem,该证书已成功部署在其他Web服务器上。此外,使用curl直接访问代理服务器是可行的,或者至少在SSL阶段之后建立了连接:

$ curl https://my-proxy-server.example:3129
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ERROR: The requested URL could not be retrieved</title>

[--SNIP--]

<div id="content">
<p>The following error was encountered while trying to retrieve the URL: <a href="https://serverfault.com/">/</a></p>

<blockquote id="error">
<p><b>Invalid URL</b></p>
</blockquote>

<p>Some aspect of the requested URL is incorrect.</p>

<p>Some possible problems are:</p>
<ul>
<li><p>Missing or incorrect access protocol (should be <q>http://</q> or similar)</p></li>
<li><p>Missing hostname</p></li>
<li><p>Illegal double-escape in the URL-Path</p></li>
<li><p>Illegal character in hostname; underscores are not allowed.</p></li>
</ul>

[--SNIP--]

有什么想法我做错了吗?我正在尝试的可能吗?提前致谢。


2
我不认为鱿鱼应该这样工作。我应该能够通过HTTPS连接发出HTTP或HTTPS请求。我在文档中没有看到任何其他建议。无论如何,无论如何我都尝试了您的建议,但没有成功(与上述结果相同)。
大卫

我之前的评论是对另一个用户似乎已删除的评论的答复。只是想注意一下,我将此问题交叉发布到了Squid邮件列表中:mail-archive.com/squid-users@squid-cache.org/msg93592.html
David

作为具有类似情况的人,我们尝试了代理方法,成功了,然后倾向于将应用程序从Heroku移到具有静态IP的虚拟机/专用机之类的提供程序中。为此目的,维护转发代理服务器会产生额外的开销。
Shyam Sundar CS

Answers:


1

@David,根据您在Squid ML中线程 -我建议使用Stunnel解决方案。您的身份验证将是隧道两端的SSL证书,其余的将成为该隧道内的“明文”,或者您可以根据需要执行Digest。

我使用了类似的解决方案来“认证” NFS端点,并取得了巨大的成功。

可以在LinuxGazette的通道安全通信中看到这种身份验证的示例用法


1

您可以在这个小的Docker映像中看到它是如何完成的:yegor256 / squid-proxy。您的代码存在的问题是配置在acl指令之后进行。只需交换它们,一切就开始起作用。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.