All checks were successful
CI / Lint, typecheck, test (pull_request) Successful in 4m52s
CI / Build container images (pull_request) Successful in 3m54s
CI / Auth e2e pack (pull_request) Successful in 8m4s
CI / Import/export fidelity gate (pull_request) Successful in 56s
CD / Build and push images (push) Successful in 19s
CD / Deploy to Test (push) Successful in 13s
CD / Smoke tests against Test (push) Successful in 1m14s
CD / Promote to Int (push) Successful in 11s
CI / Lint, typecheck, test (push) Successful in 5m0s
CI / Build container images (push) Has been skipped
CI / Auth e2e pack (push) Successful in 7m41s
CI / Import/export fidelity gate (push) Successful in 56s
BACKUP_ALLOWED_TARGETS (comma-separated destination hosts) constrains where backups may go, enforced twice: the api rejects settings writes and connection tests towards non-allowlisted hosts with admin-visible error codes and resolves a non-allowlisted configured target to null, and the sidecar enforces the same policy at the point of egress for the WebDAV upload and the rsync mirror alike (shared policy helpers in packages/shared/src/backup-target-policy.ts). BREAKING: the empty default disables every remote target - backups stay local only, the VS-NfD reference configuration (ADR 0026). Existing deployments with a remote target must list its host or uploads and mirror stop. The admin UI distinguishes unavailable-by-policy from unconfigured (i18n de+en) and shows the permitted hosts. Refs #192 (ADR 0026) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0168Ph5uBmHm8X28CSVpbpnJ
48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
/**
|
|
* Deploy-level backup target policy (issue #192, ADR 0026). A backup
|
|
* destination is an egress path for the full content of the instance, so
|
|
* the set of permissible destination HOSTS is fixed at deploy time via
|
|
* `BACKUP_ALLOWED_TARGETS` — a runtime setting could be widened by a
|
|
* compromised Site-Admin account. An empty allowlist disables every
|
|
* remote target (WebDAV and rsync mirror); "local only" is the VS-NfD
|
|
* reference configuration. Both the api (settings writes, admin view) and
|
|
* the backup sidecar (the actual egress) enforce the same policy through
|
|
* these helpers.
|
|
*/
|
|
|
|
/** Comma-separated env value → normalized, deduplicated host list. */
|
|
export function parseBackupTargetAllowlist(raw: string): string[] {
|
|
return [
|
|
...new Set(
|
|
raw
|
|
.split(',')
|
|
.map((entry) => entry.trim().toLowerCase())
|
|
.filter(Boolean),
|
|
),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* The destination host of a backup target: the hostname of a WebDAV URL,
|
|
* or the host part of an rsync-over-ssh target (`user@host:/path`).
|
|
* `null` for anything unparsable — which is never allowed.
|
|
*/
|
|
export function backupTargetHost(target: string): string | null {
|
|
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(target)) {
|
|
try {
|
|
const hostname = new URL(target).hostname;
|
|
return hostname ? hostname.toLowerCase() : null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
const rsync = /^(?:[^@\s]+@)?([^/:@\s]+):/.exec(target);
|
|
return rsync ? rsync[1]!.toLowerCase() : null;
|
|
}
|
|
|
|
/** Whether `target` points at an allowlisted host. Empty list ⇒ never. */
|
|
export function isBackupTargetAllowed(allowlist: string[], target: string): boolean {
|
|
const host = backupTargetHost(target);
|
|
return host !== null && allowlist.includes(host);
|
|
}
|