如何在 Azure 密钥保管库中更新客户端新密钥

问题描述 投票:0回答:1

我的客户端密钥已过期,因此我需要更新密钥,如何使用 azure 门户更新 Azure 数据工厂中的 Azure 密钥保管库中的密钥。

如何在 Azure 密钥保管库中更新新的客户端密钥,以及如何设置过期日期

azure-active-directory azure-data-factory azure-keyvault secret-key
1个回答
0
投票

最初,我注册了一个 Azure AD 应用程序并在其中创建了客户端密钥,如下所示:

enter image description here

在我的 Azure 密钥保管库中,我添加了一个具有上述的秘密,如下所示:

enter image description here

要在 Azure AD 应用程序注册中创建 new 客户端密钥和 update 密钥保管库密钥值,您可以在 Azure Cloud Shell 中运行以下 PowerShell 脚本:

$resourceGroupName = "YourRGname"
$keyVaultName = "YourKVname"
$secretName = "YourKBsecretname"
$appName = "YourAzureADappName"

$existingSecret = Get-AzKeyVaultSecret -VaultName $keyVaultName -Name $secretName -AsPlainText
Write-Output "Existing secret value: $existingSecret"

$customKeyIdentifier = "newSecret"
$customKeyIdentifierBase64 = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($customKeyIdentifier))

$clientSecret = New-AzADAppCredential -DisplayName $appName -CustomKeyIdentifier $customKeyIdentifierBase64 -EndDate (Get-Date).AddYears(1) 
$secretValue = ConvertTo-SecureString -String $clientSecret.SecretText -AsPlainText -Force

Set-AzKeyVaultSecret -VaultName $keyVaultName -Name $secretName -SecretValue $secretValue
Write-Output "New client secret created and updated in Key Vault successfully."

$newSecret = Get-AzKeyVaultSecret -VaultName $keyVaultName -Name $secretName -AsPlainText
Write-Output "New secret value: $newSecret"

回复:

enter image description here

为了确认,我在门户中检查了相同的内容,其中在 Azure AD 应用程序中创建了新的客户端密钥,如下所示:

enter image description here

也在 Azure Key Vault 中,通过创建新版本,成功使用新的客户端密钥值更新了密钥,如下所示:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.