やりたいこと

ActiveDirectory?に参加しているユーザがどのウェブサイトにアクセスしたかをProxyログに記録できるようにする。 実装としては、kerberosのSSO(SingleSignOn?)の仕組みを利用する。 Proxy経由でアクセスする際には、本来はProxy認証が必要にもかかわらず、ユーザはそれを意識することなくProxyを利用できる。

できていないこと

ドメイン参加できない端末に対してもProxyサービスを提供したい。
kerberos認証を受けていないクライアントに対してダイアログを出して、ユーザアカウントを入力したら使えるようにしたいのだが、できていない。
最初の auth の際にSSOとしての認証を走らせようとするので、手入力してもダメなのか?

環境

Active Directoryドメイン構成

シングルフォレスト、シングルドメインの構成
virtual.prosper2.org

ADサーバ(vmwinsv01:192.168.10.250)~

WindowsServer2008R2(試用版)
ActiveDirectory?とDNSサービス稼動中

プロキシ(VMproxy01:192.168.10.233)

CentOS6.6
squid(3.1.10)

ブラウザ(192.168.10.0/24:DHCP)

WindowsXP:InternetExplorer8
Windows7:InternetExplorer11

AD登録ユーザ

oreore-t:Password0
oreore-h:Password0

作業内容

Windows Server 2008R2 でのSPN作成

対象ホストのDNSレコード登録

前方参照ゾーンに vmproxy01 を 192.168.10.233 として登録し、

にチェックを入れる。

サービス用ユーザの登録

ドメイン内のCN=Users内にサービス用ユーザ vmproxy01 を作成する。

のみを選択して作成。 パスワードの複雑さに手を加えていない場合は、 大文字小文字数字が混ざったものでないとパスワードが許可されない

SPNの作成とkeytabのエクスポート

コマンドプロンプトで以下のコマンドを実行

cd c:\users\administrator\documents
setspn -A HTTP/vmproxy01.virtual.prosper2.org vmproxy01
setspn -l vmproxy01
setspn -q HTTP/*
ktpass -princ HTTP/vmproxy01.virtual.prospre2.org@VIRTUAL.PROSPER2.ORG -pass Password0 -mapuser vmproxy01 -ptype KRB5_NT_PRINCIPAL -out HTTP.keytab
ftp vmproxy01.virtual.prosper2.org

CentOSホストの準備

リゾルバの設定でドメイン名とNSを指定

下記のようになっていればよい

[root@vmproxy01 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search virtual.prosper2.org
nameserver 192.168.10.250

もしなっていなければ、IF起動スクリプトを書き換える (/etc/resolv.confを直接書き換えても次回起動時に上書きされてしまうため)

vi /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=192.168.10.250
DOMAIN=virtual.prosper2.org

パッケージのインストール

yum iupdate
yum install squid krb5-workstation

kerberos設定ファイルの修正

[root@vmproxy01 ~]# vi /etc/krb5.conf
[logging]
 default = FILE:/var/log/krb5libs.log
 kdc = FILE:/var/log/krb5kdc.log
 admin_server = FILE:/var/log/kadmind.log

[libdefaults]
 ;default_realm = EXAMPLE.COM
 default_realm = VIRTUAL.PROSPER2.ORG ; ← 修正
 dns_lookup_realm = false
 dns_lookup_kdc = false
 ticket_lifetime = 24h
 renew_lifetime = 7d
 forwardable = true

 default_tgs_enctypes = arcfour-hmac-md5 des-cbc-md5 des-cbc-crc ; ← 追記
 default_tkt_enctypes = arcfour-hmac-md5 des-cbc-md5 des-cbc-crc ; ← 追記
 permitted_enctypes = arcfour-hmac-md5 des-cbc-md5 des-cbc-crc   ; ← 追記

[realms]
 ;EXAMPLE.COM = {
 ; kdc = kerberos.example.com
 ; admin_server = kerberos.example.com
 ;}
 VIRTUAL.PROSPER2.ORG = {                         ; ← 追記
   kdc = vmwinsv01.virtual.prosper2.org           ; ← 追記
   admin_server = vmwinsv01.virtual.prosper2.org  ; ← 追記
   default_domain = virtual.prosper2.org          ; ← 追記
 }                                                ; ← 追記

[domain_realm]
 ;.example.com = EXAMPLE.COM
 ;example.com = EXAMPLE.COM
 .virtual.prosper2.org = VIRTUAL.PROSPER2.ORG  ; ← 追記
 virtual.prosper2.org = VIRTUAL.PROSPER2.ORG   ; ← 追記

squid設定ファイルの修正

認証のための設定を追記

[root@vmproxy01 ~]# vi /etc/squid/squid.conf
auth_param negotiate program /usr/lib/squid/squid_kerb_auth -d -s HTTP/vmproxy01.virtual.prosper2.org ; ← 追加
auth_param negotiate children 10                                                                      ; ← 追加
auth_param negotiate keep_alive on                                                                    ; ← 追加
acl auth proxy_auth REQUIRED                                                                          ; ← 追加
acl whitelist  url_regex -i "/etc/squid/whitelist.txt"                                                ; ← 追加
acl clientlist src "/etc/squid/clientlist.txt"                                                        ; ← 追加
#
# 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

#
# 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 deny !clientlist                                           ; ← clientlistにないIPからは転送させない
http_access allow whitelist                                            ; ← whitelistのURLへは常時許可(ユーザ名のログは不可)
http_access deny !auth                                                 ; ← 追加
http_access allow auth                                                 ; ← 追加

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

# Squid normally listens to port 3128
http_port 3128

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

# 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

以下をファイルの最後に追記

[root@vmproxy01 ~]# vi /etc/sysconfig/squid
# default squid options
SQUID_OPTS=""

# Time to wait for Squid to shut down when asked. Should not be necessary
# most of the time.
SQUID_SHUTDOWN_TIMEOUT=100

# default squid conf file
SQUID_CONF="/etc/squid/squid.conf"

KRB5_KTNAME=/etc/squid/HTTP.keytab        ; ← 追記
export KRB5_KTNAME                        ; ← 追記

キャッシュディレクトリの構築と起動時の自動起動

squid -z 
chkconfig squid on

ポート開放など

/etc/squid/squid.confで3128ポートとした場合は、下記のようにする。

[root@vmproxy01 ~]# cat /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3128 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

その他の注意事項など

ログ表示

#tailf /var/log/squid/access.log
1430815392.539      0 192.168.10.241 TCP_DENIED/407 4805 GET http://www.prosper2.org/devwiki/skin/pukiwiki.css.php? - NONE/- text/html
1430815392.727    176 192.168.10.241 TCP_MISS/200 8995 GET http://www.prosper2.org/devwiki/skin/pukiwiki.css.php? oreore-t@VIRTUAL.PROSPER2.ORG DIRECT/59.106.13.185 text/css

リターンコード407で認証が必要とされたあとにすぐ200で正常に完了している。 上記ログはoreore-tというユーザがアクセスしたことがわかる

設定ファイルの反映

whitelist.txt,clientlist.txt は squid の通常ACLを利用しているため
テキストファイルを反映しても、設定ファイルの再読み込み(reload)をしないと 反映されない。

ログへのユーザ名表示

ユーザ名は squid.conf のhttp_access ラインで判断するため http_accessのACLにユーザ判別の
処理が含まれていないと表示することができない。
そのため、whitelistのアクセス時にはユーザ名がロギングされない。

ホワイトリストの更新

システムユーザおよび制限ユーザがアクセスできるホワイトリストはアクセスしたいURLだけでなく
同時に読み込まれるURLについても許可してあげないと、挙動がおかしくなる可能性があるので、注意
(下記コンフィグにあるように、microsoftのサイトだが、別ドメインのファイルを読んでいる)
SSOユーザは問題ないが、非SSOユーザ(ドメイン不参加:ローカルアドミンなど)だと407で弾かれるため、
バックグラウンドで動作するプログラムでは正常に動作しない可能性がある。

設定ファイル

whitelist.txt

[root@vmproxy01 ~]# cat /etc/squid/whitelist.txt
adobe.com
adobe.co.jp
adobe.jp
windowsupdate.com
windowsupdate.co.jp
microsoft.com
microsoft.co.jp
aspnetcdn.com
webtrends.com
jquery.com
msn.com
atdmt.com

clientlist.txt

[root@vmproxy01 squid]# cat /etc/squid/clientlist.txt
192.168.10.0/24
192.168.20.0/24



Counter: 9444, today: 1, yesterday: 0

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS