LoginSignup
0
0

More than 1 year has passed since last update.

Oracle Cloud: Firewallの Whitelist登録でWebコンソール接続できるようにしてみてみた

Last updated at Posted at 2021-02-14

Firewall 等で、Web にアクセスできないことがあります。
ということで、Oracle Cloud Infrastructure (OCI) Console にサインインできるように、必要ドメインを Firewall へ Whitelist 登録することでアクセスできることを確認してみてみます。

ネットワークからのコンソールへのアクセスの許可
コンソールへのネットワーク・アクセスを許可するには、ネットワーク管理者がファイアウォールまたはプロキシ・サーバーの許可リストに次のURLを追加する必要があります。

許可リスト
*.oracle.com
*.oraclecloud.com
*.oracleinfinity.io
oracle.112.2o7.net
consent.trustarc.com (Console cookie preferences)

ということで、 Raspverry Piへ Squid をインストールして ホワイトリスト登録が有効かどうか、ブラウサでアクセス確認をしてみてみます。

■ 環境

構成.png

■ Squid Proxyインストール

● Raspberry Pi ログイン

[mac-book: ~]$ ssh pi@192.168.0.200
	pi@192.168.0.200's password:
	Linux raspberrypi 5.4.83-v7+ #1379 SMP Mon Dec 14 13:08:57 GMT 2020 armv7l

	The programs included with the Debian GNU/Linux system are free software;
	the exact distribution terms for each program are described in the
	individual files in /usr/share/doc/*/copyright.

	Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
	permitted by applicable law.

● apt-get update

インストール可能なパッケージリストを更新

pi@raspberrypi:~ $ sudo apt-get update
	取得:1 http://packages.microsoft.com/repos/code stable InRelease [10.4 kB]
	取得:2 http://raspbian.raspberrypi.org/raspbian buster InRelease [15.0 kB]
	取得:3 http://archive.raspberrypi.org/debian buster InRelease [32.8 kB]
	取得:4 http://packages.microsoft.com/repos/code stable/main armhf Packages [13.6 kB]
	取得:5 http://packages.microsoft.com/repos/code stable/main amd64 Packages [13.0 kB]
	取得:6 http://packages.microsoft.com/repos/code stable/main arm64 Packages [13.6 kB]
	取得:7 http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages [13.0 MB]
	取得:8 http://archive.raspberrypi.org/debian buster/main armhf Packages [360 kB]
	取得:9 http://raspbian.raspberrypi.org/raspbian buster/non-free armhf Packages [104 kB]
	13.6 MB を 25秒 で取得しました (534 kB/s)
	パッケージリストを読み込んでいます... 完了

● Squidインストール

apt-get installコマンドで Squidインストール

pi@raspberrypi:~ $ sudo apt-get install squid
	パッケージリストを読み込んでいます... 完了
	依存関係ツリーを作成しています
	状態情報を読み取っています... 完了
	以下の追加パッケージがインストールされます:
	libdbi-perl libecap3 squid-common squid-langpack
	提案パッケージ:
	libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl squidclient squid-cgi squid-purge resolvconf smbclient winbind
	以下のパッケージが新たにインストールされます:
	libdbi-perl libecap3 squid squid-common squid-langpack
	アップグレード: 0 個、新規インストール: 5 個、削除: 0 個、保留: 41 個。
	3,515 kB 中 767 kB のアーカイブを取得する必要があります。
	この操作後に追加で 14.0 MB のディスク容量が消費されます。
	続行しますか? [Y/n] Y
	取得:1 http://ftp.tsukuba.wide.ad.jp/Linux/raspbian/raspbian buster/main armhf libdbi-perl armhf 1.642-1+deb10u2 [767 kB]
	767 kB を 1秒 で取得しました (662 kB/s)
	以前に未選択のパッケージ libecap3:armhf を選択しています。
	(データベースを読み込んでいます ... 現在 163920 個のファイルとディレクトリがインストールされています。)
	.../libecap3_1.0.1-3.2+rpi1_armhf.deb を展開する準備をしています ...
	libecap3:armhf (1.0.1-3.2+rpi1) を展開しています...
	以前に未選択のパッケージ squid-langpack を選択しています。
	.../squid-langpack_20190110-1_all.deb を展開する準備をしています ...
	squid-langpack (20190110-1) を展開しています...
	以前に未選択のパッケージ squid-common を選択しています。
	.../squid-common_4.6-1+deb10u4_all.deb を展開する準備をしています ...
	squid-common (4.6-1+deb10u4) を展開しています...
	以前に未選択のパッケージ libdbi-perl:armhf を選択しています。
	.../libdbi-perl_1.642-1+deb10u2_armhf.deb を展開する準備をしています ...
	libdbi-perl:armhf (1.642-1+deb10u2) を展開しています...
	以前に未選択のパッケージ squid を選択しています。
	.../squid_4.6-1+deb10u4_armhf.deb を展開する準備をしています ...
	proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
	squid (4.6-1+deb10u4) を展開しています...
	squid-langpack (20190110-1) を設定しています ...
	libdbi-perl:armhf (1.642-1+deb10u2) を設定しています ...
	libecap3:armhf (1.0.1-3.2+rpi1) を設定しています ...
	squid-common (4.6-1+deb10u4) を設定しています ...
	squid (4.6-1+deb10u4) を設定しています ...
	Setcap worked! /usr/lib/squid/pinger is not suid!
	Created symlink /etc/systemd/system/multi-user.target.wants/squid.service → /lib/systemd/system/squid.service.
	ufw (0.36-1) のトリガを処理しています ...
	systemd (241-7~deb10u5+rpi1) のトリガを処理しています ...
	man-db (2.8.5-2) のトリガを処理しています ...
	libc-bin (2.28-10+rpi1) のトリガを処理しています ...

● squid.conf 設定

  1. オリジナルファイル・バックアップ
pi@raspberrypi:~ $ sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.org
pi@raspberrypi:~ $ ls -l /etc/squid
	合計 632
	drwxr-xr-x 2 root root   4096  2月 14 17:54 conf.d
	-rw-r--r-- 1 root root   1800  8月 26 19:35 errorpage.css
	-rw-r--r-- 1 root root 316146  8月 26 19:35 squid.conf
	-rw-r--r-- 1 root root 316146  2月 14 18:03 squid.conf.org
  1. squid.conf設定
/etc/squid/squid.conf
pi@raspberrypi:~ $ sudo vi /etc/squid/squid.conf
pi@raspberrypi:~ $ sudo cat /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 localnet src 192.168.0.0/24 # RFC1918 possible internal network

	# Connectable Ports
	acl SSL_ports port 443 #HTTPS

	# Squid normally listens to port 3128
	http_port 3128

	# Wite List
	acl whitelist dstdomain "/etc/squid/whitelist"
	http_access allow whitelist
  1. Whitelist設定
    以下ドメインを whitelistファイルへ登録
/etc/squid/whitelist
pi@raspberrypi:~ $ sudo vi /etc/squid/whitelist
pi@raspberrypi:~ $ sudo cat /etc/squid/whitelist
	.oracle.com
	.oraclecloud.com
	.oracleinfinity.io
	oracle.112.2o7.net
	consent.trustarc.com
  1. squid起動
pi@raspberrypi:~ $ sudo /etc/init.d/squid restart
	[ ok ] Restarting squid (via systemctl): squid.service.
  1. squidステータス確認
pi@raspberrypi:~ $ sudo service squid status
	● squid.service - Squid Web Proxy Server
	Loaded: loaded (/lib/systemd/system/squid.service; enabled; vendor preset: enabled)
	Active: active (running) since Sun 2021-02-14 19:08:05 JST; 49min ago
		Docs: man:squid(8)
	Process: 2864 ExecStartPre=/usr/sbin/squid --foreground -z (code=exited, status=0/SUCCESS)
	Process: 2867 ExecStart=/usr/sbin/squid -sYC (code=exited, status=0/SUCCESS)
	Main PID: 2868 (squid)
		Tasks: 4 (limit: 2063)
	CGroup: /system.slice/squid.service
			├─2868 /usr/sbin/squid -sYC
			├─2870 (squid-1) --kid squid-1 -sYC
			├─2888 (logfile-daemon) /var/log/squid/access.log
			└─2889 (pinger)

	2月 14 19:08:06 raspberrypi squid[2870]: Accepting HTTP Socket connections at local=[::]:3128 remote=[::] FD 12 flags=9
	2月 14 19:08:07 raspberrypi squid[2870]: storeLateRelease: released 0 objects
	2月 14 19:35:47 raspberrypi squid[2870]: local=192.168.0.200:3128 remote=192.168.0.2:63557 FD 26 flags=1: read/write failure: (110) Connection timed out
	2月 14 19:35:48 raspberrypi squid[2870]: local=192.168.0.200:3128 remote=192.168.0.2:63555 FD 25 flags=1: read/write failure: (110) Connection timed out
	2月 14 19:35:48 raspberrypi squid[2870]: local=192.168.0.200:3128 remote=192.168.0.2:63556 FD 28 flags=1: read/write failure: (110) Connection timed out
	2月 14 19:35:49 raspberrypi squid[2870]: local=192.168.0.200:3128 remote=192.168.0.2:63564 FD 21 flags=1: read/write failure: (110) Connection timed out
	2月 14 19:35:51 raspberrypi squid[2870]: local=192.168.0.200:3128 remote=192.168.0.2:63558 FD 11 flags=1: read/write failure: (110) Connection timed out
	2月 14 19:53:31 raspberrypi squid[2870]: Logfile: opening log stdio:/var/spool/squid/netdb.state
	2月 14 19:53:31 raspberrypi squid[2870]: Logfile: closing log stdio:/var/spool/squid/netdb.state
	2月 14 19:53:31 raspberrypi squid[2870]: NETDB state saved; 4 entries, 1 msec
  1. squid自動起動設定
pi@raspberrypi:~ $ sudo systemctl enable squid
	Synchronizing state of squid.service with SysV service script with /lib/systemd/systemd-sysv-install.
	Executing: /lib/systemd/systemd-sysv-install enable squid
  1. squid自動起動確認
pi@raspberrypi:~ $ systemctl is-enabled squid
	enabled

■ Firewall設定

Raspberry Piに Firewall UFW(Uncomplicated FireWall)インストールしてSquidに Firewallアクセスできるようにしてみてみます

● UFW(Uncomplicated FireWall)インストール

  1. UFW インストール
pi@raspberrypi:~ $ sudo apt-get install ufw
	パッケージリストを読み込んでいます... 完了
	依存関係ツリーを作成しています
	状態情報を読み取っています... 完了
	以下のパッケージが新たにインストールされます:
	ufw
	アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
	164 kB のアーカイブを取得する必要があります。
	この操作後に追加で 852 kB のディスク容量が消費されます。
	取得:1 http://ftp.tsukuba.wide.ad.jp/Linux/raspbian/raspbian buster/main armhf ufw all 0.36-1 [164 kB]
	164 kB を 2秒 で取得しました (78.9 kB/s)
	パッケージを事前設定しています ...
	以前に未選択のパッケージ ufw を選択しています。
	(データベースを読み込んでいます ... 現在 163812 個のファイルとディレクトリがインストールされています。)
	.../archives/ufw_0.36-1_all.deb を展開する準備をしています ...
	ufw (0.36-1) を展開しています...
	ufw (0.36-1) を設定しています ...

	Creating config file /etc/ufw/before.rules with new version

	Creating config file /etc/ufw/before6.rules with new version

	Creating config file /etc/ufw/after.rules with new version

	Creating config file /etc/ufw/after6.rules with new version
	Created symlink /etc/systemd/system/multi-user.target.wants/ufw.service → /lib/systemd/system/ufw.service.
	man-db (2.8.5-2) のトリガを処理しています ...
	rsyslog (8.1901.0-1) のトリガを処理しています ...
	systemd (241-7~deb10u5+rpi1) のトリガを処理しています ...


pi@raspberrypi:~ $ sudo ufw status
	Status: inactive
  1. Squid Port 3128登録
    Squidにアクセスできるよう設定
pi@raspberrypi:~ $ sudo ufw allow 3128/tcp
	Rule added
	Rule added (v6)
  1. ssh port 22 登録
    sshアクセスできるよう設定
pi@raspberrypi:~ $ sudo ufw allow 22/tcp
	Rules updated
	Rules updated (v6)
  1. UFW 有効化
pi@raspberrypi:~ $ sudo ufw enable
	Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
	Firewall is active and enabled on system startup
  1. UFW ステータス確認
pi@raspberrypi:~ $ sudo ufw status verbose
	Status: active
	Logging: on (low)
	Default: deny (incoming), allow (outgoing), disabled (routed)
	New profiles: skip

	To                         Action      From
	--                         ------      ----
	22/tcp                     ALLOW IN    Anywhere
	3128/tcp                   ALLOW IN    Anywhere
	22/tcp (v6)                ALLOW IN    Anywhere (v6)
	3128/tcp (v6)              ALLOW IN    Anywhere (v6)

■ オンプレミス Mac Book設定

● Network設定

Mac Bookへ OCIの DNSと Proxyサーバーを設定

  1. システム環境設定 画面
    ネットワークをクリック
    06_MacBookーNW設定00.png

  2. プロキシ画面
    HTTPSをチェックし、
    保護されたWebプロキシサーバー: ProxyサーバーのIPアドレス, Port番号3128を設定
    06_MacBookーNW設定02.png

● Proxy Server接続確認

[mac-book: ~]$ ping 192.168.0.200 -c 3
	PING 192.168.0.200 (192.168.0.200): 56 data bytes
	64 bytes from 192.168.0.200: icmp_seq=0 ttl=62 time=8.027 ms
	64 bytes from 192.168.0.200: icmp_seq=1 ttl=62 time=60.485 ms
	64 bytes from 192.168.0.200: icmp_seq=2 ttl=62 time=8.567 ms

	--- 192.168.0.200 ping statistics ---
	3 packets transmitted, 3 packets received, 0.0% packet loss
	round-trip min/avg/max/stddev = 8.027/25.693/60.485/24.603 ms

● OCI Private DNS接続確認

  1. nslookup確認
    Serverが Proxy Serverアドレスでgoogle.comなどへ名前解決できることを確認
[mac-book: ~]$ nslookup google.com
	Server:		192.168.0.254
	Address:	192.168.0.254#53

	Non-authoritative answer:
	Name:	google.com
	Address: 172.217.161.46

■ OCIコンソール Proxy接続確認

● oracle.com 以外接続不可能確認

Safariブラウザで、google.comなどへ接続でず、"プロキシサーバーに接続できません"と表示されることを確認
08_Browserアクセス05.png

● OCIコンソール接続確認

  1. https://cloud.oracle.com接続
    https://cloud.oracle.com へ接続しエラーなく接続できることを確認
    08_Browserアクセス01.png

  2. OCIコンソール ログイン完了
    08_Browserアクセス02.png

■ 参考

 ・OCI Documents: ネットワークからのコンソールへのアクセスの許可
 ・Oracle Cloud: Signing In to the Console
 ・Raspberry Pi: Teach, Learn, and Make with Raspberry Pi
 ・Squid Proxy: squid-cache.org
 ・UFW Firewall: ufw

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0