feat: system and security - start-up, accounts, sign-in, licences, log, jobs, companies (M2)
CI / Build and test (SQLite) (pull_request) Successful in 55s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / YAML check (pull_request) Successful in 5s
CI / Docker image (pull_request) Failing after 2m4s
CI / Build and test (SQLite) (pull_request) Successful in 55s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / YAML check (pull_request) Successful in 5s
CI / Docker image (pull_request) Failing after 2m4s
The instance now starts on its own from KHAEMHAT_* variables: it migrates the system and company databases, creates the super user and the first company, and only then reports ready. Users sign in with password and TOTP through revocable database sessions, and licences decide which modules and how many companies are available. - Configuration: every wrong variable reported at once (exit code 2), _FILE variants - Accounts, password policy and lockout, TOTP with recovery codes, session states with token rotation, security audit with a hash chain - Sign-in pages (mockups 001-003), authorization attributes, security headers and a CSP without inline scripts, login rate limit - Signed licences, activation codes, test mode, licence tool - DataProtection keys in the system database, encrypted with the instance key - Memory or Redis cache (in-house RESP client) that falls back to memory - Database log by section with trace id; cron scheduler with locks and system jobs; record history (audit_log) - Company creation, states, company context and X-Company, 503 in maintenance - In-memory SQLite databases stay alive for the process (tests, demo) - Tests for all of the above, ADR 0019, wiki, SECURITY, CHANGELOG, STATUS, DATA-MODEL Refs #15 #16 #17 #18 #19 #20 #21 #22 #23 #24 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4582837b70
commit
032c602b49
107 files changed
+12202
-116
No files matched your search
@@ -1,3 +1,4 @@
|
||||
using Khaemhat.Application.Instance;
|
||||
using Khaemhat.Core.Common;
|
||||
|
||||
namespace Khaemhat.Web.Hosting;
|
||||
@@ -5,13 +6,14 @@ namespace Khaemhat.Web.Hosting;
|
||||
/// <summary>
|
||||
/// Health endpoints for Docker and reverse proxies (SPEC §16.1, ADR 0012):
|
||||
/// <c>/health/live</c> says the process answers (the image HEALTHCHECK), <c>/health/ready</c> says it can serve
|
||||
/// requests (from M1 it also checks the system database), <c>/health</c> summarises both with the version.
|
||||
/// requests (the start sequence completed: databases migrated), <c>/health</c> summarises both with the version.
|
||||
/// They carry no personal or configuration data and need no authentication.
|
||||
/// </summary>
|
||||
public static class HealthEndpoints
|
||||
{
|
||||
/// <summary>Maps the three health endpoints.</summary>
|
||||
/// <param name="endpoints">The application's route builder.</param>
|
||||
/// <returns>The route builder.</returns>
|
||||
public static IEndpointRouteBuilder MapHealthEndpoints(this IEndpointRouteBuilder endpoints)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(endpoints);
|
||||
@@ -19,22 +21,26 @@ public static class HealthEndpoints
|
||||
endpoints.MapGet("/health/live", () => Results.Text("live", "text/plain"))
|
||||
.ExcludeFromDescription();
|
||||
|
||||
endpoints.MapGet("/health/ready", () => Results.Text("ready", "text/plain"))
|
||||
endpoints.MapGet("/health/ready", (BootstrapState state) => state.IsReady
|
||||
? Results.Text("ready", "text/plain")
|
||||
: Results.Text(state.Phase == BootstrapPhase.Failed ? "failed" : "starting", "text/plain", statusCode: StatusCodes.Status503ServiceUnavailable))
|
||||
.ExcludeFromDescription();
|
||||
|
||||
endpoints.MapGet("/health", (ProductVersion version) => Results.Json(new HealthReport(
|
||||
Status: "ok",
|
||||
Live: true,
|
||||
Ready: true,
|
||||
Version: version.Version,
|
||||
Revision: version.Revision)))
|
||||
endpoints.MapGet("/health", (ProductVersion version, BootstrapState state) => Results.Json(
|
||||
new HealthReport(
|
||||
Status: state.IsReady ? "ok" : state.Phase == BootstrapPhase.Failed ? "failed" : "starting",
|
||||
Live: true,
|
||||
Ready: state.IsReady,
|
||||
Version: version.Version,
|
||||
Revision: version.Revision),
|
||||
statusCode: state.IsReady ? StatusCodes.Status200OK : StatusCodes.Status503ServiceUnavailable))
|
||||
.ExcludeFromDescription();
|
||||
|
||||
return endpoints;
|
||||
}
|
||||
|
||||
/// <summary>The body of <c>/health</c>.</summary>
|
||||
/// <param name="Status"><c>ok</c> when the instance is live and ready.</param>
|
||||
/// <param name="Status"><c>ok</c> when the instance is live and ready, <c>starting</c> or <c>failed</c> otherwise.</param>
|
||||
/// <param name="Live">Whether the process answers.</param>
|
||||
/// <param name="Ready">Whether the instance can serve requests.</param>
|
||||
/// <param name="Version">Product version (SemVer).</param>
|
||||
|
||||
Reference in new issue
Block a user