用Squid添加一个HTTP请求头

我想允许我的用户只为我的域名loginGoogle应用。 我通过添加HTTP头X-GoogApps-Allowed-Domains来find解决scheme,如本帮助页面所述 。

我使用Squid,但无法弄清楚如何configurationSquid来做到这一点。 我怎样才能使用Squid添加这个请求头?

    根据Squid FAQ :

    Squid.conf ACL

    通过Squid ACL修改标题仅限于删除标题或用常量stringreplace匹配的标题。

    换句话说,您将无法简单地通过使用Squid ACL来添加任意请求标头。 Squid ACL限制您删除现有的标题或replace现有的标题,但不允许添加新的标题。 添加新头文件的唯一方法是使用ICAP服务器和Squid。 有关更多信息,请参阅Squid FAQ中的ICAP部分 。

    你可以用新的Squid 3.3支持命令“request_header_add”。 我用CentOS来做。

    我的Squid.conf是:

     acl CONNECT method CONNECT visible_hostname MySERVER.local acl local src 192.168.0.0/24 http_access allow local ssl_bump client-first all always_direct allow all http_port 3128 ssl_bump generate-host-certificates=on dynamic_cert_mem_cache_size=4MB cert=/usr/local/squid/etc/cert.pem request_header_add X-GoogApps-Allowed-Domains "mycompany.com" all cache_dir ufs /usr/local/squid/var/cache 8192 32 256 

    对于SSL证书,您是否需要使用openSSL进行生成:

     openssl req -new -newkey rsa:1024 -days 36500 -nodes -x509 -keyout /usr/local/squid/etc/cert.pem -out /usr/local/squid/etc/cert.pem 

    而且,对于用户无法查看浏览器中的错误,请将其安装为每台计算机中受信任的根目录或将其添加到Active Directory(Google可能对此有所帮助)。

     openssl x509 -in /usr/local/squid/etc/cert.pem -outform DER -out /usr/local/squid/etc/cert.der 

    使用鱿鱼,你会:

    1. 设置dyanmic SSL证书生成 。 在Web客户端的浏览器中安装根证书。
    2. 设置SSL Bump拦截代理的SSL / TLSstream量 。
    3. 使用ACL来插入所需的标题 。

    显然可以用ICAP完成

    服务器: http : //icap-server.sourceforge.net/irml.html

    客户端在squid3中: http ://ftp.meisei-u.ac.jp/mirror/squid/squid-3.0-RELEASENOTES.html#ss4.1

    从上面configuration:(squid.conf)

     icap_enable on icap_service service_req reqmod_precache 1 icap://127.0.0.1:1344/request icap_service service_resp respmod_precache 0 icap://127.0.0.1:1344/response icap_class class_req service_req icap_class class_resp service_resp icap_access class_req allow all icap_access class_resp allow all 

    然后configuration服务器以确定是否修改标头或不是基于目标域:

     ????+ 

    利润? 不知道如何编写这样做的规则..也许你会有更多的运气。

    所以你可以用一个Web代理和一个ICAP服务器的组合来做到这一点。 我最熟悉ICAP的Squid Proxy&GreasySpoon。 我正在使用Squid v3.2.1和GreasySpoon 1.0.8。

    • 鱿鱼: http : //www.squid-cache.org/
    • GreasySpoon:失效! :(这个想法在其他的ICAP服务器上是一样的,只不过是用不同的impl而已,它曾经被托pipe在sourceforge上,所以也许Wayback Machine会拥有它。

    Squidconfiguration

    无论如何,configurationSquid作为一个标准的caching。 这是一个示例configuration。 有关正确的squidconfiguration的更多细节,请查看大量的文档。 你关心这个问题的部分是底部的# ICAP Configurations

     cache_effective_user squid cache_effective_group squid 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 81 # http - public 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 http_access allow manager localhost http_access deny manager http_access deny !Safe_ports http_access deny CONNECT !SSL_ports http_access deny blocksites http_access allow localnet http_access allow localhost http_access deny all http_port 3128 transparent # Leave coredumps in the first cache dir core dump_dir /var/cache/squid # ICAP Configurations icap_enable on icap_preview_enable on icap_service service_req reqmod_precache bypass=0 icap://127.0.0.1:1344/reqmod adaptation_access service_req allow all icap_service service_resp respmod_precache bypass=0 icap://127.0.0.1:1344/respmod adaptation_access service_resp allow all 

    请注意,我使用的ICAP服务器与squid代理位于同一主机上,所以我使用了127.0.0.1。 如果您的代理和ICAP在不同的主机上,那么一定要换掉其他服务器的IP或服务器名称的环回。

    ICAPconfiguration

    这是简单的部分。

    再次,我正在使用现已不存在的“油腻勺”ICAP服务器。 我发现它是非常直接的,做了我想要的最小的头痛。 另外,当其他选项可用时,我使用Java插件function。

    对于GreasySpoon来说,我只是创build了一个小的Java脚本(不是JavaScript,尽pipe这对于许多ICAP服务器来说是可能的),它以HTTP请求为目标,并添加了所需的头文件(注意前面的注释向GS服务器提供了元数据。其他人可能不需要):

     //------------------------------------------------------------------- // ==ServerScript== // @name Add_Header // @status on // @description // @include .* // @exclude // @order 0 // ==/ServerScript== // -------------------------------------------------------------------- public void main(HttpMessage httpMessage){ // Add the "my-header" header with a value of "test.server.com" httpMessage.addHeader("my-header", "test.server.com"); } 

    这将my-header头元素添加到每个请求中。

    使用Squid添加自定义标题非常困难。 我试过但失败了,但是我发现另一个解决scheme来阻止消费者帐户使用以下方法:

    1. 下载burp套装 (可以添加自定义标题的独立代理)。
    2. 阅读这篇文章我写道: http : //computech.in/2013/09/block-access-to-consumer-gmail-accounts-but-allow-google-apps/

    在一个小型组织中,我认为Burp代理更好,这就是我们目前使用的。

    您可能需要获得一个完整的商业网页filter来完成这样的工作 – 除非您想深入研究自己的ICAP内容,比如@Richard Keller似乎暗示的那样。 我为Smoothwall公司工作,他们生产一个可以完成工作的filter – 如果它真的是你需要的(即没有其他filter),请与销售人员一起检查我们,我们可以适当地进行许可。 为了公平,有竞争的产品也有这个function – YouTube也使用它。