概要

Azure のサービスプリンシパルを作成後、それを使用してログインする手順を記載する。

目次

パスワードベースのサービスプリンシパルの作成

サービスプリンシパル作成

az ad sp create-for-rbac --name サービスプリンシパル名

{
  "appId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "displayName": "サービスプリンシパル名",
  "name": "http://サービスプリンシパル名",
  "password": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "tenant": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

ログイン確認

az login --service-principal -u 表示されたname -p 表示されたpassword --tenant 表示されたtenant

証明書ベースのサービスプリンシパル作成

証明書の作成(パスワードなしで作成)

openssl req \
  -newkey rsa:4096 -nodes -sha256 -keyout my_cert.key \
  -x509 -days 365 -out my_cert.crt

# 秘密キーと証明書を1ファイルに纏める

cat my_cert.key >my_cert.pem
cat my_cert.crt >>my_cert.pem
rm -rf my_cert.key && rm -rf my_cert.crt

サービスプリンシパル作成

az ad sp create-for-rbac --name サービスプリンシパル名 --cert @`pwd`/my_cert.pem

{
  "appId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "displayName": "サービスプリンシパル名",
  "name": "http://サービスプリンシパル名",
  "password": null,
  "tenant": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

ログイン確認

az login --service-principal -u 表示されたname -p ./my_cert.pem --tenant 表示されたtenant

ロールの管理

サービス プリンシパルの既定のロールは共同作成者になっているので、必要なロールのみを割り当て直しておく必要がある。

参考

例) 閲覧者ロールを追加し、共同作成者ロールを削除

az role assignment create --assignee APP_ID --role Reader
az role assignment delete --assignee APP_ID --role Contributor

カスタムロールの作成

TODO:

https://docs.microsoft.com/ja-jp/azure/role-based-access-control/resource-provider-operations
https://docs.microsoft.com/ja-jp/azure/role-based-access-control/resource-provider-operations#microsoftweb

チュートリアル:Azure CLI を使用して Azure カスタム ロールを作成する

Azure ロールの定義について
Azure カスタム ロール

ロール説明
Microsoft.Web/sites/Write新しい Web アプリを作成するか、既存の Web アプリを更新します。
Microsoft.Web/sites/Write新しい Web アプリを作成するか、既存の Web アプリを更新します。
Microsoft.Web/sites/restart/ActionWeb アプリを再起動します。
Microsoft.Web/sites/start/ActionWeb アプリを起動します。
Microsoft.Web/sites/stop/ActionWeb アプリを停止します。
microsoft.web/sites/functions/actionWeb アプリの関数。
microsoft.web/sites/sync/actionWeb アプリを同期します。
microsoft.web/sites/syncfunctiontriggers/action関数トリガーを同期します。
Microsoft.Web/sites/eventGridFilters/deleteWeb アプリから Event Grid フィルターを削除します。
Microsoft.Web/sites/eventGridFilters/readWeb アプリから Event Grid フィルターを取得します。
Microsoft.Web/sites/eventGridFilters/writeWeb アプリに Event Grid フィルターを配置します。
microsoft.web/sites/host/sync/action関数トリガーを同期します。
Microsoft.ContainerRegistry/registries/importImage/action指定されたパラメーターを使用して、コンテナー レジストリにイメージをインポートします。
Microsoft.ContainerRegistry/registries/builds/write指定したパラメーターでコンテナー レジストリのビルドを更新します。
Microsoft.ContainerRegistry/registries/buildTasks/write指定したパラメーターでコンテナー レジストリのビルド タスクを作成または更新します。
Microsoft.ContainerRegistry/registries/metadata/readコンテナー レジストリの特定のリポジトリのメタデータを取得します
Microsoft.ContainerRegistry/registries/pull/readコンテナー レジストリからイメージをプルまたは取得します。
Microsoft.ContainerRegistry/registries/push/writeコンテナー レジストリにイメージをプッシュするか書き込みます。

Microsoft.ContainerRegistry/registries/listBuildSourceUploadUrl/action コンテナー レジストリのソース アップロード URL の場所を取得します。
Microsoft.ContainerRegistry/registries/scheduleRun/action コンテナー レジストリに対する実行をスケジュールします。
Microsoft.ContainerRegistry/registries/runs/listLogSasUrl/action 実行のログ SAS URL を取得します。


トップ   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS