我在 Azure 上设置了一个资源组,其中有一个带有一个数据库的 SQL Server。
我正在尝试使用 UAI 将同一资源组中的容器应用程序连接到此数据库,我已使用此连接字符串为此容器设置:
env: [
{ name: 'AZURE_CLIENT_ID', value: identity.properties.clientId }
{ name: 'AZURE_TENANT_ID', value: tenant().tenantId }
{ name: 'ConnectionString', value: Server=${databaseHost},1433;Database=${databaseName};Authentication=Active Directory Managed Identity;User ID=${identity.properties.principalId}' }
]
所有这些都是通过二头肌文件完成的,正如您在此片段中看到的。
当我的部署完成后,一切都部署得很好,我可以看到我的容器应用程序的身份设置正确。此 UAI 也是我创建并指定为 SQL Server 所有者的 DbAdmin 安全组的成员。
这是我的 SQL Server 和数据库的设置:
resource sqlServer 'Microsoft.Sql/servers@2022-05-01-preview' = {
name: serverName
location: location
tags: tags
properties: {
administrators: {
administratorType: 'ActiveDirectory'
azureADOnlyAuthentication: true
principalType: 'Group'
login: sqlAdminGroupName
sid: sqlAdminGroupObjectId
tenantId: subscription().tenantId
}
minimalTlsVersion: '1.2'
publicNetworkAccess: 'Enabled'
restrictOutboundNetworkAccess: 'Disabled'
}
identity: {
type: 'SystemAssigned'
}
}
resource sqlDB 'Microsoft.Sql/servers/databases@2022-05-01-preview' = {
parent: sqlServer
name: sqlDBName
location: location
tags: tags
sku: {
name: 'Basic'
tier: 'Basic'
capacity: 5
}
properties: {
requestedBackupStorageRedundancy: 'Zone'
}
}
所有这些设置正确并成功部署后,我仍然在容器应用程序的日志中收到此错误:
Unhandled exception. Microsoft.Data.SqlClient.SqlException (0x80131904): ManagedIdentityCredential authentication failed: Service request failed.
我无法弄清楚我的配置/设置中缺少什么才能使其正常工作。我真的很希望这个能起作用,因为不必设置密码对我来说似乎是最好的选择。我在我的配置、二头肌文件和直接在门户上尝试了多次调整,但没有成功。
显然,我的 myh 连接字符串有两个问题:
Encrypt=True
我的最终 ConnectionString 如下所示:
Server=${databaseHost},1433;Database=${databaseName};Authentication=Active Directory Managed Identity;User ID=${identity.properties.clientId}'; Encrypt=True
我还更新了所有 nuget 软件包以使用最新版本