Azure 服务主体机密以小时为单位过期

Azure Service Principal Secret expiration in hours

创建 Azure Principal 时是否有强制机密在数小时内过期的选项,我知道有年、月、日的选项,但有几个小时的选项吗?

谢谢

您不能直接在 Azure 门户中执行此操作,最简单的方法是在创建应用程序后使用 powershell 执行此操作,您可以使用两个 Az module and AzureAD 模块,这取决于您的要求。

此外,我相信您只是想在 Certificates & secrets 中添加用于应用程序注册的秘密,而不是服务主体,它们是不同的。

使用New-AzADAppCredential:

$SecureStringPassword = ConvertTo-SecureString -String "password123" -AsPlainText -Force
New-AzADAppCredential -ObjectId <object-id of App Registration> -Password $SecureStringPassword -StartDate (Get-Date) -EndDate (Get-Date).AddHours(3)

使用New-AzureADApplicationPasswordCredential:

New-AzureADApplicationPasswordCredential -ObjectId <object-id of App Registration> -StartDate (Get-Date) -EndDate (Get-Date).AddHours(3)

除此之外,如果您真的想将密钥添加到服务主体,请改用New-AzADSpCredential and New-AzureADServicePrincipalPasswordCredential