c# - 使用 Pulumi 将应用服务 - 身份分配给 Azure 中的 KeyVault
问题描述
我使用“经典”Pulumi.Azure 创建了一个应用服务:
var appservice=new AppService(appserviceName, new AppServiceArgs
{
Name = appserviceName,
Location = _resourceGroup.Location,
AppServicePlanId = _servicePlan.Id,
ResourceGroupName = _resourceGroup.Name,
SiteConfig = new Pulumi.Azure.AppService.Inputs.AppServiceSiteConfigArgs
{
DotnetFrameworkVersion = "v5.0",
ScmType = "None",
},
Tags = { { "environemnt", "dev" } },
Logs = new AppServiceLogsArgs
{
HttpLogs = new AppServiceLogsHttpLogsArgs
{
FileSystem = new AppServiceLogsHttpLogsFileSystemArgs { RetentionInDays = 14, RetentionInMb = 35 }
}
}
,
AppSettings = appSettings
});
我还创建了一个密钥库:
var currentConfig=Output.Create(GetClientConfig.InvokeAsync());
var keyVault = new KeyVault(vaultname, new KeyVaultArgs
{
Name = vaultname,
Location = _resourceGroup.Location,
ResourceGroupName = _resourceGroup.Name,
TenantId = currentConfig.Apply(q => q.TenantId),
SkuName="standard"
, AccessPolicies=
{
new Pulumi.Azure.KeyVault.Inputs.KeyVaultAccessPolicyArgs
{
TenantId=currentConfig.Apply(q=>q.TenantId),
ObjectId=currentConfig.Apply(q=>q.ObjectId),
KeyPermissions={"get", "create", "list"},
SecretPermissions={"set","get","delete","purge","recover", "list"}
}
}
});
两者都按预期工作。我正在创建和访问 KeyVault 和应用服务。现在我需要应用服务也可以访问 KeyVault。
但是当添加一个新的访问策略时,我被困在了 ObjectId 上。应用服务似乎没有我可以分配给保管库的有效对象 ID。在 Azure 门户上检查服务时,我还看到缺少身份:
那么作为 pulumi 代码必须做些什么才能实现与在 Azure 中单击“On”并随后检索 ObjectId 相同的事情呢?
解决方案
您需要设置以下属性AppService
以启用托管标识:
Identity = new AppServiceIdentityArgs {Type = "SystemAssigned"},
推荐阅读
- c++ - 更改 volatile const 的值 - G++ vs Visual Studio 2019
- linq - 具有多个条件的 Linq @Where 子句
- swift - How to put background image on SwiftUI Form
- angular - Angular HttpClient 获得状态 0(Safari 和 IE)
- selenium - 使用 selenium 在 Edge 上接受麦克风和摄像头权限
- javascript - 如果我使用 *ngIf 将过滤器隐藏在 mat-table 中,则出现错误无法读取未定义的属性“值”
- matlab - 在两个 yaxes 上指定次要刻度
- javascript - 如何在不同的屏幕尺寸交换 JavaScript 事件监听器
- c++ - value_comp 和 * 在迭代器之前
- android - android Firebase 云消息通知图标