WCCP (Web Cache Communication Protocol)

1. WCCPによる透過Proxy構成


WCCPv2を利用してCatalystスイッチでWeb通信を強制的にProxyサーバにリダイレクトすることにより、透過Proxy構成(複数の場合は負荷分散可能)にする。
WCCPの詳細設定は以下とする。

対象プロトコル:HTTP(80/tcp)、HTTPS(443/tcp)
WCCPタイプ:Dynamic
WCCP ID:10
転送方式:L2
負荷分散方式:MASK方式
MASK方式の対象:送信元IP
除外通信:192.168.0.0/16 → 192.168.0.0/16
対象通信:192.168.1.0/24 → Any



  • CatalystスイッチのSDMテンプレート変更
Catalyst3560/3750等のBOXスイッチでは、デフォルトでSDMテンプレートがdefaultとなっている。
このSDMテンプレートではPBRやWCCPが使用出来ないため、SDMテンプレートの変更を行う。
この時、configの保存は不要でコマンド実行後の再起動で反映される。
Switch(config)# sdm prefer routing
Switch(config)# end
Switch# reload


  • CatalystスイッチのWCCP設定
Switch(config)# ip wccp 10 redirect-list WCCP_ACCESS

Switch(config)# ip access-list extended WCCP_ACCESS
Switch(config-ext-nacl)#  deny   ip 192.168.0.0 0.0.255.255 192.168.0.0 0.0.255.255
Switch(config-ext-nacl)#  permit tcp 192.168.1.0 0.0.0.255 any eq www 443
Switch(config-ext-nacl)# !

Switch(config)# interface Vlan1
Switch(config)#  ip address 192.168.1.254 255.255.255.0
Switch(config)#  ip wccp 10 redirect in
Switch(config)# !


  • Squid Proxy Serverの準備(CentOS7)
透過Proxyサーバとして、Squid ProxyでHTTPとHTTPSを動作させるために必要な設定を行う。

基本的にはクライアントPCからの通信をiptablesでProxyの待ち受けポートに転送すればよいが、HTTPSではSquid Proxyにおいて、SSL-BUMPによる通信の暗号化、復号化の処理がクライアントPC側、及びWebサーバ側で必要になるため、Squid Proxyが認証局(CA:Certification Authority)となり、SSLサーバ証明書が動的に作成される。

  • Squid Proxyのインストール
squidをインストール後、squid -vよりWCCPの機能が有効になっているか確認する。
以下のコマンドで表示がない場合はソースコードからのBuildが必要になる。(CentOS7では問題なし!)
動作確認squidは以下のバージョンです。
Squid Cache: Version 3.5.20

[root@centos ~]# yum install squid
[root@centos ~]# squid -v grep --enable-linux-netfilter grep --enable-wccpv2


  • iptablesの設定
HTTPは8080ポートへ、HTTPSは8443ポートへ転送する。FORWARDチェーンのデフォルトポリシーがDROPの場合は追加で
FORWARDのルールが必要かも( ^ω^)・・・
[root@centos ~]# iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
[root@centos ~]# iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 8443
[root@centos ~]# iptables-save > /etc/sysconfig/iptables


  • ルート証明書の作成
秘密鍵、及びルート証明書を1つのファイルとして、PEM形式でてきとーに作成する。
※別々に分けても、Squidのhttps_port設定でkeyオプション指定すれば行けるかも( ^ω^)・・・
また、クライアントPCインストール用に、ルート証明書をDER形式に変換する。
このルート証明書をクライアントPCのブラウザに信頼されたルート証明機関としてインストールする。
インストール方法はブラウザ毎に異なるよ( ^ω^)

[root@centos ~]# mkdir /etc/squid/ssl_cert
[root@centos ~]# cd /etc/squid/ssl_cert
[root@centos ~]# chown squid:squid ./
[root@centos ~]# chmod 700 ./
[root@centos ssl_cert]# openssl req -new -newkey rsa:2048 -sha256 -days 3650 -nodes -x509 -keyout myCA.pem  -out myCA.pem
Generating a 2048 bit RSA private key
...........+++
.....................................................................................................+++
writing new private key to 'myCA.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Tokyo
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:centos.local
Email Address []:
[root@centos ssl_cert]#
[root@centos ssl_cert]# openssl x509 -in myCA.pem -outform DER -out myCA.der


  • Squid Proxy用の証明書キャッシュディレクトリ作成
SSL-BUMPにおいて、動的にサーバ証明書が作成されるため、このサーバ証明書を格納するキャッシュディレクトリを初期化、作成する。
[root@centos ssl_cert]# /usr/lib64/squid/ssl_crtd -c -s /var/lib/ssl_db
Initialization SSL db...
Done
[root@centos ssl_cert]#
[root@centos ssl_cert]# chown -R squid:squid /var/lib/ssl_db/


  • Squid Proxyの設定
WCCP用のIDは標準のweb-cache(0番)がHTTPでDstAddrのMASKしかサポートしていないため、DynamicとしてIDの10番を使用する。
この時、SrcAddr、Priority、DstPortをHTTP, HTTPSに指定することで、一つのIDでこれらの処理を行う。

[root@centos squid]# vim /etc/squid/squid.conf
http_port 8080 intercept
https_port 8443 intercept ssl-bump generate-host-certificates=on dynamic_cert_mem_cache_size=100MB cert=/etc/squid/ssl_cert/myCA.pem key=/etc/squid/ssl_cert/myCA.pem

sslcrtd_program /usr/lib64/squid/ssl_crtd -s /var/lib/ssl_db -M 100MB
sslproxy_options NO_SSLv2,NO_SSLv3,NO_TLSv1
acl step1 at_step SslBump1
ssl_bump peek step1
ssl_bump bump all

wccp2_router 192.168.254.254
wccp2_forwarding_method 2
wccp2_return_method 2
wccp2_assignment_method 2
wccp2_service dynamic 10
wccp2_service_info 10 protocol=tcp flags=src_ip_hash priority=100 ports=80,443

[root@centos squid]# 


  • WCCPの状態確認
Squid ProxyがWCCP通信を正しく行っているかを確認する。
Switch# show ip wccp 10 view
    WCCP Routers Informed of:
        10.0.0.1

    WCCP Clients Visible:
        192.168.254.1

    WCCP Clients NOT Visible:
        -none-

Switch#

タイプがDynamicでIDが10、プロトコルが6、宛先ポートが80, 443であることを確認する。
Switch# show ip wccp 10 service
WCCP service information definition:
        Type:          Dynamic
        Id:            10
        Priority:      100
        Protocol:      6
        Options:       0x00000011
        --------
            Mask/Value sets:  1
            Value elements :  64
            Dst Ports: 80 443 0 0 0 0 0 0

Switch#

WCCPクライアント(Squid Proxy)との詳細情報でMASK(0x1741)がSrcAddrになっていることを確認する。
これにより、IPv4アドレスの第3オクテットの0x17と第4オクテットの0x41とのAnd演算で負荷分散先が決定される。
(以下の例はProxyサーバが1台だけだから意味ないですが( ^ω^)・・・)
Switch# show ip wccp 10 detail
WCCP Client information:
        WCCP Client ID:          192.168.254.1
        Protocol Version:        2.0
        State:                   Usable
        Redirection:             L2
        Packet Return:           L2
        Assignment:              MASK
        Connect Time:            00:32:32
        Redirected Packets:
          Process:               0
          CEF:                   0
        GRE Bypassed Packets:
          Process:               0
          CEF:                   0
        Mask Allotment:          64 of 64 (100.00%)

        Mask  SrcAddr    DstAddr    SrcPort DstPort
        ----  -------    -------    ------- -------
        0000: 0x00001741 0x00000000 0x0000  0x0000

        Value SrcAddr    DstAddr    SrcPort DstPort
        ----- -------    -------    ------- -------
        0000: 0x00000000 0x00000000 0x0000  0x0000
        0001: 0x00000001 0x00000000 0x0000  0x0000
        0002: 0x00000040 0x00000000 0x0000  0x0000
        0003: 0x00000041 0x00000000 0x0000  0x0000
        0004: 0x00000100 0x00000000 0x0000  0x0000
        0005: 0x00000101 0x00000000 0x0000  0x0000
        0006: 0x00000140 0x00000000 0x0000  0x0000
        0007: 0x00000141 0x00000000 0x0000  0x0000
        0008: 0x00000200 0x00000000 0x0000  0x0000
        0009: 0x00000201 0x00000000 0x0000  0x0000
        0010: 0x00000240 0x00000000 0x0000  0x0000
        0011: 0x00000241 0x00000000 0x0000  0x0000
        0012: 0x00000300 0x00000000 0x0000  0x0000
        0013: 0x00000301 0x00000000 0x0000  0x0000
        0014: 0x00000340 0x00000000 0x0000  0x0000
        0015: 0x00000341 0x00000000 0x0000  0x0000
        0016: 0x00000400 0x00000000 0x0000  0x0000
        0017: 0x00000401 0x00000000 0x0000  0x0000
        0018: 0x00000440 0x00000000 0x0000  0x0000
        0019: 0x00000441 0x00000000 0x0000  0x0000
        0020: 0x00000500 0x00000000 0x0000  0x0000
        0021: 0x00000501 0x00000000 0x0000  0x0000
        0022: 0x00000540 0x00000000 0x0000  0x0000
        0023: 0x00000541 0x00000000 0x0000  0x0000
        0024: 0x00000600 0x00000000 0x0000  0x0000
        0025: 0x00000601 0x00000000 0x0000  0x0000
        0026: 0x00000640 0x00000000 0x0000  0x0000
        0027: 0x00000641 0x00000000 0x0000  0x0000
        0028: 0x00000700 0x00000000 0x0000  0x0000
        0029: 0x00000701 0x00000000 0x0000  0x0000
        0030: 0x00000740 0x00000000 0x0000  0x0000
        0031: 0x00000741 0x00000000 0x0000  0x0000
        0032: 0x00001000 0x00000000 0x0000  0x0000
        0033: 0x00001001 0x00000000 0x0000  0x0000
        0034: 0x00001040 0x00000000 0x0000  0x0000
        0035: 0x00001041 0x00000000 0x0000  0x0000
        0036: 0x00001100 0x00000000 0x0000  0x0000
        0037: 0x00001101 0x00000000 0x0000  0x0000
        0038: 0x00001140 0x00000000 0x0000  0x0000
        0039: 0x00001141 0x00000000 0x0000  0x0000
        0040: 0x00001200 0x00000000 0x0000  0x0000
        0041: 0x00001201 0x00000000 0x0000  0x0000
        0042: 0x00001240 0x00000000 0x0000  0x0000
        0043: 0x00001241 0x00000000 0x0000  0x0000
        0044: 0x00001300 0x00000000 0x0000  0x0000
        0045: 0x00001301 0x00000000 0x0000  0x0000
        0046: 0x00001340 0x00000000 0x0000  0x0000
        0047: 0x00001341 0x00000000 0x0000  0x0000
        0048: 0x00001400 0x00000000 0x0000  0x0000
        0049: 0x00001401 0x00000000 0x0000  0x0000
        0050: 0x00001440 0x00000000 0x0000  0x0000
        0051: 0x00001441 0x00000000 0x0000  0x0000
        0052: 0x00001500 0x00000000 0x0000  0x0000
        0053: 0x00001501 0x00000000 0x0000  0x0000
        0054: 0x00001540 0x00000000 0x0000  0x0000
        0055: 0x00001541 0x00000000 0x0000  0x0000
        0056: 0x00001600 0x00000000 0x0000  0x0000
        0057: 0x00001601 0x00000000 0x0000  0x0000
        0058: 0x00001640 0x00000000 0x0000  0x0000
        0059: 0x00001641 0x00000000 0x0000  0x0000
        0060: 0x00001700 0x00000000 0x0000  0x0000
        0061: 0x00001701 0x00000000 0x0000  0x0000
        0062: 0x00001740 0x00000000 0x0000  0x0000
        0063: 0x00001741 0x00000000 0x0000  0x0000


Switch#



最終更新:2017年03月03日 09:31
添付ファイル