【AWS】統合脅威管理「Sophos UTM」を使ってVPCへSSL-VPN接続する(Ubuntu編&自動接続)#Sophos

2015.10.31

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは、コカコーラ好きなカジです。

本日は統合脅威管理「Sophos UTM」のSSL-VPNを用いてUbuntuからのリモートアクセスを試してみたいと思います。 過去弊社のブログでWindows/MacOS/iPhone/AndroidからのVPN接続方法を紹介しておりましたが、Ubuntuの接続手順が無かったので追加記事を作成しました。 また、以前Windowsの自動VPN接続を紹介しましたが、Ubuntuの自動VPN接続も紹介します。

前提条件

【AWS】統合脅威管理「Sophos UTM」を使ってVPCへSSL-VPN接続する(Windows7編)

上記ページのSophos UTM側にて「SSL-VPN接続設定」まで完了していることが前提となります。

VPN設定ファイルのダウンロード

Webブラウザを起動し、SophosのグローバルIP(EIP)にHTTPSで接続してユーザーポータル画面を開きます。「セキュリティ証明書が信頼できない」というメッセージがでますが「続ける」をクリックします。ユーザーとパスワードを入力してログインします。 画面上部の「リモートアクセス」をクリックします。

sophos-ssl-vpn-mac-os-04

画面中央にLinux、Mac OS X、BSD、Solaris環境の設定があります。接続に必要なソフトウェアと設定を一括インストールできるzipファイルが提供されていますのでダウンロードします。

sophos-ssl-vpn-mac-os-06

Ubuntuからの接続

SSL-VPN ClientのUbuntuは、以下のAMIで構築し検証しました。

ubuntu-precise-12.04-amd64-server-20150930 (ami-0ec1580e)

パブリックIPを付与されるようLaunch設定しておきます。

OpenVPNとunzipのインストール

ubuntu@ip-10-10-10-32:~$ sudo apt-get install openvpn
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
liblzo2-2 libpkcs11-helper1
The following NEW packages will be installed:
liblzo2-2 libpkcs11-helper1 openvpn
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 551 kB of archives.
After this operation, 1,398 kB of additional disk space will be used.
Do you want to continue [Y/n]? Y
<省略>
Processing triggers for man-db ...
Processing triggers for ureadahead ...
Setting up liblzo2-2 (2.06-1ubuntu0.1) ...
Setting up libpkcs11-helper1 (1.09-1) ...
Setting up openvpn (2.2.1-8ubuntu1.4) ...
* Restarting virtual private network daemon(s)...
* No VPN is running.
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
ubuntu@ip-10-10-10-32:~$

ubuntu@ip-10-10-10-32:~$ sudo apt-get install unzip
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
zip
The following NEW packages will be installed:
unzip
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 194 kB of archives.
After this operation, 386 kB of additional disk space will be used.
Get:1 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu/ precise-updates/main unzip amd64 6.0-4ubuntu2.3 [194 kB]
Fetched 194 kB in 0s (7,146 kB/s)
Selecting previously unselected package unzip.
(Reading database ... 47714 files and directories currently installed.)
Unpacking unzip (from .../unzip_6.0-4ubuntu2.3_amd64.deb) ...
Processing triggers for man-db ...
Setting up unzip (6.0-4ubuntu2.3) ...
ubuntu@ip-10-10-10-32:~$

設定ファイルのインストール

上記「VPN設定ファイルのダウンロード」でダウンロードしたものをUbuntuへscpで転送します。 解凍後、/etc/openvpnへ各ファイルを配置します。

ubuntu@ip-10-10-10-32:~$ ls -ltr
total 8
-rw-r----- 1 ubuntu ubuntu 7762 Oct 27 10:36 sslvpn_conf_cm-kaji@sophos.example.co.jp.zip
ubuntu@ip-10-10-10-32:~$ ls -ltr
ubuntu@ip-10-10-10-32:~$ unzip sslvpn_conf_cm-kaji@sophos.example.co.jp.zip
Archive: sslvpn_conf_cm-kaji@sophos.example.co.jp.zip
creating: config/
creating: config/cm-kaji@sophos.example.co.jp/
inflating: config/cm-kaji@sophos.example.co.jp/cm-kaji@sophos.example.co.jp.ovpn
inflating: config/cm-kaji@sophos.example.co.jp/sophos.example.co.jp.ca.crt
inflating: config/cm-kaji@sophos.example.co.jp/sophos.example.co.jp.user.crt
inflating: config/cm-kaji@sophos.example.co.jp/sophos.example.co.jp.user.key
ubuntu@ip-10-10-10-32:~$
ubuntu@ip-10-10-10-32:~$
ubuntu@ip-10-10-10-32:~$ cd config/cm-kaji@sophos.example.co.jp
ubuntu@ip-10-10-10-32:~/config/cm-kaji@sophos.example.co.jp$ ls -ltr
total 24
-rw------- 1 ubuntu ubuntu 1708 Oct 27 2015 sophos.example.co.jp.user.key
-rw-r--r-- 1 ubuntu ubuntu 5040 Oct 27 2015 sophos.example.co.jp.user.crt
-rw-r--r-- 1 ubuntu ubuntu 4376 Oct 27 2015 sophos.example.co.jp.ca.crt
-rw-r--r-- 1 ubuntu ubuntu 654 Oct 27 2015 cm-kaji@sophos.example.co.jp.ovpn
ubuntu@ip-10-10-10-32:~/config/cm-kaji@sophos.example.co.jp$ cp -ip sophos.example.co.jp.* /etc/openvpn/
ubuntu@ip-10-10-10-32:~/config/cm-kaji@sophos.example.co.jp$ cp -ip cm-kaji@sophos.example.co.jp.ovpn /etc/openvpn
ubuntu@ip-10-10-10-32:~/config/cm-kaji@sophos.example.co.jp$ cd /etc/openvpn/
ubuntu@ip-10-10-10-32:/etc/openvpn$ ls -ltr
total 40
-rwxr-xr-x 1 root root 1357 Dec 1 2014 update-resolv-conf
-rw-r--r-- 1 ubuntu ubuntu 810 Oct 27 11:00 sophos.example.co.jp.conf
-rw------- 1 ubuntu ubuntu 1708 Oct 27 2015 sophos.example.co.jp.user.key
-rw-r--r-- 1 ubuntu ubuntu 5040 Oct 27 2015 sophos.example.co.jp.user.crt
-rw-r--r-- 1 ubuntu ubuntu 4376 Oct 27 2015 sophos.example.co.jp.ca.crt
-rw-r--r-- 1 ubuntu ubuntu 654 Oct 27 2015 cm-kaji@sophos.example.co.jp.ovpn
ubuntu@ip-10-10-10-32:/etc/openvpn$

ubuntu環境のOpenVPN用に設定ファイルを修正

設定のバックアップ

ubuntu@ip-10-10-10-32:/etc/openvpn$ cp -ip cm-kaji@sophos.example.co.jp.ovpn sophos.example.co.jp.ovpn

設定ファイルの修正

ubuntu@ip-10-10-10-32:/etc/openvpn$ vi sophos.example.co.jp.ovpn

一番最初の行へ以下を追加(DNS設定の反映に必要)

script-security 2
up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf

以下のファイルパスを修正

ca /etc/openvpn/sophos.example.co.jp.ca.crt
cert /etc/openvpn/sophos.example.co.jp.user.crt
key /etc/openvpn/sophos.example.co.jp.user.key

自動接続したい場合は、以下の後半を追記 ご注意:お客様責任でご利用ください。 コンピュータ上のプレーンテキストで接続用のパスワードを格納するため、セキュリティ上のリスクを許容可能なことをご確認上利用ください。

auth-user-pass /etc/openvpn/userpass.txt

修正箇所の確認

ubuntu@ip-10-10-10-32:/etc/openvpn$ diff sophos.example.co.jp.ovpn cm-kaji@sophos.example.co.jp.ovpn
1,3c1
< script-security 2
< up /etc/openvpn/update-resolv-conf
< down /etc/openvpn/update-resolv-conf --- >
17,20c15,18
< ca /etc/openvpn/sophos.example.co.jp.ca.crt
< cert /etc/openvpn/sophos.example.co.jp.user.crt
< key /etc/openvpn/sophos.example.co.jp.user.key
< auth-user-pass /etc/openvpn/userpass.txt --- > ca sophos.example.co.jp.ca.crt
> cert sophos.example.co.jp.user.crt
> key sophos.example.co.jp.user.key
> auth-user-pass

自動接続用の認証ファイル作成

ご注意:お客様責任でご利用ください。 コンピュータ上のプレーンテキストで接続用のパスワードを格納するため、セキュリティ上のリスクを許容可能なことをご確認上利用ください。

ubuntu@ip-10-10-10-32:/etc/openvpn$ ls /etc/openvpn/userpass.txt
/etc/openvpn/userpass.txt
ubuntu@ip-10-10-10-32:/etc/openvpn$ cat /etc/openvpn/userpass.txt
cm-kaji <- ユーザ名
XXXXXXXXXX <-パスワード

接続テスト

sudo openvpn --config <ovpnファイル名>で接続テストします。

ubuntu@ip-10-10-10-32:/etc/openvpn$ sudo openvpn --config "/etc/openvpn/sophos.example.co.jp.ovpn"

Tue Oct 27 11:37:30 2015 OpenVPN 2.2.1 x86_64-linux-gnu [SSL] [LZO2] [EPOLL] [PKCS11] [eurephia] [MH] [PF_INET6] [IPv6 payload 20110424-2 (2.2RC2)] built on Dec 1 2014
Tue Oct 27 11:37:30 2015 WARNING: file '/etc/openvpn/userpass.txt' is group or others accessible
Tue Oct 27 11:37:30 2015 WARNING: Make sure you understand the semantics of --tls-remote before using it (see the man page).
Tue Oct 27 11:37:30 2015 NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
Tue Oct 27 11:37:30 2015 LZO compression initialized
Tue Oct 27 11:37:30 2015 Control Channel MTU parms [ L:1560 D:140 EF:40 EB:0 ET:0 EL:0 ]
Tue Oct 27 11:37:30 2015 Socket Buffers: R=[87380->131072] S=[16384->131072]
Tue Oct 27 11:37:30 2015 Data Channel MTU parms [ L:1560 D:1450 EF:60 EB:135 ET:0 EL:0 AF:3/1 ]
Tue Oct 27 11:37:30 2015 Local Options hash (VER=V4): 'bc07730e'
Tue Oct 27 11:37:30 2015 Expected Remote Options hash (VER=V4): 'b695cb4a'
Tue Oct 27 11:37:30 2015 Attempting to establish TCP connection with [AF_INET]xxx.xxx.xxx.xxx:443 [nonblock]
Tue Oct 27 11:37:31 2015 TCP connection established with [AF_INET]xxx.xxx.xxx.xxx:443
Tue Oct 27 11:37:31 2015 TCPv4_CLIENT link local: [undef]
Tue Oct 27 11:37:31 2015 TCPv4_CLIENT link remote: [AF_INET]xxx.xxx.xxx.xxx:443
Tue Oct 27 11:37:31 2015 TLS: Initial packet from [AF_INET]xxx.xxx.xxx.xxx:443, sid=5ca76656 4d0099c8
Tue Oct 27 11:37:31 2015 WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this
Tue Oct 27 11:37:31 2015 VERIFY OK: depth=1, /C=jp/L=Tokyo/O=M3_Inc./CN=M3_Inc._VPN_CA/emailAddress=admin@example.co.jp
Tue Oct 27 11:37:31 2015 VERIFY X509NAME OK: /C=jp/L=Tokyo/O=M3_Inc./CN=sophos.example.co.jp/emailAddress=admin@example.co.jp
Tue Oct 27 11:37:31 2015 VERIFY OK: depth=0, /C=jp/L=Tokyo/O=M3_Inc./CN=sophos.example.co.jp/emailAddress=admin@example.co.jp
Tue Oct 27 11:37:32 2015 Data Channel Encrypt: Cipher 'AES-128-CBC' initialized with 128 bit key
Tue Oct 27 11:37:32 2015 Data Channel Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Tue Oct 27 11:37:32 2015 Data Channel Decrypt: Cipher 'AES-128-CBC' initialized with 128 bit key
Tue Oct 27 11:37:32 2015 Data Channel Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Tue Oct 27 11:37:32 2015 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 2048 bit RSA
Tue Oct 27 11:37:32 2015 [sophos.example.co.jp] Peer Connection Initiated with [AF_INET]xxx.xxx.xxx.xxx:443
Tue Oct 27 11:37:34 2015 SENT CONTROL [sophos.example.co.jp]: 'PUSH_REQUEST' (status=1)
Tue Oct 27 11:37:34 2015 PUSH: Received control message: 'PUSH_REPLY,route 10.242.2.1,topology net30,ping 10,ping-restart 120,route 10.11.0.0 255.255.0.0,dhcp-option DNS 10.11.0.2,ifconfig 10.242.2.10 10.242.2.9'
Tue Oct 27 11:37:34 2015 OPTIONS IMPORT: timers and/or timeouts modified
Tue Oct 27 11:37:34 2015 OPTIONS IMPORT: --ifconfig/up options modified
Tue Oct 27 11:37:34 2015 OPTIONS IMPORT: route options modified
Tue Oct 27 11:37:34 2015 OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified
Tue Oct 27 11:37:34 2015 ROUTE default_gateway=10.10.10.1
Tue Oct 27 11:37:34 2015 TUN/TAP device tun0 opened
Tue Oct 27 11:37:34 2015 TUN/TAP TX queue length set to 100
Tue Oct 27 11:37:34 2015 do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0
Tue Oct 27 11:37:34 2015 /sbin/ifconfig tun0 10.242.2.10 pointopoint 10.242.2.9 mtu 1500
Tue Oct 27 11:37:34 2015 /etc/openvpn/update-resolv-conf tun0 1500 1560 10.242.2.10 10.242.2.9 init
dhcp-option DNS 10.11.0.2
Tue Oct 27 11:37:38 2015 /sbin/route add -net xxx.xxx.xxx.xxx netmask 255.255.255.255 gw 10.10.10.1
Tue Oct 27 11:37:38 2015 /sbin/route add -net 10.242.2.1 netmask 255.255.255.255 gw 10.242.2.9
Tue Oct 27 11:37:38 2015 /sbin/route add -net 10.11.0.0 netmask 255.255.0.0 gw 10.242.2.9
Tue Oct 27 11:37:38 2015 Initialization Sequence Completed

エラーがないことを確認。
Ctrl + Cで停止

OpenVPNの自動起動設定

Linux版のOpenVPNで、自動起動するには、ovpnファイルをconfファイルにする必要があるため、コピーします。

ubuntu@ip-10-10-10-32:/etc/openvpn$ pwd
/etc/openvpn
ubuntu@ip-10-10-10-32:/etc/openvpn$
ubuntu@ip-10-10-10-32:/etc/openvpn$ cp -ip sophos.example.co.jp.ovpn sophos.example.co.jp.conf

/etc/default/openvpnの「AUTOSTART="all"」のコメントを外す。

ubuntu@ip-10-10-10-32:/etc/openvpn$ sudo cat /etc/default/openvpn
# This is the configuration file for /etc/init.d/openvpn

#
# Start only these VPNs automatically via init script.
# Allowed values are "all", "none" or space separated list of
# names of the VPNs. If empty, "all" is assumed.
# The VPN name refers to the VPN configutation file name.
# i.e. "home" would be /etc/openvpn/home.conf
#
AUTOSTART="all"
#AUTOSTART="none"
#AUTOSTART="home office"
#
# Refresh interval (in seconds) of default status files
# located in /var/run/openvpn.$NAME.status
# Defaults to 10, 0 disables status file generation
#
#STATUSREFRESH=10
#STATUSREFRESH=0
# Optional arguments to openvpn's command line
OPTARGS=""
#
# If you need openvpn running after sendsigs, i.e.
# to let umountnfs work over the vpn, set OMIT_SENDSIGS
# to 1 and include umountnfs as Required-Stop: in openvpn's
# init.d script (remember to run insserv after that)
#
OMIT_SENDSIGS=0
ubuntu@ip-10-10-10-32:/etc/openvpn$

OS再起動し、自動接続されることを確認。

ubuntu@ip-10-10-10-32:/etc/openvpn$ ps -ef | grep openvpn
root 1510 1 0 11:41 ? 00:00:00 /usr/sbin/openvpn --writepid /var/run/openvpn.sophos.example.co.jp.pid --daemon ovpn-sophos.example.co.jp --status /var/run/openvpn.sophos.example.co.jp.status 10 --cd /etc/openvpn --config /etc/openvpn/sophos.example.co.jp.conf

ubuntu@ip-10-10-10-32:~$ ifconfig tun0
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.242.2.10 P-t-P:10.242.2.9 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:1261 (1.2 KB) TX bytes:761 (761.0 B)

ubuntu@ip-10-10-10-32:~$ netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.10.10.1 0.0.0.0 UG 0 0 0 eth0
10.10.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.11.0.0 10.242.2.9 255.255.0.0 UG 0 0 0 tun0
10.242.2.1 10.242.2.9 255.255.255.255 UGH 0 0 0 tun0
10.242.2.9 0.0.0.0 255.255.255.255 UH 0 0 0 tun0
xxx.xxx.xxx.xxx 10.10.10.1 255.255.255.255 UGH 0 0 0 eth0
ubuntu@ip-10-10-10-32:~$

まとめ

簡単そうに見えますよね。ですが、DNSの設定が有効にならずに私はハマってしまいました。 ovpnファイル(confファイル)に3行追加が必要なことは今回初めて知りましたのでどなたかのお役に立てれば光栄です。

参考元

Starting openvpn client automatically at boot

How to accept DNS push on Linux systems with resolvconf