feat: backup encryption#1400
Closed
caffeinated92 wants to merge 13 commits into
Closed
Conversation
Enable optional AES-256-CBC encryption for single-file backups before restic upload and add a CLI decrypt-backup command for restore workflows. Treat backup-encryption-passphrase as a managed secret and resolve passphrase sources with env/config/admin fallback for safer operations.
Add tar/tar.gz packaging plus streaming OpenSSL encryption/decryption for directory-based logical backups so large artifacts avoid in-memory processing while preserving restore and restic compatibility. Record encryptionTool metadata for forward-compatible decrypt behavior and expose new directory encryption config controls.
Introduce backup-encryption-directory-mode with archive default and per-file option, plus encryptionMode metadata to preserve cross-version compatibility. Extend restore logic to decrypt per-file directories in place and clean up .enc files after successful decrypt.
…nsafe override - Per-file encrypted restore now requires backup-keep-until-valid=true for safe reversible staging - Implements incremental journal persistence for crash-safe rollback (decrypt -> rename to .old -> activate plaintext) - Journal write failures cause fatal abort with in-memory rollback - Stale journal rollback failure aborts restore preparation - Cleanup preserves journal if rollback fails for recovery - Add backup-encryption-unsafe-per-file-restore flag to bypass safety for low-disk environments - Add tests for gated behavior, transactional flow, unsafe path, and journal failure rollback - Update docs with new safety guarantees
…th traversal - Reject empty, absolute, and escaping symlink targets in extractArchiveToDir - Use isPathWithinBase to enforce boundary checking - Fail-fast on first unsafe symlink to prevent write-through attacks - Add comprehensive tests for absolute/escaping/empty/in-tree symlinks - Add deterministic traversal-chain test with shared temp root
Validate symlink and hardlink targets stay within the extraction root, normalize archive link paths for cross-platform tar semantics, and resolve hardlinks safely with a copy fallback. Add regression tests covering traversal protection, hardlink ordering, ambiguity handling, and path normalization policies.
Replaces in-memory buffering with file-to-file streaming to support decrypting large (100+ GB) backups without loading entire file into memory. Pipes *os.File directly to OpenSSL stdin/stdout instead of using bytes.NewReader. Maintains passphrase-first then legacy key/iv fallback behavior with proper temp file cleanup.
…encryption - Track passphrase source (env, config, api-credentials, server DB) - Warn when fallback rotating credentials are used for encryption - Add backup-encryption-require-explicit-passphrase flag to enforce explicit passphrase (env var or config) and reject rotating credentials - Use lazy passphrase resolution in per-file encrypt/decrypt to avoid warnings on no-op directory operations - Remove duplicate warnings from preflight (now only warn on actual use) - Add nil-safety guards to prevent panics when ClusterGroup is absent - Add comprehensive tests for source precedence, strict mode, and lazy resolution behavior
…ion hardening - Add streaming encryption negative-path tests: - TestBackupEncryptionStreamDecryptWrongPasswordFails - TestBackupEncryptionStreamEncryptEmptyPassphraseFails - Add per-file directory encrypt/decrypt round-trip test - Add archive extraction path traversal tests: - TestExtractArchiveToDirRejectsRelativePathTraversalEntryName - TestExtractArchiveToDirRejectsAbsoluteEntryName (table-driven) - Add hardlink source-type edge case tests: - TestExtractArchiveToDirRejectsHardlinkToSymlinkSource - TestExtractArchiveToDirRejectsHardlinkToDirectorySource - Security fix: reject absolute archive entry names before switch (covers TypeDir, TypeReg, TypeSymlink, TypeLink uniformly)
Collaborator
Author
|
Claude encountered an error —— View job PR Review: feat: backup encryption
|
Collaborator
Author
|
I found 3 important issues to address before merge:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
encryptionMode/encryptionToolmetadata for forward-compatible restoresTesting