feat(deployment): add secure Linux runtime (#17)
This commit is contained in:
@@ -3,6 +3,7 @@ using FinalFactory.Rendezvous.Contracts;
|
||||
using FinalFactory.Rendezvous.Server.Abuse;
|
||||
using FinalFactory.Rendezvous.Server.Browser;
|
||||
using FinalFactory.Rendezvous.Server.ConnectionOutcomes;
|
||||
using FinalFactory.Rendezvous.Server.Deployment;
|
||||
using FinalFactory.Rendezvous.Server.Http;
|
||||
using FinalFactory.Rendezvous.Server.JoinAttempts;
|
||||
using FinalFactory.Rendezvous.Server.Observability;
|
||||
@@ -235,8 +236,29 @@ AbuseProtectionOptions configuredAbuseProtection = builder.Configuration
|
||||
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
||||
TrustedProxyForwarding.Configure(options, configuredAbuseProtection));
|
||||
|
||||
DeploymentOptions deploymentOptions = builder.Configuration
|
||||
.GetSection(DeploymentOptions.SectionName)
|
||||
.Get<DeploymentOptions>() ?? new DeploymentOptions();
|
||||
if (!builder.Environment.IsDevelopment() && !isOpenApiGeneration)
|
||||
{
|
||||
IReadOnlyList<string> deploymentErrors = deploymentOptions.ValidateProduction(
|
||||
configuredAbuseProtection,
|
||||
builder.Configuration["AllowedHosts"]);
|
||||
if (deploymentErrors.Count > 0)
|
||||
{
|
||||
throw new DeploymentConfigurationException(deploymentErrors);
|
||||
}
|
||||
}
|
||||
|
||||
builder.Services.AddSingleton(Microsoft.Extensions.Options.Options.Create(deploymentOptions));
|
||||
builder.Services.Configure<HostOptions>(options =>
|
||||
options.ShutdownTimeout = TimeSpan.FromSeconds(deploymentOptions.DrainDeadlineSeconds + 10));
|
||||
|
||||
SystemRendezvousClock rendezvousClock = new();
|
||||
EphemeralStoreOptions stateOptions = new();
|
||||
EphemeralStoreOptions stateOptions = new()
|
||||
{
|
||||
GracefulDrainLifetime = TimeSpan.FromSeconds(deploymentOptions.DrainDeadlineSeconds),
|
||||
};
|
||||
InMemoryEphemeralRendezvousStore stateStore = new(
|
||||
stateOptions,
|
||||
rendezvousClock,
|
||||
@@ -304,10 +326,12 @@ if (!isOpenApiGeneration)
|
||||
builder.Services.AddSingleton<NatMediationProcessor>();
|
||||
builder.Services.AddHostedService(static services =>
|
||||
services.GetRequiredService<UdpMediatorService>());
|
||||
// Hosted services stop in reverse registration order. Drain must complete while
|
||||
// Kestrel and the UDP mediator are still able to finish bounded in-flight work.
|
||||
builder.Services.AddHostedService<GracefulDrainService>();
|
||||
}
|
||||
|
||||
WebApplication app = builder.Build();
|
||||
app.Lifetime.ApplicationStopping.Register(() => stateStore.BeginDrain());
|
||||
|
||||
if (TrustedProxyForwarding.IsEnabled(configuredAbuseProtection))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user