fix(infra): persist Data Protection keys to filesystem for Docker

- Add PersistKeysToFileSystem to /var/lib/heimdall/dp-keys so camera
  credential decryption survives container restarts
- Remove hardcoded connection string fallback, throw instead
- Add Microsoft.AspNetCore.DataProtection.Extensions dependency
This commit is contained in:
Arnaud Dartois committed 2026-07-19 19:33:10 +00:00
1 parent 3f75a20860
commit 32025eae67
5 files changed
+43 -29

No files matched your search

+11 -9
View File
@@ -4,20 +4,22 @@ using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Options;
// ── Sentry (GlitchTip) — DSN from env var, with hardcoded fallback ─
var sentryDsn = Environment.GetEnvironmentVariable("SENTRY_DSN")
?? "https://db94b9fc2f36425f9eb4b9f6f347dc73@glitchtip.tordais.cc/6";
// ── Sentry (GlitchTip) — DSN from env var only ───────────────────
var sentryDsn = Environment.GetEnvironmentVariable("SENTRY_DSN");
var builder = WebApplication.CreateSlimBuilder(args);
// ── Sentry ────────────────────────────────────────────────────────
builder.WebHost.UseSentry(options =>
if (sentryDsn is not null)
{
options.Dsn = sentryDsn;
options.MinimumBreadcrumbLevel = LogLevel.Debug;
options.MinimumEventLevel = LogLevel.Error;
options.TracesSampleRate = 0.1;
});
builder.WebHost.UseSentry(options =>
{
options.Dsn = sentryDsn;
options.MinimumBreadcrumbLevel = LogLevel.Debug;
options.MinimumEventLevel = LogLevel.Error;
options.TracesSampleRate = 0.1;
});
}
// Strongly-typed configuration with validation
builder.Services.AddOptions<AgentOptions>()
+11 -9
View File
@@ -12,20 +12,22 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
// ── Sentry (GlitchTip) — DSN from env var, with hardcoded fallback ─
var sentryDsn = Environment.GetEnvironmentVariable("SENTRY_DSN")
?? "https://db94b9fc2f36425f9eb4b9f6f347dc73@glitchtip.tordais.cc/6";
// ── Sentry (GlitchTip) — DSN from env var only ───────────────────
var sentryDsn = Environment.GetEnvironmentVariable("SENTRY_DSN");
var builder = WebApplication.CreateBuilder(args);
// ── Sentry ────────────────────────────────────────────────────────
builder.WebHost.UseSentry(options =>
if (sentryDsn is not null)
{
options.Dsn = sentryDsn;
options.MinimumBreadcrumbLevel = LogLevel.Debug;
options.MinimumEventLevel = LogLevel.Error;
options.TracesSampleRate = 0.1;
});
builder.WebHost.UseSentry(options =>
{
options.Dsn = sentryDsn;
options.MinimumBreadcrumbLevel = LogLevel.Debug;
options.MinimumEventLevel = LogLevel.Error;
options.TracesSampleRate = 0.1;
});
}
// ── Rate Limiting (Polly/System.Threading.RateLimiting) ───────────
builder.Services.AddRateLimiter(options =>
@@ -1,9 +1,11 @@
using System.IO;
using Heimdall.Application.Services;
using Heimdall.Domain.Entities;
using Heimdall.Infrastructure.Data;
using Heimdall.Infrastructure.Security;
using Heimdall.Infrastructure.Services;
using Heimdall.Infrastructure.Services.Discovery;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
@@ -23,7 +25,8 @@ public static class DependencyInjection
var connectionString = Environment.GetEnvironmentVariable("DATABASE_URL")
?? configuration.GetConnectionString("Default")
?? "Host=localhost;Port=5432;Database=heimdall;Username=heimdall;Password=heimdall";
?? throw new InvalidOperationException(
"Database connection string is not configured. Set DATABASE_URL env var or ConnectionStrings:Default.");
if (isTesting)
{
@@ -58,7 +61,11 @@ public static class DependencyInjection
.AddDefaultTokenProviders();
// Data Protection (for camera credential encryption)
services.AddDataProtection();
// Keys are persisted to /var/lib/heimdall/dp-keys to survive container restarts.
// Without this, Docker container restart permanently breaks camera credential decryption.
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo("/var/lib/heimdall/dp-keys"))
.SetApplicationName("Heimdall");
// JWT
services.AddScoped<IJwtService, JwtService>();
@@ -15,6 +15,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.8" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.Extensions" Version="10.0.8" />
<PackageReference Include="Npgsql" Version="10.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.3" />
</ItemGroup>
+11 -9
View File
@@ -7,20 +7,22 @@ using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Components.Authorization;
using MudBlazor.Services;
// ── Sentry (GlitchTip) — DSN from env var, with hardcoded fallback ─
var sentryDsn = Environment.GetEnvironmentVariable("SENTRY_DSN")
?? "https://db94b9fc2f36425f9eb4b9f6f347dc73@glitchtip.tordais.cc/6";
// ── Sentry (GlitchTip) — DSN from env var only ───────────────────
var sentryDsn = Environment.GetEnvironmentVariable("SENTRY_DSN");
var builder = WebApplication.CreateBuilder(args);
// ── Sentry ────────────────────────────────────────────────────────
builder.WebHost.UseSentry(options =>
if (sentryDsn is not null)
{
options.Dsn = sentryDsn;
options.MinimumBreadcrumbLevel = LogLevel.Debug;
options.MinimumEventLevel = LogLevel.Error;
options.TracesSampleRate = 0.1;
});
builder.WebHost.UseSentry(options =>
{
options.Dsn = sentryDsn;
options.MinimumBreadcrumbLevel = LogLevel.Debug;
options.MinimumEventLevel = LogLevel.Error;
options.TracesSampleRate = 0.1;
});
}
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();