「[[マイクロソフト系技術情報 Wiki>http://techinfoofmicrosofttech.osscons.jp/]]」は、「[[Open棟梁Project>https://github.com/OpenTouryoProject/]]」,「[[OSSコンソーシアム .NET開発基盤部会>https://www.osscons.jp/dotNetDevelopmentInfrastructure/]]」によって運営されています。
-戻る
--[[SPN]]
--[[Azure]] > [[RBAC>Role Based Access Control (RBAC)]]
---Azure サービス プリンシパル
---[[Azure Managed ID]]
* 目次 [#b8b9698b]
#contents
*概要 [#l4b36e5e]
-≒ [[SPN]]のAzure版
-[[Active Directory]]ではなく、[[Azure AD>Microsoft Azure Active Directory]]に管理される。
-[[RBAC>Role Based Access Control (RBAC)]]のアクセス権を付与するために使用される。
*詳細 [#q10c5d5a]
-Azureのリソース操作用のID
-このID(appId)は、[[Azure AD>Microsoft Azure Active Directory]]によって管理される。
-基本は、アプリケーション用として利用する。
**認証の種類 [#y62421eb]
サービス・プリンシパルでは 2 種類の認証を使用可能。
***パスワード・ベースの認証 [#z989738b]
***証明書ベースの認証 [#z4f274de]
***[[Azure Managed ID]] [#dbb7cc81]
ラッパとして機能し、[[パスワード>#be520860]]を使用しないで利用できる。
**パスワードの失効とリフレッシュ [#be520860]
***失効 [#vda440d5]
-既定では一年でパスワード(シークレット)が失効する。
-無期限に設定することも出来る模様。
***リフレッシュ [#od2fb802]
-必要に応じリフレッシュが必要になる。
-リフレッシュはパスワード(シークレット)再作成し、
-アプリケーションにパスワード(シークレット)を再設定する。
*用例 [#h6bfa378]
***オートメーション・アカウント [#k7071566]
-Azure オートメーションを利用すると、Azure リソースへの操作を自動化できる
--主にインフラ系操作の自動化に利用する仕組み
--オートメーション・アカウントを作成し、複数のアカウントを束ねて管理
--Runbook と呼ばれる仕組みで、実際に行う自動化の作業を記述・管理
-Azure インフラ操作だけでなく、オンプレミス側へのリソース操作指示なども可能
--[[RBAC>Role Based Access Control (RBAC)]]には、サービス・プリンシパルが利用される。
--これにより、Runbook が実際に実行できるインフラ操作内容を制限できる。
-参考
--スタンドアロン Azure Automation アカウントを作成する | Microsoft Docs~
https://docs.microsoft.com/ja-jp/azure/automation/automation-create-standalone-account
***[[Azure CLI]]用 [#f0ba22b5]
[[Azure CLI]]用とすれば、操作者のSubscriptionが変更されても権限を維持可能。
>az ad sp create-for-rbac --skip-assignment
{
"appId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"displayName": "azure-cli-2019-12-12-08-08-32",
"name": "http://azure-cli-2019-12-12-08-08-32",
"password": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"tenant": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
>az role assignment create --assignee "<appId>" --role Reader
>az login --service-principal --username "<appId>" --password "<password>" --tenant TENANT_ID
-参考
--[[コチラのチュートリアル>Azure Kubernetes Service (AKS)#l3698aeb]]での方式
--Azure CLI で Azure サービス プリンシパルを使用する | Microsoft Docs~
https://docs.microsoft.com/ja-jp/cli/azure/create-an-azure-service-principal-azure-cli?view=azure-cli-latest
**ストレージ系 [#re662778]
***[[Key Vault]]用 [#qbef49c9]
[[Managed ID>Azure Managed ID]]方式で、[[Key Vault]]経由で、~
クレデンシャルを取り出し、任意のサービスを認証する。
-参考
--Azure Key Vault 開発者ガイド | Microsoft Docs~
https://docs.microsoft.com/ja-jp/azure/key-vault/general/developers-guide
***[[Azureのストレージ]] [#bbb5dd2f]
**AKS [#rd1447fb]
***AKS制御プレーン用 [#cab71a53]
-SPN方式~
前述の[[Azure CLI用のSPN>#f0ba22b5]]を使用する。
az aks create -n myAKSCluster -g myResourceGroup --node-count 2 --service-principal "<appId>" --client-secret "<password>" --generate-ssh-keys
-[[Managed ID>Azure Managed ID]]方式
az aks create -n myAKSCluster -g myResourceGroup --enable-managed-identity
-参考
--[[SPN方式:実行手順>AKSクラスタ作成・操作に必要な権限#c8ea8683]]
--[[Managed ID方式:実行手順>AKSクラスタ作成・操作に必要な権限#i3b0bd60]]
***AKS制御プレーンのAKS ARC Pull用 [#e9e4c0d9]
-SPN方式~
前述の[[Azure CLI用のSPN>#f0ba22b5]]を使用する。
az role assignment create --assignee "<appId>" --scope "<acrId>" --role acrpull
-[[Managed ID>Azure Managed ID]]方式~
既存の AKS クラスターに対する ACR 統合
既存の AKS クラスターに対する [[ACR>Azure Container Registry]] 統合
az aks update -n myAKSCluster -g myResourceGroup --attach-acr <acrName>
-参考
--[[実行手順>AKSクラスタ作成・操作に必要な権限#qc2c2db1]]
--Microsoft Docs
---サービス プリンシパルでの認証~
https://docs.microsoft.com/ja-jp/azure/container-registry/container-registry-auth-service-principal
---マネージド ID による認証~
https://docs.microsoft.com/ja-jp/azure/container-registry/container-registry-authentication-managed-identity
***AKS制御プレーンの既存のVNET操作用 [#w59a5f58]
-SPN方式
AKS_VNET_ID=$(az network vnet show --name $AKS_VNET_NAME --resource-group $RG_AKS --query id -o tsv)
az role assignment create --assignee $AKS_SP_ID --role "Contributor" --scope $AKS_VNET_ID
-[[Managed ID>Azure Managed ID]]方式
AKS_VNET_ID=$(az network vnet show --name $AKS_VNET_NAME --resource-group $RG_AKS --query id -o tsv)
AKS_MANAGED_ID=$(az aks show --name $AKS_CLUSTER_NAME --resource-group $RG_AKS --query identity.principalId -o tsv)
az role assignment create --assignee $AKS_MANAGED_ID --role "Contributor" --scope $AKS_VNET_ID
-参考
--[[実行手順>AKSクラスタ作成・操作に必要な権限#db6b9d7e]]
--Qiita
---Azure Kubernetes Serviceを別の仮想ネットワークにデプロイする時の注意点~
https://qiita.com/yotan/items/75a54dc60761d5b6f866
*参考 [#i5b398d6]
-3分でわかるAzureでのService Principal~
https://www.slideshare.net/ToruMakabe/3azure-service-principal
-Azure サービス プリンシパルの作成方法 - poke_dev’s blog~
https://poke-dev.hatenablog.com/entry/2019/11/24/213704
**Microsoft Docs [#fa8daec1]
-Azure CLI で Azure サービス プリンシパルを使用する~
https://docs.microsoft.com/ja-jp/cli/azure/create-an-azure-service-principal-azure-cli
-Microsoft identity platform
--ポータルで Azure AD アプリとサービス プリンシパルを作成する~
https://docs.microsoft.com/ja-jp/azure/active-directory/develop/howto-create-service-principal-portal
--Azure アプリ ID を作成する (PowerShell)~
https://docs.microsoft.com/ja-jp/azure/active-directory/develop/howto-authenticate-service-principal-powershell
----
Tags: [[:セキュリティ]], [[:アカウント]], [[:クラウド]], [[:認証基盤]], [[:Azure]], [[:Active Directory]]