OSSのIPsec VPN「libreswan」でオンプレミスとクラウドのハイブリッド構成を実現する!(1/2)

◆ Live配信スケジュール ◆
サイオステクノロジーでは、Microsoft MVPの武井による「わかりみの深いシリーズ」など、定期的なLive配信を行っています。
⇒ 詳細スケジュールはこちらから
⇒ 見逃してしまった方はYoutubeチャンネルをご覧ください
【5/21開催】Azure OpenAI ServiceによるRAG実装ガイドを公開しました
生成AIを活用したユースケースで最も一番熱いと言われているRAGの実装ガイドを公開しました。そのガイドの紹介をおこなうイベントです!!
https://tech-lab.connpass.com/event/315703/

こんにちは。技術部の髙岡です。

先日、オンプレのサーバとAzure上のサーバ間の通信をIPSecで暗号化することが必要となりました。
その際には、オンプレミス側は商用のVPNルータを導入してAzure側はVPN Gatewayを使ったのですが、後で思ったのが、
「商用のVPNルータを買わなくてもLinuxのIPSec実装の「libreswan」でいいじゃん」
ということです。

そこで、「libreswan」を使ったIPSec VPNとAzure VPN Gatewayの接続を検証をしてみた結果を紹介したいと思います。

「libreswan」を使えば、オンプレとクラウドのハイブリッド構成を、低コストで構築することができますので、オススメです。

構成図

実現したい構成です。
オンプレサーバとAzureサーバの間の通信は、L3レベルで暗号化してローカルIP同士で通信できるようにします。

クラウド側の作業

Azure VPN Gatewayの構築

PowerShellコマンドを使うと、結構簡単に構築できます。
チュートリアル:PowerShell を使用した VPN ゲートウェイの作成と管理が参考になります。

コマンドに渡すパラメータの説明

#$RG1         = The name of the resource group
#$VNet1       = The name of the virtual network
#$Location1   = The location region
#$FESubnet1   = The name of the first subnet
#$BESubnet1   = The name of the second subnet
#$VNet1Prefix = The address range for the virtual network
#$FEPrefix1   = Addresses for the first subnet
#$BEPrefix1   = Addresses for the second subnet
#$GwPrefix1   = Addresses for the GatewaySubnet
#$DNS1        = The IP address of the DNS server you want to use for name resolution
#$Gw1         = The name of the virtual network gateway
#$GwIP1       = The public IP address for the virtual network gateway
#$GwIPConf1   = The name of the IP configuration

コマンドに渡すパラメータの設定

$ pwsh
PowerShell 6.2.3
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

# Azureテナントに接続する。Macの場合の例です。
> Connect-AzAccount
WARNING: To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code xxxxxxxxx to authenticate.

Account           SubscriptionName                TenantId
-------           ----------------                --------                     
xxxx@xxx.com      xxxxxxxxxxxxxxxx                xxxxxxxx-xxxx-xxxx-xxxx-xxxx…

PS >
PS >$RG1         = "RG_takaoka"
PS >$VNet1       = "VNet-takaoka"
PS >$Location1   = "Japan East"
PS >$Subnet1   = "FrontEnd"
PS >$VNet1Prefix = "192.168.250.0/24"   # Azure側のネットワーク体系は予め決めておく必要があります。
PS >$Prefix1   = "192.168.250.0/26"
PS >$GwPrefix1   = "192.168.250.64/28"
PS >$DNS1        = "8.8.8.8"
PS >$Gw1         = "VNet1GW-takaoka"
PS >$GwIP1       = "VNet1GWIP-takaoka"
PS >$GwIPConf1   = "gwipconf1-takaoka"

リソースグループの作成

PS >New-AzResourceGroup -ResourceGroupName $RG1 -Location $Location1
PS >Set-Item Env:\SuppressAzurePowerShellBreakingChangeWarnings "true"

仮想ネットワークの作成
「FrontEnd」という名前のサブネットと、Azure VPN Gatewayが使用する「GatewaySubnet」というサブネットを作成します。「GatewaySubnet」というサブネット名は固定であることに注意してください。

PS >$sub1 = New-AzVirtualNetworkSubnetConfig -Name $Subnet1 -AddressPrefix $Prefix1
PS >$gwsub1 = New-AzVirtualNetworkSubnetConfig -Name GatewaySubnet -AddressPrefix $GwPrefix1
PS >$vnet1   = New-AzVirtualNetwork `
            -Name $VNet1 `
            -ResourceGroupName $RG1 `
            -Location $Location1 `
            -AddressPrefix $VNet1Prefix `
            -Subnet $sub1,$gwsub1

VPN Gatewayに割り当てるパブリック IPアドレスの作成
「-AllocationMethod Dynamic」と書いてあるので、VPN Gatewayに割り当てるパブリック IPが動的であることに不安を覚えますが、VPN Gatewayに割り当てたパブリックIPは変更されないそうです。

PS >$gwpip    = New-AzPublicIpAddress -Name $GwIP1 -ResourceGroupName $RG1 `
              -Location $Location1 -AllocationMethod Dynamic
PS >$subnet   = Get-AzVirtualNetworkSubnetConfig -Name 'GatewaySubnet' `
              -VirtualNetwork $vnet1
PS >$gwipconf = New-AzVirtualNetworkGatewayIpConfig -Name $GwIPConf1 `
              -Subnet $subnet -PublicIpAddress $gwpip

VPN ゲートウェイの作成
New-AzVirtualNetworkGatewayを実行してから終わるまで、結構時間がかかります。
45分くらいです。珈琲でも飲んで待ってましょう。

PS >New-AzVirtualNetworkGateway -Name $Gw1 -ResourceGroupName $RG1 `
  -Location $Location1 -IpConfigurations $gwipconf -GatewayType Vpn `
  -VpnType RouteBased -GatewaySku VpnGw1

コマンドが終わると、以下のような結果が出力されます。

Name                   : VNet1GW-takaoka
ResourceGroupName      : RG_takaoka
Location               : japaneast
Id                     : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/RG_takaoka/providers/Microsoft.Network/virtualNetworkGateways/VNet1GW-takaoka
Etag                   : W/"f7c7842a-f456-4482-aa1c-03e1fb7037f2"
ResourceGuid           : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
ProvisioningState      : Succeeded
Tags                   : 
IpConfigurations       : [
                           {
                             "PrivateIpAllocationMethod": "Dynamic",
                             "Subnet": {
                               "Id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/RG_takaoka/providers/Microsoft.Network/virtualNetworks/V
                         Net-takaoka/subnets/GatewaySubnet"
                             },
                             "PublicIpAddress": {
                               "Id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/RG_takaoka/providers/Microsoft.Network/publicIPAddresses
                         /VNet1GWIP-takaoka"
                             },
                             "Name": "gwipconf1-takaoka",
                             "Etag": "W/\"f7c7842a-f456-4482-aa1c-03e1fb7037f2\"",
                             "Id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/RG_takaoka/providers/Microsoft.Network/virtualNetworkGatew
                         ays/VNet1GW-takaoka/ipConfigurations/gwipconf1-takaoka"
                           }
                         ]
GatewayType            : Vpn
VpnType                : RouteBased
EnableBgp              : False
ActiveActive           : False
GatewayDefaultSite     : null
Sku                    : {
                           "Capacity": 2,
                           "Name": "VpnGw1",
                           "Tier": "VpnGw1"
                         }
VpnClientConfiguration : null
BgpSettings            : {
                           "Asn": 65515,
                           "BgpPeeringAddress": "192.168.250.78",
                           "PeerWeight": 0
                         }

コマンドに渡すパラメータの設定

# Virtual network
# On-premises network - LNGIP1 is the VPN device public IP address
$LNG1        = "On-premise-takaoka"    #任意の名前
$LNGprefix1  = "192.168.56.0/24"       #オンプレ側の内部ネットワークセグメントを指定する
$LNGIP1      = "122.219.179.43"        #オンプレ側の公開ネットワークのIPを指定する
$Location1   = "Japan East"
# Connection
$Connection1 = "VNet1-TO-On-premise"

ローカル ネットワーク ゲートウェイの作成
コマンドはすぐに終わります。

PS > New-AzLocalNetworkGateway -Name $LNG1 -ResourceGroupName $RG1 `
    -Location $Location1 -GatewayIpAddress $LNGIP1 -AddressPrefix $LNGprefix1

実行結果です。

Name                     : On-premise-takaoka
ResourceGroupName        : RG_takaoka
Location                 : japaneast
Id                       : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/RG_takaoka/providers/Microsoft.Network/localNetworkGateways/On-premise-takaoka
Etag                     : W/"d8bf1724-7c04-4ea2-8121-3e8e68e41a5a"
ResourceGuid             : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
ProvisioningState        : Succeeded
Tags                     : 
GatewayIpAddress         : 122.219.179.43
LocalNetworkAddressSpace : {
                             "AddressPrefixes": [
                               "192.168.56.0/24"
                             ]
                           }
BgpSettings              : null

サイト間接続の設定
Azure VPN Gatewayとオンプレ側のVPNルータのlibreswanとの間のVPN接続を作成します。

$vng1 = Get-AzVirtualNetworkGateway -Name $GW1  -ResourceGroupName $RG1
$lng1 = Get-AzLocalNetworkGateway   -Name $LNG1 -ResourceGroupName $RG1

# -SharedKey は共有キーとなる任意の文字列を指定します。オンプレ側のlibreswanでの設定と合わせます。
PS > New-AzVirtualNetworkGatewayConnection -Name $Connection1 -ResourceGroupName $RG1 `
   -Location $Location1 -VirtualNetworkGateway1 $vng1 -LocalNetworkGateway2 $lng1 `
   -ConnectionType IPsec -SharedKey "xxxxxxxx" -ConnectionProtocol IKEv2

実行結果です。

Name                    : VNet1-TO-On-premise
ResourceGroupName       : RG_takaoka
Location                : japaneast
Id                      : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/
                          RG_takaoka/providers/Microsoft.Network/connections/VNet1-TO-On-prem
                          ise
Etag                    : W/"9d662784-eb49-4afe-bd9d-3b6fe278c2e8"
ResourceGuid            : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
ProvisioningState       : Succeeded
Tags                    : 
AuthorizationKey        : 
VirtualNetworkGateway1  : "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups
                          /RG_takaoka/providers/Microsoft.Network/virtualNetworkGateways/VNet
                          1GW-takaoka"
VirtualNetworkGateway2  : 
LocalNetworkGateway2    : "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups
                          /RG_takaoka/providers/Microsoft.Network/localNetworkGateways/On-pre
                          mise-takaoka"
Peer                    : 
RoutingWeight           : 0
SharedKey               : xxxxxxxx
ConnectionStatus        : Unknown
EgressBytesTransferred  : 0
IngressBytesTransferred : 0
TunnelConnectionStatus  : []

Azure VPN Gatewayで決まったネットワークに属するようAzure側サーバを構築

先に、$VNet1Prefix = “192.168.250.0/24”と指定して、Azure側の仮想ネットワーク「VNet-takaoka」を作成済みですので、Azure側サーバを作る時のネットワークとして「VNet-takaoka」を指定します。

ここまでの構築結果

ここまでの作業で、構築できた部分です。

オンプレ側の作業

次回は、オンプレ側のlibreswanの構築〜Azure側のサーバとの間での疎通確認を紹介いたします。

アバター画像
About 髙岡 貴史 21 Articles
登山家兼投資家兼インフラ寄りのエンジニア。最近はDatastaxを中心としたデータ処理基盤に関心あり。
ご覧いただきありがとうございます! この投稿はお役に立ちましたか?

役に立った 役に立たなかった

0人がこの投稿は役に立ったと言っています。


ご覧いただきありがとうございます。
ブログの最新情報はSNSでも発信しております。
ぜひTwitterのフォロー&Facebookページにいいねをお願い致します!



>> 雑誌等の執筆依頼を受付しております。
   ご希望の方はお気軽にお問い合わせください!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


質問はこちら 閉じる