Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
容器的应用程序服务中缺少Azure托管服务标识终结点_Azure_Azure Keyvault_Azure App Service Plans_Azure Managed Identity - Fatal编程技术网

容器的应用程序服务中缺少Azure托管服务标识终结点

容器的应用程序服务中缺少Azure托管服务标识终结点,azure,azure-keyvault,azure-app-service-plans,azure-managed-identity,Azure,Azure Keyvault,Azure App Service Plans,Azure Managed Identity,我正在尝试使用docker compose预览将我的应用部署到Azure容器应用服务。部署配置如下所示: version: "3.7" services: auth: image: myorg/myimage environment: - MyOrg__Hosting__PathBase=/auth - ASPNETCORE_FORWARDEDHEADERS_ENABLED=true - ConnectionStrings__Authent

我正在尝试使用docker compose预览将我的应用部署到Azure容器应用服务。部署配置如下所示:

version: "3.7"
services:
  auth:
    image: myorg/myimage
    environment:
      - MyOrg__Hosting__PathBase=/auth
      - ASPNETCORE_FORWARDEDHEADERS_ENABLED=true
      - ConnectionStrings__AuthenticationDatabase
  # other services not important for this question
在该部署中,我需要访问Azure Key Vault,我已通过Key Vault配置提供商将我的应用程序与之集成,如下所示:

My Azure Key Vault具有适当的访问策略集,从Kudu页面可以看出,运行时环境中似乎已设置了
MSI_端点
MSI_SECRET
环境变量。但是,密钥库配置提供程序多次无法连接到密钥库,出现以下错误:

这三种方法中的第一种方法清楚地表明MSI不适用于某些rean

我添加了一个用于调试目的的手动请求,该请求取自:

公共静态异步任务GetToken(字符串资源,字符串版本) { HttpClient=新的HttpClient(); var msident=Environment.GetEnvironmentVariable(“MSI_端点”)??“未设置MSI_端点!”; Debug(“MSI_端点为{msident}”,msident); client.DefaultRequestHeaders.Add(“Secret”、Environment.GetEnvironmentVariable(“MSI_Secret”); 返回wait client.GetAsync(String.Format(“{0}/?resource={1}&api version={2}”,msident,resource,apiversion)); } 我可以在我的应用程序日志中清楚地看到,
MSI_端点是
,所以它被设置了,但为空或空白。调试请求抛出的
invalidoOperationException
支持这一点,指出“提供了无效的请求URI。请求URI必须是绝对URI或必须设置基址。”

我尝试过禁用和重新启用系统分配的标识,重新启动我的应用程序服务,并三次检查密钥保险库访问策略,但都没有成功。此时,我想我只能假设运行时没有将
MSI.*
环境变量传递给容器,我不确定为什么会这样



更新:我现在也尝试在docker compose配置中的
环境
映射中列出
MSI.*
环境变量,但这也没有产生任何效果。

对于您的问题,我认为您错过了容器Web应用程序的托管标识的两个步骤

一是您需要首先启用托管标识。例如,您使用系统分配的托管标识类型。系统将按如下方式启用它:

然后环境变量
MSI_ENDPOINT
MSI_SECRET
将显示如下:


另一个原因是,如果需要使用托管标识访问密钥库,则需要授予托管标识足够的权限。您可以按照中的步骤操作。

谢谢Charles。我已经启用了系统分配的标识,并且我看到了根据第二个屏幕截图定义的环境变量。但是,在我的容器中,这些环境变量未设置或为空。我只是检查了KeyVault的RBAC权限,发现web应用没有为该资源分配读卡器角色。不幸的是,即使添加了该分配,我仍然看到同样的错误@alastairs,而不仅仅是密钥库的权限。您还需要设置访问策略,例如,机密访问控制。您可以按照步骤操作。@alastairs还有问题吗?它解决了您的问题吗?资源上的访问策略已针对应用程序适当设置:获取和列出机密。事实上,这是你链接到的页面,我首先按照它来设置
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var keyVaultClient = new KeyVaultClient(
    new KeyVaultClient.AuthenticationCallback(
        azureServiceTokenProvider.KeyVaultTokenCallback));

    config.AddAzureKeyVault(
        $"https://{builtConfig["KeyVault:Name"]}.vault.azure.net/",
        keyVaultClient,
        DefaultKeyVaultSecretManager());
Microsoft.Azure.Services.AppAuthentication.AzureServiceTokenProviderException: Parameters: 
Connection String: [No connection string specified], Resource: https://vault.azure.net, 
Authority: https://login.windows.net/6e5e63bd-f497-4f71-a6f4-9d29200a8a61. Exception 
Message: Tried the following 3 methods to get an access token, but none of them worked.
2020-02-21T18:27:27.024474350Z Parameters: 
Connection String: [No connection string specified], Resource: https://vault.azure.net, 
Authority: https://login.windows.net/6e5e63bd-f497-4f71-a6f4-9d29200a8a61. Exception 
Message: Tried to get token using Managed Service Identity. Unable to connect to the Managed Service Identity (MSI) endpoint. Please check that you are running on an Azure resource that has MSI setup.
2020-02-21T18:27:27.024479550Z Parameters: 
Connection String: [No connection string specified], Resource: https://vault.azure.net, 
Authority: https://login.windows.net/6e5e63bd-f497-4f71-a6f4-9d29200a8a61. Exception 
Message: Tried to get token using Visual Studio. Access token could not be acquired. Environment variable LOCALAPPDATA not set.
2020-02-21T18:27:27.024483550Z Parameters: 
Connection String: [No connection string specified], Resource: https://vault.azure.net, 
Authority: https://login.windows.net/6e5e63bd-f497-4f71-a6f4-9d29200a8a61. Exception 
Message: Tried to get token using Azure CLI. Access token could not be acquired. No such file or directory
public static async Task<HttpResponseMessage> GetToken(string resource, string apiversion)
{
    HttpClient client = new HttpClient();
    var msiEndpoint = Environment.GetEnvironmentVariable("MSI_ENDPOINT") ?? "MSI_ENDPOINT is not set!";
    Log.Logger.Debug("MSI_ENDPOINT is {MsiEndpoint}", msiEndpoint);
    client.DefaultRequestHeaders.Add("Secret", Environment.GetEnvironmentVariable("MSI_SECRET"));
    return await client.GetAsync(String.Format("{0}/?resource={1}&api-version={2}", msiEndpoint, resource, apiversion));
}