我需要在 Azure 中创建一个临时密钥以在 Terraform 中使用

I need to create a temporary key in Azure to use in Terraform

我正在使用 Terraform 云,我不想在其中使用永久密钥。那么,是否可以在 Azure Cloud 中创建临时密钥(就像我们可以在 AWS 中创建的那样)。

通过创建 ServicePrincipal in AzureAD you're also able to assign a LifetimePolicy (tokenLifetimePolicies)。这样您就可以让令牌“生命终结”。

这里还有一个短片how to on creating a new ServicePrincipal


或者您可以使用这个新的预览功能:Configurable token lifetimes in Microsoft identity platform (Preview).

由于它是一个预览功能,因此您不应在生产环境中使用它。

当您 authenticating to Azure Cloud via Azure service principal 时,默认情况下,Az CLI 命令将为该服务主体获取一个密码,其有效期为 one-year。

az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/<subscription_id>"

从您的评论来看,您实际上是想让这个密码在短时间内过期。您可以使用 az ad app credential reset 附加或覆盖应用程序的密码或证书凭据。

例如,使用以下 Az CLI 命令重置应用程序密码。

az ad app credential reset --id <appId> --password <sp_password> --end-date 2020-08-13T11:59:59+00:00

更多信息,您可以阅读Relationship between application objects and service principals