[Oracle Cloud] Oracle Cloud(DBaaS)とAWS(EC2)をIPSec VPN(Libreswan)で繋いでみた

本文書の目的

IPSec VPNの設定手順を理解するために、IPSecによるVPNプロトコルの標準的なソフトウェアであるlibreswanを利用して、Oracle Cloud(DBaaS)とAWS(EC2)を繋ぐ手順を確認してみました。

業務環境で利用する場合には、オンプレミス側には専用ルーターを用意することが多いと思うので、実際の手順についてはマニュアルおよび該当ルーターの手順などを参考としてください。

IPSec利用時の設定の流れの理解に役立ててもらえればと思います。

 

 

前提/準備

接続に利用するOracle Cloud側のインスタンスはDBaaS(VM)、AWS側のEC2をそれぞれ作成済み。

・Oracle Cloud(DBaaS(VM))
# uname -a
Linux dbvmee02 4.1.12-124.20.3.el6uek.x86_64 #2 SMP Thu Oct 11 17:47:32 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux

・AWS(EC2)
# uname -a
Linux ip-172-31-40-70.us-east-2.compute.internal 3.10.0-957.el7.x86_64 #1 SMP Thu Oct 4 20:48:51 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

# ipsec –version
Linux Libreswan 3.25 (netkey) on 3.10.0-957.el7.x86_64

 

サポートされるIPSecパラメータ

Oracle Cloudとの接続でサポートされるIPSecパラメータはマニュアルで定義されています。

参考)
https://docs.cloud.oracle.com/iaas/Content/Network/Reference/supportedIPsecparams.htm

Supported IPSec Parameters

This topic lists the supported ISAKMP and IPSec configuration parameters for an IPSec VPN. Oracle chose these values to maximize security and to cover a wide range of CPE devices. For some parameters, Oracle supports multiple values, and the recommended one is highlighted in red italics. If your CPE device is not on the list of verified devices, use the information here to configure your device.

ISAKMP Policy Options

  • ISAKMP Protocol version 1
  • Exchange type: Main mode
  • Authentication method: pre-shared-keys
  • Encryption: AES-256-cbc, AES-192-cbc, AES-128-cbc
  • Authentication algorithm: SHA-384, SHA-256, SHA1 (also called SHA or SHA1-96)
  • Diffie-Hellman group: group 5, group 2, group 1
  • IKE session key lifetime: 28800 seconds (8 hours)

IPSec Policy Options

  • IPSec protocol: ESP, tunnel-mode
  • Encryption: AES-256-cbc, AES-192-cbc, AES-128-cbc
  • Authentication algorithm: HMAC-SHA1-96
  • IPSec session key lifetime: 3600 seconds (1 hour)
  • Perfect Forward Secrecy (PFS): enabled, group 5

さらに、マニュアルには主なルーター機器を利用した際の検証済み設定手順が記載されています。
機器の種類やバージョンの差異がある場合、必ずしもその通りに設定できるとは限らないですが、参考にするとよいと思います。

 

設定手順の概要

libreswanを利用した場合の手順もマニュアルに載っています。

基本的にマニュアルに沿って設定すればよいのですが、載っているlibreswanのバージョンとの差異のせいか、うまくいかない部分がありましたので、実際の設定に利用した設定ファイルの内容を後述します。

構成のイメージ(マニュアルより転記)

手順(タイトルはマニュアルより抜粋)

    1. [共通] Information to Gather
      構成に必要となる情報(例:IPアドレスや仮想ネットワークのCIDR)を集めます。

    2. [AWS] Start the AWS Libreswan Configuration
      yum -y install libreswan
      libreswanをインストールして、VPN接続を許可するためのEC2側の各種設定を行います。

    3. [OCI] Configure Oracle Cloud Infrastructure DRG and CPE
      次にOracle Cloud側でDRGとCPEというVPN接続用のリソースを作成し、それぞれに接続対象の仮想ネットワーク情報の登録や、VPN接続を許可するためのセキュリティリストなどの設定を行います。

    4. [AWS] Set Up Your Configuration File: /etc/ipsec.d/oci-ipsec.conf
      今回接続させたい環境に合わせてIPアドレス情報などを登録します。

    5. [AWS] Set Up Your Secrets File: /etc/ipsec.d/oci-ipsec.secrets
      Oracle Cloud側のDRGにて確認したセキュリティキー情報を登録します。

    6. [AWS] Reload the Libreswan Configuration
      service ipsec restart
      設定が正しければDRGのコネクションがUPとなるはず。

    7. [AWS] Check the Libreswan Statusipsec status
      ipsec status
      ipsec接続のステータスを確認。
      設定が正しければ「established」という文字列が確認できるはず。

    8. [AWS] Check the Tunnel Interface Status
      ifconfig
      ip route show

    9. [AWS] Configure IP Routing
      ip route add ${VcnCidrBlock} nexthop dev ${vti1} nexthop dev ${vti2}
      ip route show
      OracleCloud側の接続対象インスタンスが所属するVCN用のルーティングを設定

    10. [AWS] Test the Connection
      pingコマンドなどで疎通を確認

 

設定値サンプル

今回の検証で実際に設定した各種ファイルの設定値について紹介します(一部マスク済み)

・/etc/sysctl.conf

以下を追記
net.ipv4.ip_forward = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.eth0.send_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.eth0.accept_redirects = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.eth0.rp_filter = 0
net.ipv4.conf.ip_vti0.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
反映 
sysctl -p

 

・/etc/ipsec.conf

config setup
    plutoopts="--perpeerlog"
    protostack=auto
include /etc/ipsec.d/*.conf
# include /etc/ipsec.d/*.secrets

⇒マニュアルの記載通りだとエラーが発生したため、最終行はコメントアウト

 

・/etc/ipsec.d/ipsec_oci.secrets

<DRGのIPアドレス1> <EC2のPublic IP> : PSK "<OCIコンソールで確認したVPN用キー情報>
<DRGのIPアドレス2> <EC2のPublic IP> : PSK "<OCIコンソールで確認したVPN用キー情報>

⇒拡張子は指定だが、ファイル名は任意。

 

・/etc/ipsec.d/ipsec_oci.conf

[root@ip-172-31-40-70 ~]# vi /etc/ipsec.d/ipsec_oci.conf
conn oracle-tunnel-1
     authby=secret
     auto=start
     pfs=yes
     leftid=AAA.AAA.AAA.AAA      # OCI DRG IPSec Public IP 1
     left=AAA.AAA.AAA.AAA        # OCI DRG IPSec Public IP 1
     leftsubnet=0.0.0.0/0
     right=yyy.yyy.yyy.yyy       # AWS Libreswan VPC internal address
     rightid=zzz.zzz.zz.zzz      # AWS Libreswan VPC public address
     rightsubnet=0.0.0.0/0
     mark=10/0xffffffff          # Needs to be unique across all tunnels
     vti-interface=vti01
     vti-routing=no
     encapsulation=no
     nat-keepalive=yes
conn oracle-tunnel-2
     authby=secret
     auto=start
     pfs=yes
     leftid=BBB.BBB.BBB.BBB      # OCI DRG IPSec Public IP 2
     left=BBB.BBB.BBB.BBB        # OCI DRG IPSec Public IP 2
     leftsubnet=0.0.0.0/0
     right=yyy.yyy.yyy.yyy       # AWS Libreswan VPC internal address
     rightid=zzz.zzz.zz.zzz      # AWS Libreswan VPC public address
     rightsubnet=0.0.0.0/0
     mark=15/0xffffffff          # Needs to be unique across all tunnels
     vti-interface=vti02
     vti-routing=no
     encapsulation=no
     nat-keepalive=yes

⇒拡張子は指定だが、ファイル名は任意。

markパラメータの設定に関して、マニュアルに記載されていた値(mark=5/0xfffffff1、mark=5/0xfffffff2)を利用した場合、コネクションは有効となるが、疎通がうまくできない(pingできない)状態となったので上記の通りに変更(環境依存?)

 

・ルーティグ設定

[root@ip-172-31-40-70 ipsec.d]# ip route add <OCIのVCN CIDR> nexthop dev vti01 nexthop dev vti02
[root@ip-172-31-40-70 ipsec.d]# ip route
default via 172.31.32.1 dev eth0 proto dhcp metric 100
10.0.0.0/16
        nexthop dev vti01 weight 1
        nexthop dev vti02 weight 1
172.31.32.0/20 dev eth0 proto kernel scope link src 172.31.40.70 metric 100

⇒OCIのVCN用のルーティングを設定

 

・ipsecプロセス起動

[root@ip-172-31-40-70 ipsec.d]# systemctl start ipsec

 

・ping確認(AWS->OCI)

設定が正しければお互いのprivate IPアドレス同士で以下のようにping応答可能となる。

[root@ip-172-31-40-70 ~]# traceroute 10.0.0.13
traceroute to 10.0.0.13 (10.0.0.13), 30 hops max, 60 byte packets
 1  * * *
 2  ip-10-0-0-13.us-east-2.compute.internal (10.0.0.13)  11.425 ms !X  11.407 ms !X  11.391 ms !X

[root@ip-172-31-40-70 ~]# ping 10.0.0.13
PING 10.0.0.13 (10.0.0.13) 56(84) bytes of data.
64 bytes from 10.0.0.13: icmp_seq=1 ttl=63 time=11.6 ms
64 bytes from 10.0.0.13: icmp_seq=2 ttl=63 time=11.5 ms
64 bytes from 10.0.0.13: icmp_seq=3 ttl=63 time=11.7 ms
^C

 

・ping確認(OCI->AWS)

[root@dbvmee02 ~]# ping 172.31.40.70
PING 172.31.40.70 (172.31.40.70) 56(84) bytes of data.
64 bytes from 172.31.40.70: icmp_seq=14 ttl=63 time=11.2 ms
64 bytes from 172.31.40.70: icmp_seq=15 ttl=63 time=11.2 ms
64 bytes from 172.31.40.70: icmp_seq=16 ttl=63 time=11.2 ms
64 bytes from 172.31.40.70: icmp_seq=17 ttl=63 time=11.2 ms

 

ステータス確認例

疎通成功時の各種ステータス確認結果。

・ipsec verify

[root@ip-172-31-40-70 ipsec.d]# ipsec verify
Verifying installed system and configuration files

Version check and ipsec on-path                         [OK]
Libreswan 3.25 (netkey) on 3.10.0-957.el7.x86_64
Checking for IPsec support in kernel                    [OK]
 NETKEY: Testing XFRM related proc values
         ICMP default/send_redirects                    [OK]
         ICMP default/accept_redirects                  [OK]
         XFRM larval drop                               [OK]
Pluto ipsec.conf syntax                                 [OK]
Two or more interfaces found, checking IP forwarding    [OK]
Checking rp_filter                                      [OK]
Checking that pluto is running                          [OK]
 Pluto listening for IKE on udp 500                     [OK]
 Pluto listening for IKE/NAT-T on udp 4500              [OK]
 Pluto ipsec.secret syntax                              [OK]
Checking 'ip' command                                   [OK]
Checking 'iptables' command                             [OK]
Checking 'prelink' command does not interfere with FIPS [OK]
Checking for obsolete ipsec.conf options                [OK]

⇒全てOKとなることを確認する。

 

・ifconfig

[root@ip-172-31-40-70 ~]# ifconfig
(中略)
vti01: flags=209<UP,POINTOPOINT,RUNNING,NOARP>  mtu 8981
        tunnel   txqueuelen 1000  (IPIP Tunnel)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vti02: flags=209<UP,POINTOPOINT,RUNNING,NOARP>  mtu 8981
        tunnel   txqueuelen 1000  (IPIP Tunnel)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

⇒ipsec.confで指定した仮想インターフェースが表示されていればOK

 

・ip link show

[root@ip-172-31-40-70 ipsec.d]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 0a:25:bb:10:02:3e brd ff:ff:ff:ff:ff:ff
3: ip_vti0@NONE:  mtu 1480 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ipip 0.0.0.0 brd 0.0.0.0
4: vti01@NONE: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 8981 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/ipip 172.31.40.70 peer <OCI DRG IPSec Public IP 1>
5: vti02@NONE: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 8981 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/ipip 172.31.40.70 peer <OCI DRG IPSec Public IP 2>

⇒ipsec.confで指定した仮想インターフェースが、OCI DRGを対向としてアップしていることを確認

 

・systemctl status ipsec

[root@ip-172-31-40-70 ipsec.d]# systemctl status ipsec | grep established
Mar 10 02:25:49 ip-172-31-40-70.us-east-2.compute.internal pluto[5958]: "oracle-tunnel-1" #3: STATE_QUICK_I2: sent QI2, IPsec SA established tunnel mode {ESP=>0x4d5668a5 <0x38c9e77a xfrm=AES_CBC_128-HMAC_SHA1_96 NATOA=none NATD=none DPD=passive} 
Mar 10 02:25:49 ip-172-31-40-70.us-east-2.compute.internal pluto[5958]: "oracle-tunnel-2" #4: STATE_QUICK_I2: sent QI2, IPsec SA established tunnel mode {ESP=>0x3fc7bc44 <0x5fbba94d xfrm=AES_CBC_128-HMAC_SHA1_96 NATOA=none NATD=none DPD=passive}

⇒establishedとなっていることを確認。

 

・ipsec auto –status |grep “===”

[root@ip-172-31-40-70 ipsec.d]# ipsec auto --status |grep "==="
000 "oracle-tunnel-1": 0.0.0.0/0===172.31.40.70<172.31.40.70>[<AWSのPublic IP>]...<DRG IP1><DRG IP1>===0.0.0.0/0; erouted; eroute owner: #3
000 "oracle-tunnel-2": 0.0.0.0/0===172.31.40.70<172.31.40.70>[<AWSのPublic IP>]...<DRG IP2><DRG IP1>===0.0.0.0/0; erouted; eroute owner: #4

⇒ipsec.confのアドレス指定ミスはこのコマンド使うと分かりやすい。
有効時はステータスは「erouted」となった。

 

参考文書

・Access to Other Clouds with Libreswan

Oracle Cloud:Oracle Cloud と AWS を IPSec VPN(Libreswan)でつないでみた

libreswan.org

authby
how the two security gateways should authenticate each other; acceptable values are rsasig (the default) for RSA digital signatures based authentication, secret for shared secrets (PSK) authentication, secret|rsasig for either, never if negotiation is never to be attempted or accepted (useful for shunt-only conns), and null for null-authentication. If asymmetric authentication is requested, IKEv2 must be enabled, and the options leftauth= and rightauth= should be used instead of authby. Digital signatures are superior in every way to shared secrets. Especially IKEv1 in Aggressive Mode is vulnerable to offline dictionary attacks and is performed routinely by at least the NSA on monitored internet traffic globally. The never option is only used for connections that do not actually start an IKE negotiation, such as type=passthrough connections. The auth method null is used for “anonymous opportunistic IPsec” and should not be used for regular pre-configured IPsec VPNs.

pfs
whether Perfect Forward Secrecy of keys is desired on the connection*(Aqs keying channel (with PFS, penetration of the key-exchange protocol does not compromise keys negotiated earlier); Since there is no reason to ever refuse PFS, Libreswan will allow a connection defined with pfs=no to use PFS anyway. Acceptable values are yes (the default) and no.

mark If set, the MARK to set for the IPsec SA of this connection. The format of a CONNMARK is mark/mask. If the mask is left out, a default mask of 0xffffffff is used. A mark value of -1 means to assign a new global unique mark number for each instance of the connection. Global marks start at 1001. This option is only available on linux NETKEY/XFRM kernels. It can be used with iptables to create custom iptables rules using CONNMARK. It can also be used with Virtual Tunnel Interfaces (“VTI”) to direct marked traffic to specific vtiXX devices.

vti-interface
This option is used to create “Routing based VPNs” (as opposed to “Policy based VPNs”). It will create a new interface that can be used to route traffic in for encryption/decryption. The Virtual Tunnel Interface (“VTI”) interface name is used to for all IPsec SA*(Aqs created by this connection. This requires that the connection also enables either the mark= or mark-in= / mark-out- option(s). All traffic marked with the proper MARKs will be automatically encrypted if there is an IPsec SA policy covering the source/destination traffic. Tools such as tcpdump and iptables can be used on all cleartext pre-encrypt and post-decrypt traffic on the device. See the libreswan wiki for example configurations that use VTI. VTI interfaces are currently only supported on Linux with XFRM/NETKEY. The _updown script handles certain Linux specific interfaces settings required for proper functioning (disable_policy, rp_filter, forwarding, etc). Interface names are limited to 16 characters and may not allow all characters to be used. If marking and vti-routing=yes is used, no manual iptables should be required. However, administrators can use the iptables mangle table to mark traffic manually if desired.

vti-routing
Whether or not to add network rules or routes for IPsec SA*(Aqs to the respective VTI devices. Valid values are yes (the default) or no. When using “routing based VPNs” with a subnets policy of 0.0.0.0/0, this setting needs to set to no to prevent imploding the tunnel, and the administrator is expected to manually add ip rules and ip routes to configure what traffic must be encrypted. When set to yes, the _updown script will automatically route the leftsubnet/rightsubnet traffic into the VTI device specified with vti-interface

encapsulation
In some cases, for example when ESP packets are filtered or when a broken IPsec peer does not properly recognise NAT, it can be useful to force RFC-3948 encapsulation. In other cases, where IKE is NAT*(Aqed but ESP packets can or should flow without encapsulation, it can be useful to ignore the NAT-Traversal auto-detection. encapsulation=yes forces the NAT detection code to lie and tell the remote peer that RFC-3948 encapsulation (ESP in port 4500 packets) is required. encapsulation=no ignores the NAT detection causing ESP packets to send send without encapsulation. The default value of encapsulation=auto follows the regular outcome of the NAT auto-detection code performed in IKE. This option replaced the obsoleted forceencaps option.

nat-keepalive
whether to send any NAT-T keep-alives. These one byte packets are send to prevent the NAT router from closing its port when there is not enough traffic on the IPsec connection. Acceptable values are: yes (the default) and no.

 

 

IPSec本をいくつか読んでみようかな(メモ)

 

 

スポンサードリンク

1 Comment

  1. Howdy,

    Must say your website looks quite ok. Good job.
    However, if you want your website to be really successful, then make sure you use the best tools to optimize your online content.
    Otherwise it won’t be on the top of Google search results and no-one will know about it. I’m sure you didn’t create this website to just be online, but to attract new people/customers.

    Few months ago my friend convinced me to use tools from below article and I have to say it helped me soo much:
    https://janzac.com/resources/

    I hope it will help you as well.
    Keep up the good work and you will eventually build a big online business.
    //Lucy

Lucy へ返信する コメントをキャンセル

Your email address will not be published.


*