fix(gateway): harden self-signed cert persistence and config validation
This commit is contained in:
@@ -18,6 +18,13 @@ public static class KestrelTlsInspector
|
||||
/// </summary>
|
||||
public static bool RequiresGeneratedCertificate(IConfiguration configuration)
|
||||
{
|
||||
// A Kestrel default certificate applies to every endpoint that lacks its own.
|
||||
// If the operator configured one, the gateway must not override it.
|
||||
if (HasConfiguredCertificate(configuration.GetSection("Kestrel:Certificates:Default")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IConfigurationSection endpoints = configuration.GetSection("Kestrel:Endpoints");
|
||||
foreach (IConfigurationSection endpoint in endpoints.GetChildren())
|
||||
{
|
||||
@@ -28,13 +35,7 @@ public static class KestrelTlsInspector
|
||||
continue;
|
||||
}
|
||||
|
||||
IConfigurationSection certificate = endpoint.GetSection("Certificate");
|
||||
bool hasOwnCertificate =
|
||||
!string.IsNullOrWhiteSpace(certificate["Path"]) ||
|
||||
!string.IsNullOrWhiteSpace(certificate["Subject"]) ||
|
||||
!string.IsNullOrWhiteSpace(certificate["Thumbprint"]);
|
||||
|
||||
if (!hasOwnCertificate)
|
||||
if (!HasConfiguredCertificate(endpoint.GetSection("Certificate")))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -42,4 +43,9 @@ public static class KestrelTlsInspector
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool HasConfiguredCertificate(IConfigurationSection certificate)
|
||||
=> !string.IsNullOrWhiteSpace(certificate["Path"]) ||
|
||||
!string.IsNullOrWhiteSpace(certificate["Subject"]) ||
|
||||
!string.IsNullOrWhiteSpace(certificate["Thumbprint"]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user