【问题标题】:IdentityServer4 + Docker: The remote certificate is invalid according to the validation procedureIdentityServer4 + Docker:远程证书根据验证程序无效
【发布时间】:2019-01-30 19:06:45
【问题描述】:

我正在按照 IdentityServer4 的快速入门指南设置受保护的 API 并使用客户端 (Sample 2) 访问它。我正在使用 .Net Core + Docker for Windows(Windows 容器)来运行我的测试应用程序。

设置应该是这样的:

当我致电https://<identity-url>/.well-known/openid-configuration 时,我得到了配置,但前面有已知的“不安全 - 你确定”页面。

API 1 受以下保护:

services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
    .AddIdentityServerAuthentication(options =>
        {
            options.Authority = "https://<identity-url>";
            options.RequireHttpsMetadata = this.Environment.IsProduction();
            options.ApiName = "api1";
        });

并且Config.cs(在IdentityServer)是根据快速入门的文档。

问题:

当我尝试从我的Client 呼叫API 1 时,我需要首先访问IdentityServer(根据快速入门):

var disco = await DiscoveryClient.GetAsync("https://<identity-url>");
if (disco.IsError)
{
    Console.WriteLine(disco.Error);
    return BadRequest(disco.Exception);
}

这会导致这个错误

远程证书根据验证无效 过程。

我正在使用来自.net core templates for web applications 的默认证书,我认为问题与证书是自签名的事实有关。这是正确的吗?

信任另一个容器中的自签名证书以便建立连接的正确方法是什么?

【问题讨论】:

标签: docker ssl asp.net-core identityserver4


【解决方案1】:

您可以为您的容器添加de证书,但这仅适用于外部请求,在容器之间您收到错误的证书远程证书根据验证程序无效因为不可能验证证书,docker 网络是安全的,您可以覆盖策略以允许 http insted https

IdentityModel 具有扩展方法 GetDiscoveryDocumentAsync 与重载添加策略以允许 http

    DiscoveryDocumentResponse disco = 
    await client.GetDiscoveryDocumentAsync(new DiscoveryDocumentRequest { 
                    Address = "http://<identity-url>", 
                    Policy = { RequireHttps = false } 
                });

【讨论】:

    【解决方案2】:

    我在使用 Web Api 和 Swagger 作为客户端时遇到了同样的问题。这不是身份服务器问题,而是 SSL 限制。如果您想在远程服务器上使用 SSL 和 https 连接到您的 Ids4,唯一的方法是从 CA 购买证书。将自签名证书放在信任库中也不起作用。您可以改用 http 协议,但当然,仅用于测试目的。

    【讨论】:

    • 我不同意。您可以毫无问题地使用带有自制 CA 的自签名证书。只需将 CA 证书添加到受信任的存储区即可。
    猜你喜欢
    • 2011-03-28
    • 2016-11-28
    • 2013-08-08
    • 2012-07-20
    • 2015-03-17
    • 2021-05-30
    • 1970-01-01
    相关资源
    最近更新 更多