#author("2020-08-22T08:19:13+00:00","","") #mynavi(Azureメモ) #setlinebreak(on); * 概要 [#gb9ab00c] #html(<div class="pl10">) Azure のサービスプリンシパルを作成後、それを使用してログインする手順を記載する。 #html(</div>) * 目次 [#kc48b057] #contents - 関連 -- [[Azureメモ]] -- [[Azure CLI の操作]] * パスワードベースのサービスプリンシパルの作成 [#m92c293d] #html(<div class="pl10">) サービスプリンシパル作成 #myterm2(){{ az ad sp create-for-rbac --name サービスプリンシパル名 { "appId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "displayName": "サービスプリンシパル名", "name": "http://サービスプリンシパル名", "password": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "tenant": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } }} ログイン確認 #myterm2(){{ az login --service-principal -u 表示されたname -p 表示されたpassword --tenant 表示されたtenant }} #html(</div>) * 証明書ベースのサービスプリンシパル作成 [#fe799b1e] #html(<div class="pl10">) 証明書の作成(パスワードなしで作成) #myterm2(){{ openssl req \ -newkey rsa:4096 -nodes -sha256 -keyout my_cert.key \ -x509 -days 365 -out my_cert.crt }} # 秘密キーと証明書を1ファイルに纏める #myterm2(){{ cat my_cert.key >cat my_cert.pem cat my_cert.crt >>cat my_cert.pem rm -rf my_cert.key && my_cert.crt }} サービスプリンシパル作成 #myterm2(){{ az ad sp create-for-rbac --name サービスプリンシパル名 --cert @`pwd`/my_cert.crt { "appId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "displayName": "サービスプリンシパル名", "name": "http://サービスプリンシパル名", "password": null, "tenant": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } }} ログイン確認 #myterm2(){{ az login --service-principal -u 表示されたname -p ./my_cert.pem --tenant 表示されたtenant }} #html(</div>)