Skip to content

Commit

Permalink
Add setting to disable HTTPS
Browse files Browse the repository at this point in the history
To avoid crashes due to race condition as described at <natemcmaster/LettuceEncrypt#293>
  • Loading branch information
Viir committed Mar 22, 2024
1 parent 877c369 commit 6a484c7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions implement/elm-time/Platform/WebService/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public static class Configuration

public static string DisableLetsEncryptSettingKey => "disableLetsEncrypt";

public static string DisableHttpsSettingKey => "disableHttps";

public static string[] PublicWebHostUrlsDefault => ["http://*", "https://*"];

/// <summary>
Expand Down
15 changes: 10 additions & 5 deletions implement/elm-time/Platform/WebService/PublicAppState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public WebApplication Build(
WebApplicationBuilder appBuilder,
IHostEnvironment env,
IReadOnlyList<string> publicWebHostUrls,
bool? disableLetsEncrypt)
bool? disableLetsEncrypt,
bool disableHttps)
{
appBuilder.Services.AddLogging(logging =>
{
Expand All @@ -110,16 +111,17 @@ public WebApplication Build(
serverAndElmAppConfig.ServerConfig?.letsEncryptOptions is not null && !(disableLetsEncrypt ?? false);

var publicWebHostUrlsFilteredForHttps =
canUseHttps
canUseHttps && !disableHttps
?
publicWebHostUrls
:
publicWebHostUrls
.Where(url => !url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
.ToImmutableArray();

logger.LogInformation("disableLetsEncrypt: {disableLetsEncrypt}", (disableLetsEncrypt?.ToString() ?? "null"));
logger.LogInformation("disableLetsEncrypt: {disableLetsEncrypt}", disableLetsEncrypt?.ToString() ?? "null");
logger.LogInformation("canUseHttps: {canUseHttps}", canUseHttps);
logger.LogInformation("disableHttps: {disableHttps}", disableHttps);

var webHostBuilder =
appBuilder.WebHost
Expand Down Expand Up @@ -200,7 +202,9 @@ private void ConfigureServices(
}
else
{
logger.LogInformation("I found 'letsEncryptOptions' in the configuration.");
logger.LogInformation(
"I found 'letsEncryptOptions' in the configuration: {letsEncryptOptions}",
System.Text.Json.JsonSerializer.Serialize(letsEncryptOptions));
services.AddFluffySpoonLetsEncrypt(letsEncryptOptions);
services.AddFluffySpoonLetsEncryptFileCertificatePersistence();
services.AddFluffySpoonLetsEncryptMemoryChallengePersistence();
Expand Down Expand Up @@ -734,4 +738,5 @@ public record ServerAndElmAppConfig(
Func<string, Result<string, StateShim.InterfaceToHost.FunctionApplicationResult>> ProcessEventInElmApp,
PineValue SourceComposition,
InterfaceToHost.BackendEventResponseStruct? InitOrMigrateCmds,
bool? DisableLetsEncrypt);
bool? DisableLetsEncrypt,
bool DisableHttps);
11 changes: 9 additions & 2 deletions implement/elm-time/Platform/WebService/StartupAdminInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public void Configure(
configuration?.GetValue<string>(Configuration.DisableLetsEncryptSettingKey)
?.Equals("true", StringComparison.InvariantCultureIgnoreCase);

var disableHttps =
configuration?.GetValue<string>(Configuration.DisableHttpsSettingKey)
?.Equals("true", StringComparison.InvariantCultureIgnoreCase)
?? false;

object avoidConcurrencyLock = new();

var processStoreFileStore = processStoreForFileStore.fileStore;
Expand Down Expand Up @@ -257,7 +262,8 @@ WebApplication buildWebApplication(
},
SourceComposition: processAppConfig.appConfigComponent,
InitOrMigrateCmds: restoreProcessOk.initOrMigrateCmds,
DisableLetsEncrypt: disableLetsEncrypt
DisableLetsEncrypt: disableLetsEncrypt,
DisableHttps: disableHttps
);

var publicAppState = new PublicAppState(
Expand All @@ -271,7 +277,8 @@ WebApplication buildWebApplication(
appBuilder,
env,
publicWebHostUrls: publicWebHostUrls,
disableLetsEncrypt: disableLetsEncrypt);
disableLetsEncrypt: disableLetsEncrypt,
disableHttps: disableHttps);

publicAppState.ProcessEventTimeHasArrived();

Expand Down

0 comments on commit 6a484c7

Please sign in to comment.