質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Squid

Squidは、TCP/IPネットワークでのユーザーとサーバの通信を中継するオープンソースのプロキシサーバソフト。リバースプロキシやキャッシュサーバとして使用することも可能です。

Windows 11

Windows 11は、Windows 10の後継バージョン。それまでのMetroデザインを廃止し、Fluentデザインを導入しています。スタートメニューの構成やウィンドウのデザインの変更の他、Androidアプリをネイティブに実行できます。

Q&A

解決済

1回答

2869閲覧

squidでwhitelistの設定を行いたい

morningglow

総合スコア85

Squid

Squidは、TCP/IPネットワークでのユーザーとサーバの通信を中継するオープンソースのプロキシサーバソフト。リバースプロキシやキャッシュサーバとして使用することも可能です。

Windows 11

Windows 11は、Windows 10の後継バージョン。それまでのMetroデザインを廃止し、Fluentデザインを導入しています。スタートメニューの構成やウィンドウのデザインの変更の他、Androidアプリをネイティブに実行できます。

0グッド

0クリップ

投稿2022/11/28 15:17

前提

下記の環境です
・windows11
・squidは下記のwindows console app
https://squid.diladele.com

実現したいこと

windowsでsquidを使ってwhitelistの設定を行いたいです。

設定値・発生している問題・エラーメッセージ

下記設定の場合ローカルホストからのアクセスをすべて許可にしているため、正常にリクエストが返ってきます。

squid.conf

1acl localnet src 10.0.0.0/8 # RFC1918 possible internal network 2acl localnet src 172.16.0.0/12 # RFC1918 possible internal network 3acl localnet src 192.168.0.0/16 # RFC1918 possible internal network 4acl localnet src fc00::/7 # RFC 4193 local private network range 5acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines 6 7acl SSL_ports port 443 8acl Safe_ports port 80 # http 9acl Safe_ports port 21 # ftp 10acl Safe_ports port 443 # https 11acl Safe_ports port 70 # gopher 12acl Safe_ports port 210 # wais 13acl Safe_ports port 1025-65535 # unregistered ports 14acl Safe_ports port 280 # http-mgmt 15acl Safe_ports port 488 # gss-http 16acl Safe_ports port 591 # filemaker 17acl Safe_ports port 777 # multiling http 18acl CONNECT method CONNECT 19 20http_access deny !Safe_ports 21http_access deny CONNECT !SSL_ports 22 23# ★ローカルホストからのアクセスをすべて許可 24http_access allow localhost 25 26http_access deny !localnet 27 28# ★ホワイトリストの設定 29# acl whitelist dstdomain .qiita.com 30# http_access allow whitelist 31 32# 上記以外はすべて拒否 33http_access deny all 34 35http_port 3128 36 37coredump_dir /var/cache/squid 38 39refresh_pattern ^ftp: 1440 20% 10080 40refresh_pattern ^gopher: 1440 0% 1440 41refresh_pattern -i (/cgi-bin/|\?) 0 0% 0 42refresh_pattern . 0 20% 4320 43 44dns_nameservers 8.8.8.8 208.67.222.222 45 46max_filedescriptors 3200

curlで確認結果

cmd

1C:\work>curl https://qiita.com -x http://localhost:3128 -v 2* Trying 127.0.0.1:3128... 3* Connected to localhost (127.0.0.1) port 3128 (#0) 4* allocate connect buffer 5* Establish HTTP proxy tunnel to qiita.com:443 6> CONNECT qiita.com:443 HTTP/1.1 7> Host: qiita.com:443 8> User-Agent: curl/7.83.1 9> Proxy-Connection: Keep-Alive 10> 11< HTTP/1.1 200 Connection established

上の設定の星の箇所を下記のように修正しました。
これでローカルホストのすべてのアクセスが許可せれずに、whitelistのqiitaのみアクセスができると考えているのですが、下記の結果となります。
設定値

squid.conf

1acl localnet src 10.0.0.0/8 # RFC1918 possible internal network 2acl localnet src 172.16.0.0/12 # RFC1918 possible internal network 3acl localnet src 192.168.0.0/16 # RFC1918 possible internal network 4acl localnet src fc00::/7 # RFC 4193 local private network range 5acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines 6 7acl SSL_ports port 443 8acl Safe_ports port 80 # http 9acl Safe_ports port 21 # ftp 10acl Safe_ports port 443 # https 11acl Safe_ports port 70 # gopher 12acl Safe_ports port 210 # wais 13acl Safe_ports port 1025-65535 # unregistered ports 14acl Safe_ports port 280 # http-mgmt 15acl Safe_ports port 488 # gss-http 16acl Safe_ports port 591 # filemaker 17acl Safe_ports port 777 # multiling http 18acl CONNECT method CONNECT 19 20http_access deny !Safe_ports 21http_access deny CONNECT !SSL_ports 22 23# ★ローカルホストからのアクセスをすべて許可 24# http_access allow localhost 25 26http_access deny !localnet 27 28# ★ホワイトリストの設定 29acl whitelist dstdomain .qiita.com 30http_access allow whitelist 31 32# 上記以外はすべて拒否 33http_access deny all 34 35http_port 3128 36 37coredump_dir /var/cache/squid 38 39refresh_pattern ^ftp: 1440 20% 10080 40refresh_pattern ^gopher: 1440 0% 1440 41refresh_pattern -i (/cgi-bin/|\?) 0 0% 0 42refresh_pattern . 0 20% 4320 43 44dns_nameservers 8.8.8.8 208.67.222.222 45 46max_filedescriptors 3200

実行結果

cmd

1C:\work>curl https://qiita.com -x http://localhost:3128 -v 2* Trying 127.0.0.1:3128... 3* Connected to localhost (127.0.0.1) port 3128 (#0) 4* allocate connect buffer 5* Establish HTTP proxy tunnel to qiita.com:443 6> CONNECT qiita.com:443 HTTP/1.1 7> Host: qiita.com:443 8> User-Agent: curl/7.83.1 9> Proxy-Connection: Keep-Alive 10> 11< HTTP/1.1 403 Forbidden 12< Server: squid/4.14 13< Mime-Version: 1.0 14< Date: Mon, 28 Nov 2022 15:12:29 GMT 15< Content-Type: text/html;charset=utf-8 16< Content-Length: 3389 17< X-Squid-Error: ERR_ACCESS_DENIED 0 18< Vary: Accept-Language 19< Content-Language: en 20< X-Cache: MISS from DESKTOP-DPHFI9G 21< Via: 1.1 DESKTOP-DPHFI9G (squid/4.14) 22< Connection: keep-alive 23< 24* Received HTTP code 403 from proxy after CONNECT 25* CONNECT phase completed 26* Closing connection 0 27curl: (56) Received HTTP code 403 from proxy after CONNECT

squidのログは下記の状態です

access.log

11669647778.854 6416 127.0.0.1 TCP_TUNNEL/200 211114 CONNECT qiita.com:443 - HIER_DIRECT/54.150.97.130 - ★whitelist未設定 21669648349.085 0 127.0.0.1 TCP_DENIED/403 3732 CONNECT qiita.com:443 - HIER_NONE/- text/html ★whitelist設定

基本的には初期設定なのですが、どこか悪そうな箇所やデバッグの方法等知っている方がいらっしゃいましたらご教授お願いいたします。

補足情報(FW/ツールのバージョンなど)

ここを参考に設定しました。
https://qiita.com/aiai_osaru/items/95feefe4787600b2f478

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

acl localnet に localhost (127.0.0.1) が含まれていないので、whitelist 許可の前に http_access deny !localnet で拒否されているのだと思います。
この後、localnet は特に許可されていないので、このルール自体、不要では?

やりたいことは「localhost から接続、かつ、宛先ドメインが whitelist のリクエストを許可する」ことでしょうか?
http_access allow で複数の acl を設定すると「AND」条件になります。

acl whitelist dstdomain .qiita.com http_access allow localhost whitelist http_access deny all

投稿2022/11/29 12:12

TaichiYanagiya

総合スコア12146

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

morningglow

2022/11/30 07:44

ご指摘の通りlocalnet に localhostが含まれていないことが原因でした。 追加で```acl localnet src 127.0.0.1```を追加しても、上記の回答の通りand条件でwhitelistを追加しても期待通りに、qiitaのみアクセスできることを確認しました。 大変助かりました。ご回答ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問