Kentico 如何允许ContinuousIntegration.exe在Azure Key Vault中使用连接字符串

Kentico 如何允许ContinuousIntegration.exe在Azure Key Vault中使用连接字符串,kentico,azure-keyvault,Kentico,Azure Keyvault,我在Azure中有一个Kentico Experience(v13)实例,我想运行ContinuousIntegration.exe,用我的CI xml文件中的内容填充我的数据库。问题是我们正在将CMSConnectionString设置从Azure Key Vault(AKV)注入web应用程序,而CI.exe没有看到它。相反,我收到以下错误消息: CMS.DataEngine.ApplicationInitException: Cannot access the database speci

我在Azure中有一个Kentico Experience(v13)实例,我想运行
ContinuousIntegration.exe
,用我的CI xml文件中的内容填充我的数据库。问题是我们正在将
CMSConnectionString
设置从Azure Key Vault(AKV)注入web应用程序,而CI.exe没有看到它。相反,我收到以下错误消息:

CMS.DataEngine.ApplicationInitException: Cannot access the database specified by the 'CMSConnectionString' connection string. Please install the database externally and set a correct connection string.
Failed to execute the command.
或者可能出现以下错误消息:

CMS.DataEngine.ApplicationInitException: Cannot access the database specified by the 'CMSConnectionString' connection string. Please install the database externally and set a correct connection string.
Failed to execute the command.
下面是我们web.config中的相关部分(适用于网站!):



如何确保可执行文件能够访问AKV中的机密?

可以让ContinuousIntegration.exe了解安全连接字符串,该字符串带有一个小型自定义模块,用于在启动时设置连接字符串。以下是模块的基本代码:

[程序集:程序集可发现]
[程序集:注册表模块(类型(AzureConnectionStringModule))]
公共类AzureConnectionString模块:模块
{
公共AzureConnectionString模块()
:base(名称(AzureConnectionString模块))
{
}
受保护的重写void OnPreInit()
{
base.OnPreInit();
var azureConnectionString=Environment.GetEnvironmentVariable(“SQLAZURECONNSTR_CMSConnectionString”);
if(string.IsNullOrWhiteSpace(azureConnectionString))
{
azureConnectionString=Environment.GetEnvironmentVariable(“CMSConnectionString”);
}
如果(!string.IsNullOrWhiteSpace(azureConnectionString))
{
SettingsHelper.ConnectionString.SetConnectionString(“CMSConnectionString”,azureConnectionString);
}
}
}
从新安装的Kentico Xperience 13中,以下是配置此功能的步骤:

  • 按照此处的步骤将密钥库支持添加到本地管理应用程序:
  • 将上面的模块添加到类库中的解决方案中。确保主项目引用类库,以便在构建过程中包含该类库
  • 确保~\web.config没有名为CMSConnectionString的连接字符串或应用程序设置
  • 将应用部署到应用服务
  • 在Azure中,使用名称CMSConnectionString和值@Microsoft.KeyVault(VaultName=your KeyVault;SecretName=CMSConnectionString)创建应用程序服务配置设置
  • 在密钥库中,创建一个名为CMSConnectionString的秘密,并为Azure SQL数据库的连接字符串赋值。您可能还需要遵循为我的应用程序服务创建访问策略
  • 此时,Kentico Experience 13管理员应该加载对数据库的访问权限
  • 在应用程序服务门户的开发工具下选择控制台
  • 在控制台中,运行
    cd-bin
    ,然后运行
    ContinuousIntegration.exe-r
    。这将生成一条关于未配置存储库的消息,或在还原操作中输出
  • 我无法执行上面的第1步,即使用AKV进行本地开发。我的帐户没有权限。剩下的部分似乎有效,所以我将把它标记为答案。