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 System.Collections.Concurrent;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Globalization;
|
||||
@@ -11,9 +12,15 @@ namespace Khaemhat.Data.Sqlite;
|
||||
/// <c>foreign_keys=ON</c> and <c>busy_timeout=5000</c>; file databases use <c>journal_mode=WAL</c>. Databases are files
|
||||
/// under <c>KHAEMHAT_DATA_DIR</c>, or in-memory databases shared by the connections of the process (tests).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// An in-memory database disappears with its last connection: <see cref="EnsureDatabaseExistsAsync"/> opens one that
|
||||
/// stays open for the life of the process (or until <see cref="DropDatabaseAsync"/>), so the database lives as long as
|
||||
/// the instance that created it.
|
||||
/// </remarks>
|
||||
public sealed class SqliteProvider : IDbProvider
|
||||
{
|
||||
private const int BusyTimeoutMilliseconds = 5000;
|
||||
private static readonly ConcurrentDictionary<string, SqliteConnection> MemoryKeepers = new(StringComparer.Ordinal);
|
||||
|
||||
/// <inheritdoc />
|
||||
public DbEngine Engine => DbEngine.Sqlite;
|
||||
@@ -62,6 +69,17 @@ public sealed class SqliteProvider : IDbProvider
|
||||
{
|
||||
if (!IsFile(connectionString))
|
||||
{
|
||||
var name = new SqliteConnectionStringBuilder(connectionString).DataSource;
|
||||
if (!MemoryKeepers.ContainsKey(name))
|
||||
{
|
||||
var keeper = new SqliteConnection(connectionString);
|
||||
await keeper.OpenAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (!MemoryKeepers.TryAdd(name, keeper))
|
||||
{
|
||||
await keeper.DisposeAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -76,6 +94,11 @@ public sealed class SqliteProvider : IDbProvider
|
||||
{
|
||||
if (!IsFile(connectionString))
|
||||
{
|
||||
if (MemoryKeepers.TryRemove(new SqliteConnectionStringBuilder(connectionString).DataSource, out var keeper))
|
||||
{
|
||||
keeper.Dispose();
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user