fix(manage-server): encrypt pre-upgrade pg_dump backup on all platforms (#1119) #30
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
primatekuntech/triton-install!30
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/1119-windows-backup-encryption"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes triton#1119, plus a second gap found while scoping it.
1. Sync gap (bash side, not previously tracked)
triton repo's PR #1117 (issue #1114) added
scripts/backup-encrypt.shand wired
BACKUP_ENCRYPTION_KEYintoscripts/deploy/manage-server/{install.sh,upgrade.sh,env.template}onmain, but per that repo's CLAUDE.md "copy to triton-install and pushboth repos" rule, this was never actually copied here. Confirmed
by diff: this repo's
manage-server/install.sh/upgrade.shhad zeromention of
BACKUP_ENCRYPTION_KEY, andbackup-encrypt.shdidn'texist here at all. Real customers installing via
curl | bashtodaygot fully unencrypted pre-upgrade backups despite #1114 supposedly
fixing this weeks ago.
Fixed:
manage-server/backup-encrypt.shcopied verbatim from the tritonrepo (now byte-identical, confirmed via diff).
manage-server/install.sh/upgrade.sh: applied the same smalldiff main has (key generation + retrofit + encryption wiring +
.sql.gz.encextension + decrypt hint).SCRIPT_VERSIONbumped inboth.
manage-server/env.template: fully synced to main's copy (alsopicks up the previously-unsynced #1105 SIEM-forwarding block and
TRITON_LOG_DEBUG— both inert template text, safe to bring toparity while already touching this file).
get.sh'sINSTALLER_FILESarray + all 4chmod +xcall sites nowinclude
backup-encrypt.sh(now byte-identical to main'sget.sh).2. #1119 itself (Windows, no source-of-truth to copy from)
manage-server/upgrade.ps1had the same unencrypted-backup gap andworse — no gzip at all, a raw plaintext
.sqlfile. This side has nobash counterpart to copy (documented CLAUDE.md asymmetry), so it's a
from-scratch, Windows-native implementation:
manage-server/backup-encrypt.ps1(dot-sourced byupgrade.ps1,not a separate executable): AES-256-CBC with a PBKDF2-stretched key
(10000 iterations, SHA-256), encrypt-then-MAC (HMAC-SHA256) for
explicit wrong-key/corruption detection — no external
openssldependency, since a fresh Windows Server host may not have Git Bash
installed. Own self-consistent format ([salt][iv][ciphertext][hmac]),
not wire-compatible with
backup-encrypt.sh's openssl output sincenothing cross-decrypts it.
upgrade.ps1: gzips (GZipStream) then encrypts the dump beforewriting
manage-pre-upgrade-*.sql.gz.enc; self-healsBACKUP_ENCRYPTION_KEYinto.envfor pre-existing installs(mirrors
backup-encrypt.sh's own retrofit inupgrade.sh); printsa decrypt-hint one-liner.
install.ps1: generatesBACKUP_ENCRYPTION_KEYfor new installs,alongside the existing
pgPass/workerKey/vaultKey.get.ps1's$INSTALLER_FILESnow includesbackup-encrypt.ps1.Testing
backup-encrypt.sh: verified against the triton repo's existinghand-rolled test harness (12/12 assertions pass) — not committed
here, since that repo remains its source of truth.
backup-encrypt.ps1: newmanage-server/backup-encrypt_test.ps1,committed permanently in this repo, since this Windows-only code
has no other home to hold a test for it (unlike the bash side). 11
assertions: round-trip, wrong-key, tampered-ciphertext,
truncated-ciphertext, bad-key-format (too short / non-hex), and the
empty-plaintext edge case.
check in
backup-encrypt.ps1correctly failed only thetampered-ciphertext assertion (not the others), confirming real
coverage; restored after.
gzip → encrypt → decrypt → gunzipround-trip end-to-end with a throwaway harness, matching the exact
recipe
upgrade.ps1prints as its decrypt hint.bash -n/ PowerShell AST parse /shellcheck/PSScriptAnalyzerwith zero new findings — everyexisting warning in the touched files predates this change.
inline in
backup-encrypt.ps1): aMandatoryarray parameterrejects an empty array as if unbound unless marked
[AllowEmptyCollection()], and a function returning a zero-lengtharray gets silently unwrapped to
$nullby PowerShell's outputstream unless prefixed with the unary comma operator.
This repo has no CI, so all verification above was done locally via
pwsh(PowerShell 7.6.3, cross-platform) andbash.🤖 Generated with Claude Code