Linuc 202 出題範囲
https://linuc.org/linuc2/range/202.html
- アジェンダ
- squid.confを編集して、Google Chromeでプロキシサーバ経由でWebアクセスできるようにする
- Squidのアクセス制限の設定方法を紹介
- プロキシ認証の設定方法を紹介
Squid 3.xの設定ファイル、用語、ユーティリティ
squid.conf
デフォルト設定だとこんな感じ。
http_access
の評価順はファーストマッチのため、ルールの記載順に注意が必要そう。
/etc/squid/squid.conf
#
# Recommended minimum configuration:
#
# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
# ACL名宣言
# ACL名宣言: ローカルネットワークの
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ポートへのリクエスト
acl SSL_ports port 443
# 一般的に使われるリクエストの接続先ポート番号のACL
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メソッドでのリクエスト
acl CONNECT method CONNECT
#
# Recommended minimum Access Permission configuration:
#
# Deny requests to certain unsafe ports
# ACL制御
# ACL「Safe_ports」で定義したポート番号以外へのアクセスを拒否
http_access deny !Safe_ports
# Deny CONNECT to other than secure SSL ports
# ACL「SSL_ports」で定義したポート番号以外でCONNECTメソッドでのアクセスを拒否
http_access deny CONNECT !SSL_ports
# Only allow cachemgr access from localhost
# managerがlocalhostからアクセスすることを許可 (ただし、managerが設定されていないため意味のない設定)
http_access allow localhost manager
# managerのアクセスを拒否
http_access deny manager
# 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
# ACL「localnet」で定義した接続元からのアクセスを許可
http_access allow localnet
# ACL「localhost」で定義した接続元からのアクセスを許可
http_access allow localhost
# And finally deny all other access to this proxy
# ルールにマッチしなかったアクセスは全て拒否
http_access deny all
# Squid normally listens to port 3128
# Squid LISTENポート番号
http_port 3128
# Uncomment and adjust the following to add a disk cache directory.
# ディスクキャッシュ
# タイプ パス 最大サイズ(MB) ディレクトリ作成時に何個まで作成するか
# 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
- キャッシュ関連のパラメータ
明示的に指定されていなければデフォルト値が適用される。
# キャッシュを利用しない文字列
hierarchy_stoplist
# キャッシュ可能な最大ファイルサイズ
maximum_object_size
# キャッシュ可能な最小ファイルサイズ
minimum_object_size
# メモリ上の最大ファイルサイズ
maximum_object_size_in_memory
# キャッシュするIPアドレス数
ipcache_size
# メモリ上のキャッシュサイズ
cache_mem 256 MB (デフォルト値)
# クライアントのアクセスログ
# squidを経由して参照したページのアクセスログ
cache_access_log
# キャッシュログ
# squidの動作ログ
cache_log
# キャッシュの保存期間
reference_age
# HTTPリクエストヘッダの最大サイズ
request_header_max_size
# HTTPリクエストボディの最大サイズ
requests_body_max_size
# レスポンスの最大ボディサイズ
reply_body_max_size
squidclient
- 普通にプロキシとして動作するかチェック
# squidclient -h <プロキシサーバIP> -p 3128 https://example.com | head
HTTP/1.1 200 OK
Accept-Ranges: bytes
Age: 333102
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Mon, 07 Sep 2020 08:38:08 GMT
ETag: "3147526947"
Expires: Mon, 14 Sep 2020 08:38:08 GMT
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
Server: ECS (sjc/4E76)
~
~
- Proxy認証の動作チェック
# squidclient -h <プロキシサーバIP> -p 3128 -u <ユーザ名> -w <パスワード> https://example.com | head
HTTP/1.1 200 OK
Accept-Ranges: bytes
Age: 333102
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Mon, 07 Sep 2020 08:38:08 GMT
ETag: "3147526947"
Expires: Mon, 14 Sep 2020 08:38:08 GMT
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
Server: ECS (sjc/4E76)
~
~
アクセス制限の方法 http_access
- http_access書式
http_access allow|deny ACL名
http_access allow localhost manager
クライアントユーザの認証方法
- squid.conf にプロキシ認証の設定追加
/etc/squid/squid.conf
# 外部の認証プログラムを参照
# /etc/squid/passwd にユーザ情報が記載されている
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
# proxy_authによるアクセス制御
acl passwd proxy_auth REQUIRED
http_access allow passwd
- htpasswdでProxy認証ユーザ作成
# htpasswd -c /etc/squid/passwd squid-paper
New password:
Re-type new password:
Adding password for user squid-paper
プロキシ認証のユーザ情報は/etc/squid/passwd
で管理される。
# cat /etc/squid/passwd
squid-paper:xxxx
Squid設定ファイルにおけるACLのレイアウトと内容
- ACL書式
acl ACL名 ACLタイプ 値
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
- ACLタイプ
src クライアントのIP
dst プロキシ先のIP
srcdomain クライアントのドメイン名
dstdomain プロキシ先のドメイン名
port プロキシ先のポート番号
myport クライアントのポート番号
arp MACアドレス
proto プロトコル
method HTTPメソッド
url_regex URLにマッチする正規表現
urlpath URLのパス部分にマッチする正規表現
- 192.168.30.2 からのプロキシを許可する例
homeというACL名を宣言した
/etc/squid/squid.conf
acl home src 192.168.30.2
http_access allow home