mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +00:00
fix(server): final-review polish — encryption-gate wording, all-field sentinel guard, README/e2e notes
This commit is contained in:
@@ -68,9 +68,15 @@ PORT, HOST, TRUST_PROXY, SESSION_DURATION(_REMEMBER), MCP_SESSION_TTL,
|
||||
MCP_MAX_SESSION_PER_USER, MCP_SSE_KEEPALIVE, TREK_PLUGIN_RPC_*/LOG_*/MAX_RSS_MB,
|
||||
TREK_PLUGIN_REGISTRY_URL, TREK_WIKI_DIR*, TREK_PLACE_PHOTO_DIR, BACKUP_*,
|
||||
TRANSIT_API_URL, LOG_LEVEL*, ALLOW_INTERNAL_NETWORK*, DEFAULT_LANGUAGE,
|
||||
TREK_DB_FILE, TREK_DB_JOURNAL_MODE, TREK_DB_SYNCHRONOUS, ENCRYPTION_KEY.
|
||||
TREK_DB_FILE, TREK_DB_JOURNAL_MODE, TREK_DB_SYNCHRONOUS, ENCRYPTION_KEY**.
|
||||
(* frozen today because the consuming module captures it at import; tests that
|
||||
override these set them at file top, before the SUT import.)
|
||||
(** ENCRYPTION_KEY is boot-stable only for the cipher key material itself —
|
||||
`src/config.ts` resolves and freezes it at process start, per the exemption
|
||||
below. `security.encryptionKeySet` (the storage admin-config encryption gate)
|
||||
is a *different* read of the same variable: `deriveSecurity()` reads it live
|
||||
via `readEnv()`/`RuntimeEnvService`, so a value set after boot is observed on
|
||||
the next call — it does not retroactively unlock the frozen cipher.)
|
||||
|
||||
**Tombstoned** (boot-aborting since the admin-config slice — configure storage
|
||||
in the admin UI / `data/storage-config.json` instead): `TREK_S3_ENDPOINT`,
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
import { StorageService } from './storage.service';
|
||||
import { SEED_CONFIG_PATH } from './storage-paths';
|
||||
import {
|
||||
assertNoMaskSentinels,
|
||||
decryptBackendSecrets,
|
||||
encryptionGateError,
|
||||
encryptStorageSecrets,
|
||||
@@ -62,6 +63,10 @@ export class StorageAdminService {
|
||||
/** Full-document replace of the two settings rows. Throws StorageBackendError on any refusal. */
|
||||
applyConfig(config: StorageConfig): void {
|
||||
const unmasked = unmaskStorageConfig(config, this.storedBackendsRow());
|
||||
// unmask only resolves the secret fields it knows about; a mask sentinel
|
||||
// submitted in a non-secret field would otherwise pass through untouched
|
||||
// and get persisted verbatim as garbage-in.
|
||||
assertNoMaskSentinels(unmasked);
|
||||
const plaintext = listPlaintextSecrets(unmasked);
|
||||
if (plaintext.length > 0 && !this.env.env().security.encryptionKeySet) {
|
||||
throw new StorageBackendError(encryptionGateError(plaintext[0]!));
|
||||
|
||||
@@ -49,10 +49,19 @@ export function listPlaintextSecrets(config: StorageConfig): PlaintextSecret[] {
|
||||
return found;
|
||||
}
|
||||
|
||||
/** The seed file has no mask round-trip — a literal mask sentinel is always a mistake. */
|
||||
/**
|
||||
* No literal mask sentinel may ever become a stored value, in ANY option
|
||||
* field — not just the fields the type registry marks `secret`. Secret
|
||||
* fields are already covered structurally (`unmaskStorageConfig` throws
|
||||
* when a mask has no stored counterpart); this closes the same hole for a
|
||||
* mask sentinel submitted in a non-secret field, which would otherwise be
|
||||
* persisted verbatim as garbage-in. Also the seed-file guard: the seed file
|
||||
* has no mask round-trip, so a literal mask sentinel there is always a
|
||||
* mistake.
|
||||
*/
|
||||
export function assertNoMaskSentinels(config: StorageConfig): void {
|
||||
for (const backend of config.backends) {
|
||||
for (const field of storageSecretFields(backend.type)) {
|
||||
for (const field of Object.keys(backend.options as Record<string, unknown>)) {
|
||||
if ((backend.options as Record<string, unknown>)[field] === MASKED_SETTING_VALUE) {
|
||||
throw new StorageBackendError(
|
||||
`backend '${backend.name}' field '${field}' is the mask sentinel — a mask can never become a stored value`,
|
||||
@@ -62,11 +71,11 @@ export function assertNoMaskSentinels(config: StorageConfig): void {
|
||||
}
|
||||
}
|
||||
|
||||
/** Fail-closed refusal text: the silent JWT-derived fallback key is not accepted for credentials. */
|
||||
/** Fail-closed refusal text: the implicit key persisted in the data directory is not accepted for credentials — it rides inside backups. */
|
||||
export function encryptionGateError(secret: PlaintextSecret): string {
|
||||
return (
|
||||
`backend '${secret.backend}' has a plaintext secret '${secret.field}' but ENCRYPTION_KEY is not set — ` +
|
||||
'set ENCRYPTION_KEY explicitly to save credentialed storage backends (the JWT-derived fallback key is not accepted)'
|
||||
'set ENCRYPTION_KEY explicitly to save credentialed storage backends (the implicit key persisted in the data directory is not accepted: it rides inside backups)'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user