Terraform azurerm 后端正在尝试使用基于密钥的身份验证连接到 blob 存储,即使设置了 use_msi=true

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

我正在使用 terraform 0.12 和 azurerm 后端来存储我的状态配置。

我遇到了一个问题,我已通过 ARM_USE_MSI 环境变量设置了 use_msi=true,并且还根据 Azure 的防止共享密钥授权的建议策略禁用了 Blob 存储上的密钥 (https://learn.microsoft.com/en-us/ azure/storage/common/shared-key-authorization-prevent?source=recommendations&tabs=portal)

我现在遇到一个问题,当我使用后端配置文件运行 terraform init 时,出现错误:

Error: Failed to get existing workspaces: storage: service returned error: StatusCode=403, ErrorCode=KeyBasedAuthenticationNotPermitted, ErrorMessage=Key based authentication is not permitted on this storage account. 

当我为 terraform 启用跟踪日志记录时,我看到以下几行,表明 terraform 正在拾取 use_msi 标志

2024/04/08 13:56:29 Testing if Service Principal / Client Certificate is applicable for Authentication..

2024/04/08 13:56:29 Testing if Multi Tenant Service Principal / Client Secret is applicable for Authentication..

2024/04/08 13:56:29 Testing if Service Principal / Client Secret is applicable for Authentication..

2024/04/08 13:56:29 Testing if Managed Service Identity is applicable for Authentication..

2024/04/08 13:56:29 Using Managed Service Identity for Authentication

...
Successfully configured the backend "azurerm"! Terraform will automatically

use this backend unless the backend configuration changes.


2024/04/08 13:56:29 [DEBUG] Building the Blob Client from an Access Token (using user credentials)

...

API Call to storageAccounts/<redacted>/listKeys using the "access_token". 


最后一个 API 调用返回存储帐户的 2 个密钥。此时,我质疑为什么当我说我想使用 MSI 时,后端试图使用存储帐户的密钥来访问它。

解码后的访问令牌包含适当的声明,其中包括 MSI 的正确客户端 ID,并且我还确保此 MSI 具有对 Blob 存储的所有适当访问权限。

任何人都可以帮助指出我的配置出了问题以及为什么 terraform 后端仍然尝试使用基于密钥的身份验证来连接到存储帐户。

使用 terraform 0.12 使用 azurerm 后端,设置 ARM_USE_MSI=true 环境变量以及 use_msi 工作所需的所有其他环境变量 https://developer.hashicorp.com/terraform/language/settings/backends/azurerm

azure terraform terraform-provider-azure azure-managed-identity azure-rm
1个回答
0
投票

您需要使用

use_azuread_auth=true
作为后端配置的一部分,该配置可从 Terraform 开始使用
v0.15.?

我能够使用 Terraform 让它工作

v0.15.5

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