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?

More than 1 year has passed since last update.

Azure AutomationでSet-AzKeyVaultAccessPolicyを実行できないときの対処法

0
Posted at

はじめに

めちゃくちゃニッチですが、システム割り当てマネージドIDでAzureと接続したAutomation Accountにて、Key Vaultに対してアクセスポリシーを付与するコマンド「Set-AzKeyVaultAccessPolicy」をサービスプリンシパルIDで実行する際、所有者ロールを付与しても登録できない場合の対象法になります。
よく読めばMSDocsのノートに書かれていましたが、非常に苦労したので備忘録として、、、

解決策

MSDocsに示されている通り、「-BypassObjectIdValidation」パラメータを指定する必要があります。
https://docs.microsoft.com/en-us/powershell/module/az.keyvault/set-azkeyvaultaccesspolicy?view=azps-8.1.0#description

$servicePrincipalId = "XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
$KEY_VAULT_NAME = "<your key vault name>"
 
# セッション情報の保持を無効化
Disable-AzContextAutosave -Scope Process
 
# システム割り当てマネージドIDを利用して接続
$AzureContext = (Connect-AzAccount -Identity).context
# コンテキストをセット
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext
 
# アクセスポリシー付与
Set-AzKeyVaultAccessPolicy `
    -VaultName $KEY_VAULT_NAME `
    -ObjectId $servicePrincipalId `
    -PermissionsToSecrets Get,List `
    -BypassObjectIdValidation
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?