Files
Chronos/src/Titano.Server/Hosting/ServerCommandLine.cs
T
Claude df2d4b4316 fix(server): refuse planted Windows data, guard new archives, trust only loopback proxies
- Windows data folder: the folder and everything in it must belong to SYSTEM,
  Administrators or the server's account and hold no link, checked before the
  ACL is rewritten; otherwise the server stops and names the entry. server.json
  is read only after its owner is checked on the open handle. Secrets are
  deleted and created anew with the private ACL, so a planted file's owner
  loses its rights.
- Windows archive: a folder the server creates is changeable only by those
  accounts (users may read it) and a .titano folder it creates is private; an
  existing archive others can change is logged as a warning at start.
- Proxy mode: only loopback is trusted by default, since LAN clients reach the
  HTTP port from private addresses; a cookie sign-in that did not come through
  a trusted proxy over HTTPS answers proxy_untrusted, naming
  TITANO_TRUSTED_PROXIES.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-12 11:08:12 +00:00

78 lines
3.6 KiB
C#

namespace Titano.Server.Hosting;
/// <summary>What <c>Titano.Server</c> was asked to do.</summary>
public enum ServerCommand
{
/// <summary>Run in the console (Docker, Linux, development).</summary>
Run,
/// <summary>Run under the Windows Service Control Manager (the command line the installed service uses).</summary>
Service,
InstallService,
UninstallService,
/// <summary>Probe <c>/health</c> of the local server and exit 0/1 (container health check).</summary>
HealthCheck,
Help,
}
/// <summary>Command-line switches of the server; anything else is passed on to the web host.</summary>
public sealed record ServerCommandLine(ServerCommand Command, IReadOnlyList<string> HostArguments, string? Error)
{
public const string Usage = """
Titano Server — time-lapse archive, uploads, jobs and rendering.
Usage: Titano.Server [--service | --install-service | --uninstall-service | --healthcheck | --help]
(no switch) run in the console until Ctrl+C
--service run under the Windows Service Control Manager
--install-service register the "TitanoServer" Windows service (automatic start, LocalSystem)
--uninstall-service stop and remove the Windows service
--healthcheck exit 0 when the local server answers /health, 1 otherwise
Configuration: /data/server.json (TITANO_DATA_PATH) overridden by environment variables:
TITANO_ARCHIVE_PATH TITANO_DATA_PATH TITANO_SERVER_NAME TITANO_ADMIN_USER TITANO_ADMIN_PASSWORD
TITANO_DB (postgres | sqlite | connection string) TITANO_DB_HOST TITANO_DB_PORT TITANO_DB_NAME TITANO_DB_USER
TITANO_DB_PASSWORD TITANO_DB_SSLMODE TITANO_HTTP_PORT TITANO_HTTPS_PORT TITANO_TLS_MODE (auto | pem | proxy)
TITANO_TLS_CERT TITANO_TLS_KEY TITANO_LANG TITANO_WORKERS
TITANO_LOG_LEVEL (Trace | Debug | Information | Warning | Error)
TITANO_DISCOVERY LAN beacon (true | false); in a container it needs host networking
TITANO_PUBLIC_HTTP_PORT, TITANO_PUBLIC_HTTPS_PORT
ports clients reach when the container's ports are published as other host ports
(admin redirect to HTTPS, LAN beacon)
TITANO_TRUSTED_PROXIES proxy mode: addresses or networks (CIDR) whose X-Forwarded-* headers count
(default: loopback only; list a proxy in another container or on another machine)
Container image only: PUID, PGID (user and group the server runs as, owners of /data), TZ (local time zone)
""";
public static ServerCommandLine Parse(IReadOnlyList<string> args)
{
var command = ServerCommand.Run;
var rest = new List<string>();
string? error = null;
foreach (var arg in args)
{
ServerCommand? parsed = arg switch
{
"--service" => ServerCommand.Service,
"--install-service" => ServerCommand.InstallService,
"--uninstall-service" => ServerCommand.UninstallService,
"--healthcheck" => ServerCommand.HealthCheck,
"--help" or "-h" or "-?" or "/?" => ServerCommand.Help,
_ => null,
};
if (parsed is not { } switchCommand)
{
rest.Add(arg);
continue;
}
if (command != ServerCommand.Run && command != switchCommand) error = $"{arg} cannot be combined with another command switch.";
command = switchCommand;
}
return new ServerCommandLine(command, rest, error);
}
}