10
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VPN for VPC 経由でIBM Cloudサービスにプライベート接続する

Last updated at Posted at 2020-08-11

やりたいこと

IBM Cloudには Cloud Service Endpoinという、PaaSサービス(WatsonやIBM Cloud Databases)にPrivate Network経由で呼び出すことができる仕組みがあります。
このCSEを、マネージドのSite-To-Site VPNサービスであるVPN for VPC 経由で利用し、オンプレ環境からIBM CloudサービスをPrivate Networkで呼び出せるようにします。

image.png

VPC側のVPN Gatewayの設定

このページからVPN Gatewayを作成していきます。

VPN Gatewayを作成するVPCとサブネットを指定し、接続情報を入力していきます。

image.png

VPN Gatewayは、VPNサービスが作成されたZoneと同一Zone内のVSIとしか通信できません。上記の場合、jp-tok-3でVPNサービスを作成したのでjp-tok-1やjp-tok-2のVSIにはアクセスできません。Zone障害に備えるためにはZoneごとにVPN Gatewayを作成する必要があります。

image.png

  • Peer gateway address
    • オンプレ側のVPNゲートウェイのIPアドレス
  • Local subnets
    • VPNで通信させたいローカルサイトのアドレスレンジ
    • VPCで定義したサブネットと、CSEのエンドポイントである 166.8.0.0/14 を指定します
  • Peer subnets
    • VPN通信をさせるオンプレ側のアドレスレンジ

VPN Gatewayを作成すると、Floating IPが割り当てられます。

image.png

オンプレ側のVPN Gatewayの設定

今回は疑似オンプレ環境として IBM CloudのClassic Infraの仮想サーバーを利用し、VPN Gatewayとして StrongSwan を使って実施します。
他のVPN Gatewayを使う場合はこちらを参照してください。

StrongSwanの詳細な導入手順については割愛しますが、私はこのサイトを参考に導入しました。

/etc/ipsec.confファイルは、以下のように記述してください。
leftがオンプレ側、rightがVPC側です。right, rightidにはVPN Gatewayを作成されたときに割り当てられたFloating IPを書いてください。

ipsec.conf
conn all
       type=tunnel
       auto=route
       #aggressive=no
       esp=aes256-sha256!
       ike=aes128-sha1-modp1024!
       left=165.xx.xx.xx
       leftsubnet=10.193.37.176/28
       rightsubnet=10.244.128.0/24,166.8.0.0/14
       right=165.yy.yy.yy
       leftauth=psk
       rightauth=psk
       leftid="165.xx.xx.xx"
       keyexchange=ikev2
       rightid="165.yy.yy.yy"
       lifetime=10800s
       ikelifetime=36000s
       dpddelay=30s
       dpdaction=restart
       dpdtimeout=120s

/etc/ipsec.secretsにはPreshared keyをセットするのをお忘れなく。

ipsec.secrets
# This file holds shared secrets or RSA private keys for authentication.

# RSA private key for this host, authenticating it to any other host
# which knows the public part.

: RSA "server-key.pem"
user : EAP "password"
165.xx.xx.xx 165.yy.yy.yy : PSK "**********"

設定が終わったらStrongSwanを再起動すれば、VPN接続が始まります。

# ipsec restart

# ipsec status
Routed Connections:
         all{1}:  ROUTED, TUNNEL, reqid 1
         all{1}:   10.193.37.176/28 === 10.244.128.0/24 166.8.0.0/14
Security Associations (1 up, 0 connecting):
         all[13]: ESTABLISHED 5 hours ago, 165.192.80.42[165.192.80.42]...165.192.128.32[165.192.128.32]
         all{52}:  INSTALLED, TUNNEL, reqid 1, ESP in UDP SPIs: c1049b0e_i c19d8aff_o
         all{52}:   10.193.37.176/28 === 10.244.128.0/24 166.8.0.0/14

CSEを使ってIBM Cloudサービスの呼び出し

これで、オンプレ側からIBM CloudのPaaSサービスをCSEを使って呼び出せることができるようになりました。

# ping xxxxxxxxxxxxxxxxxxxxx.private.databases.appdomain.cloud
PING icd-prod-jp-tok-db-x.jp-tok.serviceendpoint.cloud.ibm.com (166.9.42.15) 56(84) bytes of data.
64 bytes from f.2a.09a6.ip4.static.sl-reverse.com (166.9.42.15): icmp_seq=1 ttl=57 time=2.52 ms
64 bytes from f.2a.09a6.ip4.static.sl-reverse.com (166.9.42.15): icmp_seq=2 ttl=57 time=2.26 ms
64 bytes from f.2a.09a6.ip4.static.sl-reverse.com (166.9.42.15): icmp_seq=3 ttl=57 time=2.39 ms
64 bytes from f.2a.09a6.ip4.static.sl-reverse.com (166.9.42.15): icmp_seq=4 ttl=57 time=2.55 ms
^C
--- icd-prod-jp-tok-db-x.jp-tok.serviceendpoint.cloud.ibm.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 2.265/2.435/2.559/0.121 ms

補足

今回は疑似オンプレ環境としてIBM Cloud のClassic Infra環境を使いましたが、デフォルトだと以下のようにService EndpointのIPアドレス(166.8.0.0/14)に対してもstatic routeが構成されており、何もしなくてもCSEにアクセスできてしまいます。なので、当該static routeは削除して上記を検証しています。

## CSEへのstatic routeの削除

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         21.50.c0a5.ip4. 0.0.0.0         UG    0      0        0 eth1
10.0.0.0        10.193.37.129   255.0.0.0       UG    0      0        0 eth0
10.193.37.128   0.0.0.0         255.255.255.192 U     0      0        0 eth0
161.26.0.0      10.193.37.129   255.255.0.0     UG    0      0        0 eth0
165.192.80.32   0.0.0.0         255.255.255.224 U     0      0        0 eth1
166.8.0.0       10.193.37.129   255.252.0.0     UG    0      0        0 eth0

# route delete -net 166.8.0.0 gw 10.193.37.129 netmask 255.252.0.0 eth0

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         21.50.c0a5.ip4. 0.0.0.0         UG    0      0        0 eth1
10.0.0.0        10.193.37.129   255.0.0.0       UG    0      0        0 eth0
10.193.37.128   0.0.0.0         255.255.255.192 U     0      0        0 eth0
161.26.0.0      10.193.37.129   255.255.0.0     UG    0      0        0 eth0
165.192.80.32   0.0.0.0         255.255.255.224 U     0      0        0 eth1
10
3
1

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
10
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?