Read admin password from env var in production

This commit is contained in:
2026-03-04 00:09:19 +02:00
parent 109cbb29e2
commit b361f46afa
3 changed files with 9 additions and 7 deletions

View File

@@ -25,6 +25,13 @@ public class Program
var authOptions = builder.Configuration.GetSection("Auth").Get<AuthOptions>() var authOptions = builder.Configuration.GetSection("Auth").Get<AuthOptions>()
?? throw new InvalidOperationException("Auth configuration was not found."); ?? throw new InvalidOperationException("Auth configuration was not found.");
if (builder.Environment.IsProduction())
{
authOptions.Admin.Password =
Environment.GetEnvironmentVariable("KLAPI_ADMIN_PASSWORD")
?? throw new InvalidOperationException("Admin password must be set in production environment using KLAPI_ADMIN_PASSWORD environment variable.");
}
if (string.IsNullOrWhiteSpace(authOptions.SigningKey) || authOptions.SigningKey.Length < 32) if (string.IsNullOrWhiteSpace(authOptions.SigningKey) || authOptions.SigningKey.Length < 32)
{ {
throw new InvalidOperationException("Auth:SigningKey must be at least 32 characters long."); throw new InvalidOperationException("Auth:SigningKey must be at least 32 characters long.");

View File

@@ -12,15 +12,10 @@
"Issuer": "klapi-api", "Issuer": "klapi-api",
"Audience": "klapi-ui", "Audience": "klapi-ui",
"SigningKey": "change-this-to-a-long-random-32-char-minimum-key", "SigningKey": "change-this-to-a-long-random-32-char-minimum-key",
"AllowedOrigins": [ "AllowedOrigins": ["https://klapi.tietokonepaja.fi"],
"http://localhost:5173",
"http://127.0.0.1:5173",
"http://localhost:4173",
"http://127.0.0.1:4173"
],
"Admin": { "Admin": {
"Username": "admin", "Username": "admin",
"Password": "changeme", "Password": "<set in env var KLAPI_ADMIN_PASSWORD>",
"DisplayName": "Administrator" "DisplayName": "Administrator"
} }
}, },

Binary file not shown.