【问题标题】:Azure Service Fabric and Azure Key Vault Secret ErrorAzure Service Fabric 和 Azure Key Vault Secret 错误
【发布时间】:2018-03-09 15:18:26
【问题描述】:

尝试从无状态服务结构实现 Azure Key Vault Secret 时,我在控制台应用程序中工作得很好。

System.TypeLoadException
  HResult=0x80131522
  Message=Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'. Derived types must either match the security accessibility of the base type or be less accessible.
  Source=Microsoft.Rest.ClientRuntime
  StackTrace:
   at Microsoft.Rest.ServiceClient`1.CreateRootHandler

public async Task<string> GetAccessToken(string authority, string resource, string scope)
        {
            var clientId = MyConfig.Settings.Sections["MyConfigSection"].Parameters["AuthClientId"].Value;
            var clientSecret = MyConfig.Settings.Sections["MyConfigSection"].Parameters["AuthClientSecret"].Value;
            ClientCredential clientCredential = new ClientCredential(clientId, clientSecret);

            var context = new AuthenticationContext(authority, TokenCache.DefaultShared);
            var result = await context.AcquireTokenAsync(resource, clientCredential);

            return result.AccessToken;
        }

        public string GetCRMConnectionString()
        {
            var secretvaultAddress = MyConfig.Settings.Sections["MyConfigSection"].Parameters["SecretVaultUrl"].Value;
            var client = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(GetAccessToken));
            return client.GetSecretAsync(secretvaultAddress).GetAwaiter().GetResult().Value;
        }

【问题讨论】:

  • 你见过this SO question吗?这似乎与您遇到的问题相同,并且包含解决方案。

标签: azure-service-fabric azure-keyvault


【解决方案1】:

WebRequestHandler 类型(在您的情况下创建其实例)是 System.Net.Http.WebRequest.dll 的一部分。如果您探索程序集的属性,您会发现下一个应用于它 -

[程序集:AllowPartiallyTrustedCallers]

此属性使程序集被视为 SecurityTransparent。 WebRequestHandler 派生自另一个程序集 - System.Net.Http.dll 中定义的 HttpClientHandler。因此,可能在您部署了代码的环境中,System.Net.Http.dll 缺少 AllowPartiallyTrustedCallers,这使得它对安全至关重要,这意味着违反了规则——透明代码不能调用对安全至关重要的代码。

尝试通过为具有 AllowPartiallyTrustedCallers 属性的特定 System.Net.Http.dll 版本创建绑定规则来解决它,或者尝试显式创建 HttpClient 并将其传递给 KeyVaultClient ctr。

有关更多详细信息和选项,请参阅此链接 - Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'

【讨论】:

    猜你喜欢
    • 2020-01-04
    • 2020-09-09
    • 2017-09-24
    • 2022-12-22
    • 1970-01-01
    • 2019-03-13
    • 2019-11-30
    • 2016-10-19
    • 2021-04-29
    相关资源
    最近更新 更多