fix: owner review 3 phase 1: server ports for clients, screenshot baselines (#16)
CI / Build and test (push) Successful in 9m36s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 9s
Release / Build, test and publish (push) Successful in 14m4s
CI / PostgreSQL 16 integration (push) Successful in 8m26s
CI / PostgreSQL 17 integration (push) Successful in 8m43s
CI / Docker image (push) Successful in 50s
Release / Server image (push) Successful in 1m23s
CI / Build and test (push) Successful in 9m36s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 9s
Release / Build, test and publish (push) Successful in 14m4s
CI / PostgreSQL 16 integration (push) Successful in 8m26s
CI / PostgreSQL 17 integration (push) Successful in 8m43s
CI / Docker image (push) Successful in 50s
Release / Server image (push) Successful in 1m23s
Clients could not reach a server in a container whose ports are published as other host ports: the panel showed the container's ports, the template had no public HTTP port, and a bare host meant port 443. Public ports become panel settings, the panel shows the client address, both clients default to 8443, and an address that answers as another service is named as not a Chronos server (its certificate never offered for trust). The screenshot baselines are captured on the development PC and committed; measured values are fixed while the capture runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #16.
This commit is contained in:
1 parent
30a5b03f37
commit
255e149087
306 files changed
+2023
-206
No files matched your search
@@ -14,7 +14,8 @@ namespace Chronos.Server.Configuration;
|
||||
/// The admin panel's view of the configuration (BRIEF §14.8 Settings). Saving writes <c>/data/server.json</c> (only the
|
||||
/// edited keys; secrets and environment values are never written) and applies what can change while running, the
|
||||
/// parallelism and the priority queue included (owner review 1), and the log settings through <see cref="ServerLogging"/>
|
||||
/// (owner review 2, R11); ports, TLS and chunk size wait for a restart. Job history is what the housekeeping system
|
||||
/// (owner review 2, R11), and the public ports clients use (owner review 3); the listening ports, TLS and chunk size wait for
|
||||
/// a restart. In a container the listening ports are locked: the template maps them. Job history is what the housekeeping system
|
||||
/// schedule is reset to (owner review 2, R10): the schedule's own value applies. The audit retention kept here is what the
|
||||
/// audit clean-up schedule is reset to; the endpoint shows that schedule's age limit in its place and puts a new one there
|
||||
/// (<c>SchedulerHost.AuditRetentionAsync</c>, <c>SchedulerHost.ApplyAuditRetentionAsync</c>).
|
||||
@@ -43,22 +44,39 @@ public sealed class ServerSettingsStore(ServerOptions options, ServerLogging log
|
||||
/// <summary>Validates and saves; returns the error code and the offending setting, or null on success.</summary>
|
||||
public (string Code, string Setting)? Save(ServerSettingsDto request)
|
||||
{
|
||||
// A panel without the log group keeps the log settings as they are.
|
||||
if (request.Logs is null) request = request with { Logs = Current().Logs };
|
||||
if (Validate(request) is { } invalid) return ("invalid_setting", invalid);
|
||||
var before = Current();
|
||||
// A panel without the log group keeps the log settings as they are, and a client without the public ports keeps
|
||||
// them too (owner review 3: null keeps a public port, 0 clears it).
|
||||
request = request with
|
||||
{
|
||||
Logs = request.Logs ?? before.Logs,
|
||||
PublicHttpPort = Public(request.PublicHttpPort, before.PublicHttpPort),
|
||||
PublicHttpsPort = Public(request.PublicHttpsPort, before.PublicHttpsPort),
|
||||
};
|
||||
if (Validate(request, before) is { } invalid) return ("invalid_setting", invalid);
|
||||
lock (_gate)
|
||||
{
|
||||
var current = _saved ?? Snapshot(options, restartRequired: false);
|
||||
var changes = Changes(current, request);
|
||||
if (changes.FirstOrDefault(c => options.Locked.Contains(c.Name)) is { Name: { } locked }) return ("setting_locked", locked);
|
||||
if (changes.Count == 0) return null;
|
||||
var fixedSettings = LockedSettings(options);
|
||||
if (changes.FirstOrDefault(c => fixedSettings.Contains(c.Name)) is { Name: { } locked }) return ("setting_locked", locked);
|
||||
// In a container the listening ports are the template's: ports an earlier version saved are dropped at the first
|
||||
// save, so the start stops warning about them (owner review 3).
|
||||
var dropPorts = options.InContainer && options.IgnoredSavedPorts;
|
||||
if (changes.Count == 0 && !dropPorts) return null;
|
||||
|
||||
var file = File.Exists(options.SettingsFile) ? JsonNode.Parse(File.ReadAllText(options.SettingsFile)) as JsonObject ?? [] : [];
|
||||
foreach (var (name, value) in changes) file[name] = value;
|
||||
// The former name of the parallelism (jobs run at once before owner review 1) would set it again at the next start.
|
||||
if (changes.Any(c => c.Name == nameof(ServerOptions.Parallelism))) file.Remove("Workers");
|
||||
if (options.InContainer)
|
||||
{
|
||||
file.Remove(nameof(ServerOptions.HttpPort));
|
||||
file.Remove(nameof(ServerOptions.HttpsPort));
|
||||
}
|
||||
Directory.CreateDirectory(options.DataPath);
|
||||
AtomicFile.WriteAllText(options.SettingsFile, file.ToJsonString(new JsonSerializerOptions { WriteIndented = true }));
|
||||
if (dropPorts) options.IgnoredSavedPorts = false;
|
||||
|
||||
options.ServerName = request.ServerName.Trim();
|
||||
options.Discovery = request.Discovery;
|
||||
@@ -79,6 +97,9 @@ public sealed class ServerSettingsStore(ServerOptions options, ServerLogging log
|
||||
options.LogRotation = Rotation(logs.Rotation);
|
||||
options.AuditRetentionDays = logs.AuditRetentionDays;
|
||||
options.DiagnosticsLogMb = logs.DiagnosticsLogMb;
|
||||
// Read by LAN discovery and the admin redirect at every use: they apply at once.
|
||||
options.PublicHttpPort = request.PublicHttpPort;
|
||||
options.PublicHttpsPort = request.PublicHttpsPort;
|
||||
logging.Apply(options);
|
||||
var restart = request.HttpPort != options.HttpPort || request.HttpsPort != options.HttpsPort
|
||||
|| !string.Equals(request.TlsMode, options.TlsMode.ToString(), StringComparison.OrdinalIgnoreCase)
|
||||
@@ -89,10 +110,11 @@ public sealed class ServerSettingsStore(ServerOptions options, ServerLogging log
|
||||
ServerName = request.ServerName.Trim(),
|
||||
JobPriorities = Priorities(PriorityQueue(options)),
|
||||
Logs = Logs(options),
|
||||
Locked = [.. options.Locked],
|
||||
Locked = fixedSettings,
|
||||
LockedBy = LockedBy(options),
|
||||
RestartRequired = restart,
|
||||
ProxyWarning = false,
|
||||
InContainer = options.InContainer,
|
||||
};
|
||||
return null;
|
||||
}
|
||||
@@ -101,11 +123,31 @@ public sealed class ServerSettingsStore(ServerOptions options, ServerLogging log
|
||||
private static ServerSettingsDto Snapshot(ServerOptions o, bool restartRequired) => new(
|
||||
o.ServerName, o.HttpPort, o.HttpsPort, o.TlsMode.ToString().ToLowerInvariant(), o.TlsCert, o.TlsKey, o.Language, o.Parallelism, o.PriorityQueue,
|
||||
Priorities(PriorityQueue(o)), o.Discovery, o.MaxUploadBytes, o.ChunkSizeBytes, o.JobHistoryDays, o.TokenLifetimeDays, o.UploadRetentionHours,
|
||||
Logs(o), [.. o.Locked], LockedBy(o), restartRequired, ProxyWarning: false);
|
||||
Logs(o), LockedSettings(o), LockedBy(o), restartRequired, ProxyWarning: false, o.PublicHttpPort, o.PublicHttpsPort, o.InContainer);
|
||||
|
||||
/// <summary>The variable that fixes every locked setting (for one a test locks directly, the variable that would).</summary>
|
||||
private static Dictionary<string, string> LockedBy(ServerOptions o) => o.Locked.Distinct(StringComparer.Ordinal).ToDictionary(s => s,
|
||||
s => o.LockedBy.TryGetValue(s, out var variable) ? variable : ServerOptions.VariableOf(s) ?? s, StringComparer.Ordinal);
|
||||
/// <summary>The listening ports, which a container's template maps (owner review 3).</summary>
|
||||
private static readonly string[] ContainerPorts = [nameof(ServerOptions.HttpPort), nameof(ServerOptions.HttpsPort)];
|
||||
|
||||
/// <summary>Settings the panel cannot change: those environment variables fix and, in a container, its listening ports.</summary>
|
||||
private static List<string> LockedSettings(ServerOptions o) =>
|
||||
[.. o.Locked.Concat(o.InContainer ? ContainerPorts : []).Distinct(StringComparer.Ordinal)];
|
||||
|
||||
/// <summary>
|
||||
/// The variable that fixes every locked setting (for one a test locks directly, the variable that would); a container's
|
||||
/// port that no variable of its own sets is fixed by <see cref="ServerOptions.ContainerVariable"/>.
|
||||
/// </summary>
|
||||
private static Dictionary<string, string> LockedBy(ServerOptions o) => LockedSettings(o).ToDictionary(s => s,
|
||||
s => o.LockedBy.TryGetValue(s, out var variable) ? variable
|
||||
: o.InContainer && ContainerPorts.Contains(s) ? ServerOptions.ContainerVariable
|
||||
: ServerOptions.VariableOf(s) ?? s, StringComparer.Ordinal);
|
||||
|
||||
/// <summary>A public port as a request sets it: null keeps <paramref name="current"/>, 0 clears it (the listening port applies).</summary>
|
||||
private static int? Public(int? requested, int? current) => requested switch
|
||||
{
|
||||
null => current,
|
||||
0 => null,
|
||||
_ => requested,
|
||||
};
|
||||
|
||||
private static LogSettingsDto Logs(ServerOptions o) => new(ServerLogging.Wire(o.LogLevel), ServerLogging.Wire(o.ConsoleLogLevel), o.LogRetentionDays,
|
||||
o.LogMaxFileMb, o.LogMaxTotalMb, ServerLogging.Wire(o.LogRotation), o.AuditRetentionDays, o.DiagnosticsLogMb);
|
||||
@@ -131,11 +173,18 @@ public sealed class ServerSettingsStore(ServerOptions options, ServerLogging log
|
||||
return levels;
|
||||
}
|
||||
|
||||
private static string? Validate(ServerSettingsDto r)
|
||||
/// <summary>
|
||||
/// The first setting of <paramref name="r"/> out of range, or null. Listening ports are checked only when they change,
|
||||
/// so a value the panel cannot change (a container's, the test server's 0) never blocks saving the others.
|
||||
/// </summary>
|
||||
private static string? Validate(ServerSettingsDto r, ServerSettingsDto current)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(r.ServerName) || r.ServerName.Trim().Length > 60) return nameof(ServerOptions.ServerName);
|
||||
if (r.HttpPort is < 1 or > 65535) return nameof(ServerOptions.HttpPort);
|
||||
if (r.HttpsPort is < 1 or > 65535 || r.HttpsPort == r.HttpPort) return nameof(ServerOptions.HttpsPort);
|
||||
var portsChanged = r.HttpPort != current.HttpPort || r.HttpsPort != current.HttpsPort;
|
||||
if (portsChanged && r.HttpPort is < 1 or > 65535) return nameof(ServerOptions.HttpPort);
|
||||
if (portsChanged && (r.HttpsPort is < 1 or > 65535 || r.HttpsPort == r.HttpPort)) return nameof(ServerOptions.HttpsPort);
|
||||
if (r.PublicHttpPort is < 1 or > 65535) return nameof(ServerOptions.PublicHttpPort);
|
||||
if (r.PublicHttpsPort is < 1 or > 65535) return nameof(ServerOptions.PublicHttpsPort);
|
||||
if (!Enum.TryParse<TlsMode>(r.TlsMode, ignoreCase: true, out var tls) || !Enum.IsDefined(tls)) return nameof(ServerOptions.TlsMode);
|
||||
if (tls == TlsMode.Pem && (string.IsNullOrWhiteSpace(r.TlsCert) || !File.Exists(r.TlsCert))) return nameof(ServerOptions.TlsCert);
|
||||
if (tls == TlsMode.Pem && (string.IsNullOrWhiteSpace(r.TlsKey) || !File.Exists(r.TlsKey))) return nameof(ServerOptions.TlsKey);
|
||||
@@ -166,6 +215,9 @@ public sealed class ServerSettingsStore(ServerOptions options, ServerLogging log
|
||||
Add(nameof(ServerOptions.ServerName), a.ServerName, b.ServerName.Trim(), v => JsonValue.Create(v));
|
||||
Add(nameof(ServerOptions.HttpPort), a.HttpPort, b.HttpPort, v => JsonValue.Create(v));
|
||||
Add(nameof(ServerOptions.HttpsPort), a.HttpsPort, b.HttpsPort, v => JsonValue.Create(v));
|
||||
// A cleared public port is stored as null, so server.json no longer sets it.
|
||||
Add(nameof(ServerOptions.PublicHttpPort), a.PublicHttpPort, b.PublicHttpPort, v => v is { } port ? JsonValue.Create(port) : null);
|
||||
Add(nameof(ServerOptions.PublicHttpsPort), a.PublicHttpsPort, b.PublicHttpsPort, v => v is { } port ? JsonValue.Create(port) : null);
|
||||
Add(nameof(ServerOptions.TlsMode), a.TlsMode.ToLowerInvariant(), b.TlsMode.ToLowerInvariant(), v => JsonValue.Create(v));
|
||||
Add(nameof(ServerOptions.TlsCert), a.TlsCert, b.TlsCert, v => v is null ? null : JsonValue.Create(v));
|
||||
Add(nameof(ServerOptions.TlsKey), a.TlsKey, b.TlsKey, v => v is null ? null : JsonValue.Create(v));
|
||||
|
||||
Reference in new issue
Block a user