今回は AmazonLinux2 上に LDAP 認証を行う Squid (プロキシ) のインストール方法をメモします。 LDAP は特定グループに所属するメンバーで認証します。
インストール
yum
でインストールします。
yum -y install httpd-tools squid
以下のバージョンがインストールされました。
# yum info httpd-tools squid Loaded plugins: extras_suggestions, langpacks, priorities, update-motd Installed Packages Name : httpd-tools Arch : x86_64 Version : 2.4.41 Release : 1.amzn2.0.1 Size : 168 k Repo : installed From repo : amzn2-core Summary : Tools for use with the Apache HTTP Server URL : https://httpd.apache.org/ License : ASL 2.0 Description : The httpd-tools package contains tools which can be used with : the Apache HTTP Server. Name : squid Arch : x86_64 Epoch : 7 Version : 3.5.20 Release : 12.amzn2 Size : 10 M Repo : installed From repo : amzn2-core Summary : The Squid proxy caching server URL : http://www.squid-cache.org License : GPLv2+ and (LGPLv2+ and MIT and BSD and Public Domain) Description : Squid is a high-performance proxy caching server for Web clients, : supporting FTP, gopher, and HTTP data objects. Unlike traditional : caching software, Squid handles all requests in a single, : non-blocking, I/O-driven process. Squid keeps meta data and especially : hot objects cached in RAM, caches DNS lookups, supports non-blocking : DNS lookups, and implements negative caching of failed requests. : : Squid consists of a main server program squid, a Domain Name System : lookup program (dnsserver), a program for retrieving FTP data : (ftpget), and some management and client tools.
インストールされた Squid のビルドオプションは以下でした。
# squid -v Squid Cache: Version 3.5.20 Service Name: squid configure options: '--build=x86_64-koji-linux-gnu' '--host=x86_64-koji-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-strict-error-checking' '--exec_prefix=/usr' '--libexecdir=/usr/lib64/squid' '--localstatedir=/var' '--datadir=/usr/share/squid' '--sysconfdir=/etc/squid' '--with-logdir=$(localstatedir)/log/squid' '--with-pidfile=$(localstatedir)/run/squid.pid' '--disable-dependency-tracking' '--enable-eui' '--enable-follow-x-forwarded-for' '--enable-auth' '--enable-auth-basic=DB,LDAP,MSNT-multi-domain,NCSA,NIS,PAM,POP3,RADIUS,SASL,SMB,SMB_LM,getpwnam' '--enable-auth-ntlm=smb_lm,fake' '--enable-auth-digest=file,LDAP,eDirectory' '--enable-auth-negotiate=kerberos' '--enable-external-acl-helpers=file_userip,LDAP_group,time_quota,session,unix_group,wbinfo_group,kerberos_ldap_group' '--enable-cache-digests' '--enable-cachemgr-hostname=localhost' '--enable-delay-pools' '--enable-epoll' '--enable-ident-lookups' '--enable-linux-netfilter' '--enable-removal-policies=heap,lru' '--enable-snmp' '--enable-ssl-crtd' '--enable-storeio=aufs,diskd,rock,ufs' '--enable-wccpv2' '--enable-esi' '--enable-ecap' '--with-aio' '--with-default-user=squid' '--with-dl' '--with-openssl' '--with-pthreads' '--disable-arch-native' 'build_alias=x86_64-koji-linux-gnu' 'host_alias=x86_64-koji-linux-gnu' 'CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fpie' 'LDFLAGS=-Wl,-z,relro -pie -Wl,-z,relro -Wl,-z,now' 'CXXFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fpie' 'PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig'
設定ファイルの修正
Squid の設定ファイルは /etc/squid/squid.conf
です。 これを以下のように修正します。 各パラメータには必要に応じて修正します。
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 auth_param basic program /usr/lib64/squid/basic_ldap_auth -P -R -b "DC=example,DC=com" -D "CN=Administrator,CN=Users,DC=example,DC=com" -w "PASSWORD" -f "(&(objectCategory=Person)(sAMAccountName=%s)(memberOf=CN=Members,OU=Groups,DC=example,DC=com))" ldap.example.com auth_param basic children 20 auth_param basic realm Authentication auth_param basic credentialsttl 8 hour acl ldap-auth proxy_auth REQUIRED http_access allow ldap-auth http_access allow localhost http_access deny all no_cache deny all http_port 3128 cache_store_log none coredump_dir /var/spool/squid refresh_pattern -i (/cgi-bin/|\?) 0 0% 0 ipcache_size 5120
起動&自動起動の設定
systemctl enable squid systemctl start squid
これで Squid のインストールは完了です。
Chrome にプロキシ接続用プラグインをインストールする
実際に Squid 経由で通信するにはシステム全体でプロキシ設定しても良いですが、「特定サイトだけプロキシを利用する」といった場合はブラウザのプラグインを利用した方が便利かも知れません。 今回は Chrome の Proxy SwithySharp プラグインを利用してみます。 まず最初に Chrome ウェブストアからプラグインを探し、インストールします。
プラグインのオプション画面を開き、設定していきます。 まず、Proxy Profiles
タブからプロファイルと、接続するプロキシサーバを設定します。
次に Switch Rules
タブで「どの URL へアクセスする時に・どのプロファイルを利用するか」というルールを設定しておきます。
最後にプラグインを Auto Switch Mode
に設定し、完了です。 Auto Switch Mode
に設定することで Switch Rules
に設定したルールに従ってプロファイルを自動的に切り替えてくれます。
参考
Squid の初期コンフィグ (コメント除外バージョン)
# grep -v -e '^\s*#' -e '^\s*$' /etc/squid/squid.conf 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 http_access deny !Safe_ports http_access deny CONNECT !SSL_ports http_access allow localhost manager http_access deny manager http_access allow localnet http_access allow localhost http_access deny all http_port 3128 coredump_dir /var/spool/squid 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