Add configuration, OIDC auth wiring and discovery endpoints (M1)

Options, JWT bearer validation, the /meta and .well-known endpoints, and a dev compose
stack with Keycloak. Verified end to end: compose up, migrate, run, both discovery
endpoints return correct payloads, and readiness reports the schema current.

Configuration:
- Strongly-typed options for Server, Oidc, Relay and Sync, all ValidateOnStart. A
  self-hosted server that boots half-configured and fails later per-request is far harder
  to diagnose than one that refuses to start and names the bad setting.
- Cross-field validation the annotations cannot express: relay needs a WebSocketUrl when
  enabled, idle timeout must be under max session duration, item payload cap under batch cap.
- Startup warnings for combinations that are individually valid but dangerous together:
  RequireHttpsMetadata false outside Development, and AllowEmailLinking (which turns any
  token bearing a victim's email into account takeover, hence default false).

Auth:
- JwtBearer with ClockSkew cut to 30s from the 5-minute default; five minutes of slack on a
  credential granting vault ciphertext access is more than any clock needs.
- IncludeErrorDetails off, and a FallbackPolicy so an endpoint without an explicit policy
  still requires a caller rather than silently being public.

Discovery, per ADR 0002:
- /api/v1/meta reports versions, features and push caps.
- /.well-known/dodossh-configuration is the onboarding story: the user types one server URL
  and the client discovers OIDC authority, client id, scopes and relay endpoint.

Two environment problems found by actually running the stack:
- PostgreSQL 18 changed its data mount point. Mounting /var/lib/postgresql/data — correct
  through 17 — makes the image refuse to start; 18+ wants a single mount at
  /var/lib/postgresql with the cluster in a subdirectory.
- Keycloak moved to host port 18080. An unrelated Apache Tomcat on this machine holds
  127.0.0.1:8080, and a loopback-specific bind beats Docker's 0.0.0.0 publish for
  "localhost". It presents as Keycloak 404ing every realm while its own log says the import
  succeeded, which is a genuinely misleading failure.

Also: CA1848 is enforced, not advisory — warnings are errors, so the .editorconfig comment
claiming otherwise was wrong. Startup and health logging now uses [LoggerMessage]. And a
clean rebuild is back to zero warnings; the incremental build had been hiding 40 in test
projects (banned Guid.NewGuid, an obsolete Testcontainers constructor, and two analyzer
families that are genuinely noise under a test host).

Verified: 0 warnings on a clean rebuild, 122 tests pass, format clean.
This commit is contained in:
2026-07-28 14:33:54 +02:00
parent eaf68c86b0
commit d3b14e6bc0
19 changed files with 941 additions and 16 deletions
@@ -14,8 +14,10 @@ namespace DodoSSH.Infrastructure.Tests;
/// </remarks>
public sealed class PostgresFixture : IAsyncLifetime
{
private readonly PostgreSqlContainer container = new PostgreSqlBuilder()
.WithImage("postgres:18-alpine")
// Image passed to the constructor: the parameterless overload is obsolete in
// Testcontainers 4.13 and pinning the tag here keeps the test image in step with the one
// deploy/docker-compose.dev.yml uses.
private readonly PostgreSqlContainer container = new PostgreSqlBuilder("postgres:18-alpine")
.WithDatabase("dodossh")
.WithUsername("postgres")
.WithPassword("test")
@@ -312,7 +312,7 @@ public sealed class SchemaConstraintTests(PostgresFixture fixture)
public async Task User_IsUniquePerIssuerAndSubject()
{
await using var context = fixture.CreateContext();
var subject = Guid.NewGuid().ToString();
var subject = Guid.CreateVersion7().ToString();
context.Users.Add(NewUser("https://idp.example", subject));
await context.SaveChangesAsync();
@@ -329,7 +329,7 @@ public sealed class SchemaConstraintTests(PostgresFixture fixture)
{
// Multi-issuer from the start: the issuer is part of the identity, not a detail.
await using var context = fixture.CreateContext();
var subject = Guid.NewGuid().ToString();
var subject = Guid.CreateVersion7().ToString();
context.Users.Add(NewUser("https://idp-a.example", subject));
context.Users.Add(NewUser("https://idp-b.example", subject));
@@ -342,14 +342,14 @@ public sealed class SchemaConstraintTests(PostgresFixture fixture)
{
// citext: an attacker must not be able to register Alice@x with alice@x already present.
await using var context = fixture.CreateContext();
var local = $"user{Guid.NewGuid():N}";
var local = $"user{Guid.CreateVersion7():N}";
var first = NewUser("https://idp.example", Guid.NewGuid().ToString());
var first = NewUser("https://idp.example", Guid.CreateVersion7().ToString());
first.Email = $"{local}@example.com";
context.Users.Add(first);
await context.SaveChangesAsync();
var second = NewUser("https://idp.example", Guid.NewGuid().ToString());
var second = NewUser("https://idp.example", Guid.CreateVersion7().ToString());
second.Email = $"{local.ToUpperInvariant()}@EXAMPLE.COM";
context.Users.Add(second);
@@ -470,7 +470,7 @@ public sealed class SchemaConstraintTests(PostgresFixture fixture)
private static async Task<UserAccount> SeedUserAsync(DodoDbContext context)
{
var user = NewUser("https://idp.example", Guid.NewGuid().ToString());
var user = NewUser("https://idp.example", Guid.CreateVersion7().ToString());
context.Users.Add(user);
await context.SaveChangesAsync();
return user;
@@ -482,7 +482,7 @@ public sealed class SchemaConstraintTests(PostgresFixture fixture)
{
Id = Guid.CreateVersion7(),
Name = "Team",
Slug = $"team-{Guid.NewGuid():N}",
Slug = $"team-{Guid.CreateVersion7():N}",
CreatedByUserId = createdBy,
CreatedAtUtc = Now,
};
@@ -551,7 +551,7 @@ public sealed class SchemaConstraintTests(PostgresFixture fixture)
Generation = generation,
EncryptionPublicKey = new byte[32],
SigningPublicKey = new byte[32],
FingerprintSha256 = Guid.NewGuid().ToByteArray().Concat(Guid.NewGuid().ToByteArray()).ToArray(),
FingerprintSha256 = Guid.CreateVersion7().ToByteArray().Concat(Guid.CreateVersion7().ToByteArray()).ToArray(),
Statement = "{}",
StatementSignature = new byte[64],
IsCurrent = isCurrent,