LoginSignup
0
0

More than 1 year has passed since last update.

Azure VPN Client for macOS の VPN Gateway を Azure CLI で作って接続してみた

Posted at

背景と目的

Azure VPN Client for macOS が GA したので Azure CLI で VPN Gateway を作って接続してみました。

前提条件

コマンドの実施環境は、Mac + Azure CLI です。

bash
$ sw_vers
ProductName:    macOS
ProductVersion: 11.5.2
BuildVersion:   20G95

$ az version
{
  "azure-cli": "2.27.1",
  "azure-cli-core": "2.27.1",
  "azure-cli-telemetry": "1.0.6",
  "extensions": {}
}

実施内容

Azure VPN Client は、App Store からインストールしておきます。

3.VPN ゲートウェイでの Azure AD 認証を有効にする

こちらを参考に、グローバル管理者ロールの Azure AD ユーザーで下記の URL にアクセスして、Azure VPN というエンタープライズアプリケーションを作成します。

https://login.microsoftonline.com/common/oauth2/authorize?client_id=41b23e61-6c1e-4545-b367-cd054e0ed4b4&response_type=code&redirect_uri=https://portal.azure.com&nonce=1234&prompt=admin_consent

あとは、Azure CLI で VNET、VPN Gateway、動作確認用 VM を作成していき、VPN クライアントに設定ファイルをインポートして VPN 接続します。

bash
# 環境変数を設定します
region=japaneast
prefix=mnrp2svpn

# リソースグループを作成します
az group create \
  --name ${prefix}-rg \
  --location $region

# VNET を作成します
az network vnet create \
  --resource-group ${prefix}-rg \
  --name ${prefix}-vnet \
  --address-prefixes 10.1.0.0/16 \
  --subnet-name FrontEnd \
  --subnet-prefix 10.1.0.0/24

# VPN の Gateway サブネットを作成します
az network vnet subnet create \
  --vnet-name ${prefix}-vnet \
  --resource-group ${prefix}-rg \
  --name GatewaySubnet \
  --address-prefix 10.1.255.0/27

# VPN ゲートウェイのパブリック IP を作成します
az network public-ip create \
  --name ${prefix}-gwip \
  --resource-group ${prefix}-rg \
  --allocation-method Dynamic

# VPN ゲートウェイを AAD 認証を使用する OpenVPN でを作成します
az network vnet-gateway create \
  --name ${prefix}-gw \
  --public-ip-address ${prefix}-gwip \
  --resource-group ${prefix}-rg \
  --vnet ${prefix}-vnet \
  --gateway-type Vpn \
  --sku VpnGw1 \
  --vpn-type RouteBased \
  --address-prefixes 172.16.0.0/24 \
  --client-protocol OpenVPN \
  --vpn-auth-type AAD \
  --aad-tenant https://login.microsoftonline.com/$(az account show --query tenantId --output tsv)/ \
  --aad-audience 41b23e61-6c1e-4545-b367-cd054e0ed4b4 \
  --aad-issuer https://sts.windows.net/$(az account show --query tenantId --output tsv)/ \
  --no-wait

# VPN ゲートウェイの作成が完了したら「VPN クライアントのダウンロード」からファイルをダウンロードします(作成に 50 分くらいかかりました)
# (参考画面) https://docs.microsoft.com/ja-jp/azure/vpn-gateway/point-to-site-vpn-client-configuration-azure-cert#generate-files-using-the-azure-portal
unzip ~/Downloads/${prefix}-gw.zip -d ${prefix}-gw

# このファイルを Azure VPN クライアントにインポートして VPN 接続します
code ${prefix}-gw/AzureVPN/azurevpnconfig.xml

# 接続検証用の VM を作成します
vmpassword=$(openssl rand -base64 16)
echo $vmpassword

az vm create \
  --resource-group ${prefix}-rg \
  --name ${prefix}-vm \
  --os-disk-name ${prefix}-vmOSDisk \
  --image CentOS \
  --size Standard_A2_v2 \
  --vnet-name ${prefix}-vnet \
  --subnet FrontEnd \
  --admin-username azureuser \
  --admin-password $vmpassword \
  --nsg "" \
  --public-ip-address "" \
  --storage-sku Standard_LRS

# SSH 接続します
ssh azureuser@10.1.0.4

実施結果

VPN ゲートウェイに接続出来ている状態です。

p2s-vpn-mac.png

参考

作成したリソースを削除します。

bash
# リソースグループを削除します
az group delete \
  --name ${prefix}-rg

下記は、参考サイトです。

General availability: Azure VPN Client for macOS

Azure 証明書認証を使用した VNet へのポイント対サイト VPN 接続の構成:PowerShell

P2S OpenVPN プロトコル接続用の Azure Active Directory テナントを作成する

Azure Active Directory 認証: P2S OpenVPN プロトコル接続用に VPN クライアントを構成する - macOS - プレビュー

az network vnet-gateway create

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