概要

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 >cat my_cert.pem
cat my_cert.crt >>cat my_cert.pem
rm -rf my_cert.key && my_cert.crt

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

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"
}

ログイン確認

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

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