【发布时间】:2021-07-26 06:20:52
【问题描述】:
我的客户端 WebApp(作为单独的 Linux docker 映像端口 4443 运行)上总是出现以下错误:
System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'https://host.docker.internal:8443/.well-known/openid-configuration'.
---> System.IO.IOException: IDX20804: Unable to retrieve document from: 'https://host.docker.internal:8443/.well-known/openid-configuration'.
---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
它连接到我的 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;
...
});
我认为我正在创建的证书有问题,这两个 docker 映像上都没有。但是 Docker 容器都使用 HTTPS 运行,否则根本不会启动。我在这里错过了什么?
让我们按照下面评论中的建议由 LetsEncrypt 来做吧。 我下载并运行这个项目 (src:https://github.com/PKISharp/ACMESharpCore/tree/master/src/examples/ACMECLI) 设置以下属性:
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; } = " ";
但它仍然悬而未决,已经有几天了。我不知道它什么时候有效。
【问题讨论】:
标签: docker asp.net-core ssl identityserver4 x509certificate2