Docker映像错误根据客户端web应用程序上的验证过程,远程证书无效

Docker映像错误根据客户端web应用程序上的验证过程,远程证书无效,docker,asp.net-core,ssl,identityserver4,x509certificate2,Docker,Asp.net Core,Ssl,Identityserver4,X509certificate2,我的客户端WebApp(作为单独的Linux docker映像端口4443运行)上总是出现以下错误: 它连接到我的IdentityServer4(作为单独的Linux docker映像端口4444运行)。 在IS4 Startup.cs中,我创建了证书,其中包含以下代码: ... var idpUri = configuration["AppConfig:IdentityProviderUrl"]; var dnsName = new Uri(idpUri).DnsSafeH

我的客户端WebApp(作为单独的Linux docker映像端口4443运行)上总是出现以下错误:

它连接到我的IdentityServer4(作为单独的Linux docker映像端口4444运行)。 在IS4 Startup.cs中,我创建了证书,其中包含以下代码:

...
var idpUri = configuration["AppConfig:IdentityProviderUrl"];
var dnsName = new Uri(idpUri).DnsSafeHost;
var cert = new X509Certificate2(Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(),"certificate.pfx")));
var builder = services.AddIdentityServer(options => {
      options.IssuerUri = idpUri;
   }).AddSigningCredential(cert); //A self-signed PFX certificate located in the root of the IS4 and also copied in de client app used for Kestrel cert.
...
在我的客户端WebApp中,我插入了以下代码来设置权限:

  string identityProviderUrl = Configuration.GetValue<string>("AppConfig:IdentityProviderUrl");
  services.AddHttpClient(AUTHORIZATION_SERVICE_CLIENT_NAME, client => {
     client.BaseAddress = new Uri(identityProviderUrl);
     client.DefaultRequestHeaders.Clear();
     client.DefaultRequestHeaders.Add(HeaderNames.Accept, "application/json");
  });
  services.AddAuthentication("Bearer") 
     .AddJwtBearer("Bearer", options => { //NOTE: I don't know if this is needed
            options.Authority = identityProviderUrl;
            options.TokenValidationParameters = new TokenValidationParameters {
            ValidateAudience = false
         };
      });
   services.AddAuthentication(options => {
      options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
      options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
   }).AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options => {
         options.Authority = identityProviderUrl;
         options.ClientId = oidcClientId;
         options.ClientSecret = oidcClientSecret;
         ...
      });
string identityProviderUrl=Configuration.GetValue(“AppConfig:identityProviderUrl”);
services.AddHttpClient(授权\服务\客户端\名称,客户端=>{
client.BaseAddress=新Uri(identityProviderUrl);
client.DefaultRequestHeaders.Clear();
Add(HeaderNames.Accept,“application/json”);
});
服务。添加身份验证(“承载人”)
.AddJwtBearer(“Bearer”,options=>{//注意:我不知道是否需要这个
options.Authority=identityProviderUrl;
options.TokenValidationParameters=新的TokenValidationParameters{
ValidateAudience=false
};
});
services.AddAuthentication(选项=>{
options.DefaultScheme=CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme=OpenIdConnectDefaults.AuthenticationScheme;
}).AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme,选项=>{
options.Authority=identityProviderUrl;
options.ClientId=oidcClientId;
options.ClientSecret=OIDClientsecret;
...
});
我认为我正在创建的证书有问题,但这两个docker图像上都没有。但是Docker容器都使用HTTPS运行,否则根本不会启动。我错过了什么

让我们按照下面评论中的建议,通过LetsEncrypt来完成。 我下载并运行这个项目(src:) 设置了以下属性:

public string CaName { get; } = Constants.LetsEncryptStagingName;
public IEnumerable<string> Email { get; } = new string[] { "xxx@gmail.com" };
public bool AcceptTos { get; } = true;
public IEnumerable<string> Dns { get; } = new string[] { "xxx.duckdns.org" };
public (bool enabled, int? timeout) WaitForAuthz { get; } = (true, 300);
public bool Finalize { get; } = true;
public string ExportPfx { get; } = @"c:\tmp\certificate.pfx";
public string ExportPfxPassword { get; } = " ";
public string CaName{get;}=Constants.LetsEncryptStagingName;
public IEnumerable电子邮件{get;}=新字符串[]{”xxx@gmail.com" };
public bool AcceptTos{get;}=true;
public IEnumerable Dns{get;}=新字符串[]{“xxx.duckdns.org”};
public(bool-enabled,int?timeout)WaitForAuthz{get;}=(true,300);
公共bool Finalize{get;}=true;
公共字符串ExportPfx{get;}=@“c:\tmp\certificate.pfx”;
公共字符串ExportPfxPassword{get;}=”“;

但它仍然悬而未决,已经有几天了。我不知道它何时有效。

您不能拥有HTTPS的自签名证书,而是要获得一个真正的证书,或者您必须将证书添加到客户端可信证书存储中

问题是,当尝试建立安全通道时,客户端不信任它收到的证书

在内部正确使用HTTPS是容器之间的最佳实践

要在ASP.NET Core中支持HTTPS,请参阅本文:


今天我还收到了你们的证书表格。使用它们可以自动创建证书。

谢谢您的回答。我喜欢最佳实践。你建议我换什么来让它工作?你说的HTTPS在内部是什么意思?你指的是Kestrel用来支持HTTPS的证书?你能举个例子吗?看我最新的答案谢谢你的更新。我读了这篇文章。我已经做了那个app.UseHttpsRedirection部分了。当我键入HTTP url时,我认为它会重定向到HTTPS。但我看不出这如何解决我的证书问题并使用这个.AddSigningCredential(证书)部分。或者我能把它处理掉吗?我已经看过了LetsEncrypt,但是如何正确地实现它呢。我这里有一个例子:。但它在运行时似乎有错误。我在我的帖子中附加了这个错误。您能在这里帮助我吗?当我使用库生成证书时,/src/examples/ACMECLI中的CLI示例对我来说运行良好。另外,AddSigningCredential不是关于HTTPS的,而是关于如何对JWT令牌进行签名
public string CaName { get; } = Constants.LetsEncryptStagingName;
public IEnumerable<string> Email { get; } = new string[] { "xxx@gmail.com" };
public bool AcceptTos { get; } = true;
public IEnumerable<string> Dns { get; } = new string[] { "xxx.duckdns.org" };
public (bool enabled, int? timeout) WaitForAuthz { get; } = (true, 300);
public bool Finalize { get; } = true;
public string ExportPfx { get; } = @"c:\tmp\certificate.pfx";
public string ExportPfxPassword { get; } = " ";