0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Azure App Service の Unique Default Hostname を Azure CLI で試してみた

Posted at

Azure App Service を作成すると <リソース名>.azurewebsites.net という、デフォルトのホスト名でアクセスする事ができます。このデフォルトのホスト名で何かしらの Web サイトをしばらく運用していて使わなくなった際、Azure App Service を削除するとします。その後、第三者が同じ <リソース名> で Azure App Service を作成すると、以前運用されていた Web サイトへのハイパーリンクなどから流入して、サブドメインハイジャック的な事が行えてしまいます。

その対策として Azure App Service 作成時にユニークなサブドメインを生成して防止しよう、というのが今回の Unique Default Hostname です。

そこで今回は、AutoGeneratedDomainNameLabelScope の値を TenantReuseNoReuse に設定した WebApp を作成して、どのように Default Hostname がユニークになるのか試してみました。

検証用の App Service Plan を作成

bash
prefix=mnruniapp
region=japaneast

az group create \
  --name ${prefix}-rg \
  --location $region

az appservice plan create \
  --name ${prefix}-asp \
  --resource-group ${prefix}-rg \
  --is-linux \
  --sku B1

Azure CLI で REST API を実行する準備

bash
rgpath=$(az group show \
  --name ${prefix}-rg \
  --query id \
  --output tsv)

aspid=$(az appservice plan show \
  --name ${prefix}-asp \
  --resource-group ${prefix}-rg \
  --query id \
  --output tsv)

TenantReuse を試す

bash
az rest \
  --method put \
  --url "$rgpath/providers/Microsoft.Web/sites/${prefix}-tenant?api-version=2022-03-01" \
  --body '{ 
    "location": "'$region'",
    "kind": "app",
    "properties": {
        "serverFarmId": "'$aspid'",
        "AutoGeneratedDomainNameLabelScope": "TenantReuse",
    }
}'

az webapp show \
  --name ${prefix}-tenant \
  --resource-group ${prefix}-rg \
  --query defaultHostName \
  --output tsv

mnruniapp-tenant-bnctfua2f5bnd4ee.japaneast-01.azurewebsites.net

bnctfua2f5bnd4ee というランダムな英数字が含まれる Default Hostname が作成されました。

WebApp を削除してもう一度 TenantReuse で作成

bash
az webapp delete \
  --name ${prefix}-tenant \
  --resource-group ${prefix}-rg \
  --keep-empty-plan

az rest \
  --method put \
  --url "$rgpath/providers/Microsoft.Web/sites/${prefix}-tenant?api-version=2022-03-01" \
  --body '{ 
    "location": "'$region'",
    "kind": "app",
    "properties": {
        "serverFarmId": "'$aspid'",
        "AutoGeneratedDomainNameLabelScope": "TenantReuse",
    }
}'

az webapp show \
  --name ${prefix}-tenant \
  --resource-group ${prefix}-rg \
  --query defaultHostName \
  --output tsv

mnruniapp-tenant-bnctfua2f5bnd4ee.japaneast-01.azurewebsites.net

bnctfua2f5bnd4ee というランダムな英数字は前回と同じものが作成されました。

NoReuse を試す

bash
az rest \
  --method put \
  --url "$rgpath/providers/Microsoft.Web/sites/${prefix}-noreuse?api-version=2022-03-01" \
  --body '{ 
    "location": "'$region'",
    "kind": "app",
    "properties": {
        "serverFarmId": "'$aspid'",
        "AutoGeneratedDomainNameLabelScope": "NoReuse",
    }
}'

az webapp show \
  --name ${prefix}-noreuse \
  --resource-group ${prefix}-rg \
  --query defaultHostName \
  --output tsv

mnruniapp-noreuse-b8a7ahbpb8gahzf3.japaneast-01.azurewebsites.net

b8a7ahbpb8gahzf3 というランダムな英数字が作成されました。

WebApp を削除してもう一度 NoReuse で作成

bash
az webapp delete \
  --name ${prefix}-noreuse \
  --resource-group ${prefix}-rg \
  --keep-empty-plan

az rest \
  --method put \
  --url "$rgpath/providers/Microsoft.Web/sites/${prefix}-noreuse?api-version=2022-03-01" \
  --body '{ 
    "location": "'$region'",
    "kind": "app",
    "properties": {
        "serverFarmId": "'$aspid'",
        "AutoGeneratedDomainNameLabelScope": "NoReuse",
    }
}'

az webapp show \
  --name ${prefix}-noreuse \
  --resource-group ${prefix}-rg \
  --query defaultHostName \
  --output tsv

mnruniapp-noreuse-hnfrcjenatf5dqd5.japaneast-01.azurewebsites.net

前回とは違う hnfrcjenatf5dqd5 というランダムな英数字が作成されました。

検証結果

AutoGeneratedDomainNameLabelScope の値には

  • TenantReuse
  • SubscriptionReuse
  • ResourceGroupReuse
  • NoReuse

が使用できるようですが、NoReuse 以外は言葉通りランダムな英数字がリユースされるようです。

後片付け

bash
az group delete \
  --name ${prefix}-rg \
  --yes

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?