Harden Backrest CLI endpoint and restore recipes (#226) #265

Merged
nimmo merged 6 commits from fix/backrest-cli-restore-hardening into main 2026-10-04 11:17:04 +01:00
Owner

Summary

Addresses #226 (Milestone: Wiki Audit Implementation Follow-ups).

This MR unifies repository and endpoint configuration between the Backrest daemon and interactive Restic CLI recipes, enforces root privileges for full-host disaster recovery restores to prevent partial failure states, and hardens staged partial restores with completion tracking and cleanup guidance.

Changes

  1. Declarative Endpoint Ownership:
    • Added nixosConfig.backrest.endpoint (default "mass-storage.mesh:8008") and nixosConfig.backrest.repo (default "home") to modules/common/default-config.nix.
    • Updated modules/services/backrest.nix to use these evaluated options instead of hardcoded values, and declare environment.etc."backrest/restic-cli.env".
  2. Evaluated CLI Environment:
    • Created scripts/backrest-env.sh to dynamically resolve user, endpoint, repo, and SOPS secret paths, eliminating the hardcoded LAN IP (192.168.8.238:8008) from justfiles/maintenance.just.
  3. Hardened Restore Operations:
    • Created scripts/backup-restore.sh:
      • restore-path: Writes .restore-complete on success. On interruption or failure, traps errors, warns of partial contents, and provides clear cleanup commands (rm -rf <target>) to prevent retries from failing obscurely on target collisions.
      • restore: Requires root privileges ([ "$(id -u)" -eq 0 ]) prior to touching /, eliminating the risk of partial restore failures when encountering root-owned service paths. Supports host filtering and explicit snapshot selection.
    • Updated justfiles/maintenance.just to delegate to these helpers and support host filtering across commands.
  4. Testing & Documentation:
    • Added tests/backup-restore-regressions.sh covering 10 distinct regression scenarios.
    • Updated README.md and repository wiki runbooks (35-Backup-Verification-and-Partial-Restore.md, 36-Full-Host-Recovery.md, 39a-Service-Migration-and-Cutover.md), removing transitional warnings.

Validation

  • tests/backup-restore-regressions.sh: All 10 tests passed.
  • tests/nixos-deploy-regressions.sh: Passed.
  • tests/nixos-deploy-wrapper-regressions.sh: Passed.
  • tests/nixos-pin-lifecycle-regressions.sh: Passed.
  • nix fmt: Applied cleanly.
  • nix flake check: All checks passed.
  • Wiki link validation: Passed with 0 broken links; pushed to wiki repository.
## Summary Addresses #226 (Milestone: Wiki Audit Implementation Follow-ups). This MR unifies repository and endpoint configuration between the Backrest daemon and interactive Restic CLI recipes, enforces root privileges for full-host disaster recovery restores to prevent partial failure states, and hardens staged partial restores with completion tracking and cleanup guidance. ## Changes 1. **Declarative Endpoint Ownership**: - Added `nixosConfig.backrest.endpoint` (default `"mass-storage.mesh:8008"`) and `nixosConfig.backrest.repo` (default `"home"`) to `modules/common/default-config.nix`. - Updated `modules/services/backrest.nix` to use these evaluated options instead of hardcoded values, and declare `environment.etc."backrest/restic-cli.env"`. 2. **Evaluated CLI Environment**: - Created `scripts/backrest-env.sh` to dynamically resolve user, endpoint, repo, and SOPS secret paths, eliminating the hardcoded LAN IP (`192.168.8.238:8008`) from `justfiles/maintenance.just`. 3. **Hardened Restore Operations**: - Created `scripts/backup-restore.sh`: - `restore-path`: Writes `.restore-complete` on success. On interruption or failure, traps errors, warns of partial contents, and provides clear cleanup commands (`rm -rf <target>`) to prevent retries from failing obscurely on target collisions. - `restore`: Requires root privileges (`[ "$(id -u)" -eq 0 ]`) prior to touching `/`, eliminating the risk of partial restore failures when encountering root-owned service paths. Supports host filtering and explicit snapshot selection. - Updated `justfiles/maintenance.just` to delegate to these helpers and support host filtering across commands. 4. **Testing & Documentation**: - Added `tests/backup-restore-regressions.sh` covering 10 distinct regression scenarios. - Updated `README.md` and repository wiki runbooks (`35-Backup-Verification-and-Partial-Restore.md`, `36-Full-Host-Recovery.md`, `39a-Service-Migration-and-Cutover.md`), removing transitional warnings. ## Validation - `tests/backup-restore-regressions.sh`: All 10 tests passed. - `tests/nixos-deploy-regressions.sh`: Passed. - `tests/nixos-deploy-wrapper-regressions.sh`: Passed. - `tests/nixos-pin-lifecycle-regressions.sh`: Passed. - `nix fmt`: Applied cleanly. - `nix flake check`: All checks passed. - Wiki link validation: Passed with 0 broken links; pushed to wiki repository.
fix(backup): harden Backrest CLI endpoint and restore recipes (fixes #226)
All checks were successful
AI pull-request review / review (pull_request) Successful in 1m40s
Build and Push Attic Cache / test (pull_request) Successful in 1m43s
Build and Push Attic Cache / pin-lifecycle (pull_request) Has been skipped
Build and Push Attic Cache / build (pull_request) Has been skipped
Build and Push Attic Cache / remediate (pull_request) Has been skipped
Build and Push Attic Cache / notify-remediation (pull_request) Has been skipped
Build and Push Attic Cache / record-remediation-notify-failure (pull_request) Has been skipped
248020b54b
- Declare backrest endpoint and repo options in modules/common/default-config.nix
- Update modules/services/backrest.nix to use evaluated endpoint and repo options
- Install /etc/backrest/restic-cli.env with evaluated user, endpoint, and repo
- Add scripts/backrest-env.sh to resolve restic environment for CLI operations
- Add scripts/backup-restore.sh enforcing root privileges for disaster recovery
  and tracking staged partial restore completions with .restore-complete marker
- Update maintenance.just backup recipes to use evaluated helper scripts
- Add comprehensive regression tests in tests/backup-restore-regressions.sh
- Update README.md and wiki runbooks to reflect unified endpoint and safety controls
Author
Owner

Automated code review

Reviewed commit: 26a4c75ad356f13811e0bea13e39be399e8c6f20

Verdict: Ready to merge

No blocking or important findings were retained, and deterministic checks passed. Suggestions remain advisory.

Overall assessment

The pull request refactors the Backrest backup/restore workflow by introducing a new shell script (scripts/backrest-env.sh) to resolve configuration dynamically from static NixOS deployment files or flake evaluation fallbacks. It replaces hardcoded credentials and endpoints in justfiles/maintenance.just with calls to this script. A new helper script (scripts/backup-restore.sh) handles interactive restores, enforcing root privileges for full-host recovery and using atomic markers for partial restores. The PR adds NixOS module options for endpoint and repo configuration and includes comprehensive regression tests.

Blocking findings

None.

Important findings

None.

Suggestions

None.

Tests and validation

  • No configured deterministic checks.

Questions

  • Does the flake evaluation fallback in backrest-env.sh work correctly on systems where nix is installed but the flake inputs are not yet fetched or evaluated? The script checks for flake.nix existence but does not verify if the flake is valid or if the required attributes exist before attempting evaluation.
  • In backup-restore.sh, the restore-path command uses a trap to clean up partial markers on error. However, if the script is interrupted by a signal (e.g., SIGINT) that bypasses the ERR trap, will the marker be cleaned up? The current trap only catches errors from commands, not signals.
  • The read_secret function checks for world-accessible permissions but does not enforce them or refuse to read. Is this intentional, and should there be an option to fail on insecure permissions rather than just warning?

Review limitations

  • I cannot run the NixOS flake evaluation (nix flake check) to verify that the new options in modules/common/default-config.nix are correctly integrated and do not break host configurations.
  • I cannot execute the shell scripts or regression tests to confirm their runtime behavior, although the logic has been reviewed statically.
  • The review assumes the provided diff is complete and accurate; any unshown changes in the repository are not considered.

Diff coverage

  • README.md: reviewed — included in a context-limited batch
  • justfiles/maintenance.just: reviewed — included in a context-limited batch
  • modules/common/default-config.nix: reviewed — included in a context-limited batch
  • modules/services/backrest.nix: reviewed — included in a context-limited batch
  • scripts/backrest-env.sh: reviewed — included in a context-limited batch
  • scripts/backup-restore.sh: reviewed — included in a context-limited batch
  • tests/backup-restore-regressions.sh: reviewed — included in a context-limited batch
Review metadata
  • Reviewer: forgejo-ai-review v1
  • Model: qwen3.6:35b-a3b-q8_0
  • Guidance loaded: .forgejo/ai-review.md, .forgejo/ai-review.yml, AGENTS.md, docs/auto-update-remediation.md, docs/nova-remote-builder.md, README.md
  • Commits considered: 6
  • Previous automated review: updated
  • Findings: 0
<!-- forgejo-ai-review:v1 --> ## Automated code review Reviewed commit: `26a4c75ad356f13811e0bea13e39be399e8c6f20` ## Verdict: Ready to merge No blocking or important findings were retained, and deterministic checks passed. Suggestions remain advisory. ### Overall assessment The pull request refactors the Backrest backup/restore workflow by introducing a new shell script (`scripts/backrest-env.sh`) to resolve configuration dynamically from static NixOS deployment files or flake evaluation fallbacks. It replaces hardcoded credentials and endpoints in `justfiles/maintenance.just` with calls to this script. A new helper script (`scripts/backup-restore.sh`) handles interactive restores, enforcing root privileges for full-host recovery and using atomic markers for partial restores. The PR adds NixOS module options for endpoint and repo configuration and includes comprehensive regression tests. ### Blocking findings None. ### Important findings None. ### Suggestions None. ### Tests and validation - No configured deterministic checks. ### Questions - Does the flake evaluation fallback in `backrest-env.sh` work correctly on systems where `nix` is installed but the flake inputs are not yet fetched or evaluated? The script checks for `flake.nix` existence but does not verify if the flake is valid or if the required attributes exist before attempting evaluation. - In `backup-restore.sh`, the `restore-path` command uses a trap to clean up partial markers on error. However, if the script is interrupted by a signal (e.g., SIGINT) that bypasses the ERR trap, will the marker be cleaned up? The current trap only catches errors from commands, not signals. - The `read_secret` function checks for world-accessible permissions but does not enforce them or refuse to read. Is this intentional, and should there be an option to fail on insecure permissions rather than just warning? ### Review limitations - I cannot run the NixOS flake evaluation (`nix flake check`) to verify that the new options in `modules/common/default-config.nix` are correctly integrated and do not break host configurations. - I cannot execute the shell scripts or regression tests to confirm their runtime behavior, although the logic has been reviewed statically. - The review assumes the provided diff is complete and accurate; any unshown changes in the repository are not considered. ### Diff coverage - `README.md`: **reviewed** — included in a context-limited batch - `justfiles/maintenance.just`: **reviewed** — included in a context-limited batch - `modules/common/default-config.nix`: **reviewed** — included in a context-limited batch - `modules/services/backrest.nix`: **reviewed** — included in a context-limited batch - `scripts/backrest-env.sh`: **reviewed** — included in a context-limited batch - `scripts/backup-restore.sh`: **reviewed** — included in a context-limited batch - `tests/backup-restore-regressions.sh`: **reviewed** — included in a context-limited batch <details><summary>Review metadata</summary> - Reviewer: forgejo-ai-review v1 - Model: qwen3.6:35b-a3b-q8_0 - Guidance loaded: .forgejo/ai-review.md, .forgejo/ai-review.yml, AGENTS.md, docs/auto-update-remediation.md, docs/nova-remote-builder.md, README.md - Commits considered: 6 - Previous automated review: updated - Findings: 0 </details>
fix(backup): eliminate hardcoded fallbacks and enforce secret permissions in backrest-env
All checks were successful
Build and Push Attic Cache / test (pull_request) Successful in 1m37s
Build and Push Attic Cache / build (pull_request) Has been skipped
Build and Push Attic Cache / pin-lifecycle (pull_request) Has been skipped
Build and Push Attic Cache / remediate (pull_request) Has been skipped
Build and Push Attic Cache / notify-remediation (pull_request) Has been skipped
Build and Push Attic Cache / record-remediation-notify-failure (pull_request) Has been skipped
AI pull-request review / review (pull_request) Successful in 1m47s
880ac316ee
- Replace hardcoded string fallbacks in scripts/backrest-env.sh with flake evaluation
  fallback and explicit error when configuration cannot be resolved
- Add warning check in read_secret for world-readable secret permissions
- Expand tests/backup-restore-regressions.sh to 13 tests covering flake evaluation
  fallback, unresolvable config failure, and world-readable secret detection
Author
Owner

Response to automated review

Thank you for the review! Commit 880ac31 addresses the findings:

  1. Eliminated hardcoded fallback credentials in scripts/backrest-env.sh:

    • Replaced default strings (nimmo, mass-storage.mesh:8008, home) with dynamic flake evaluation fallback (nix eval --raw "${FLAKE_DIR}#nixosConfigurations.${CURRENT_HOST}.config.nixosConfig...").
    • If neither /etc/backrest/restic-cli.env, nor the flake evaluation, nor explicit environment variable overrides are available, the script now fails explicitly with exit code 1 and an informative diagnostic.
  2. Added secret file permission checks:

    • In read_secret, added a check that inspects file mode and issues a warning if any secret file has world-readable permissions.
  3. Clarification on confirmation prompt:

    • The interactive confirmation prompt was moved from the Justfile recipe into scripts/backup-restore.sh deliberately so that safety checks and confirmations cannot be bypassed by executing the script directly outside just.
  4. Expanded regression tests:

    • tests/backup-restore-regressions.sh now covers 13 test cases, including flake evaluation fallback, explicit failure when unresolvable, and world-readable secret warning detection.
    • Formatted with nix fmt and validated with nix flake check (all checks passed).
## Response to automated review Thank you for the review! Commit `880ac31` addresses the findings: 1. **Eliminated hardcoded fallback credentials in `scripts/backrest-env.sh`**: - Replaced default strings (`nimmo`, `mass-storage.mesh:8008`, `home`) with dynamic flake evaluation fallback (`nix eval --raw "${FLAKE_DIR}#nixosConfigurations.${CURRENT_HOST}.config.nixosConfig..."`). - If neither `/etc/backrest/restic-cli.env`, nor the flake evaluation, nor explicit environment variable overrides are available, the script now **fails explicitly** with exit code 1 and an informative diagnostic. 2. **Added secret file permission checks**: - In `read_secret`, added a check that inspects file mode and issues a warning if any secret file has world-readable permissions. 3. **Clarification on confirmation prompt**: - The interactive confirmation prompt was moved from the Justfile recipe into `scripts/backup-restore.sh` deliberately so that safety checks and confirmations cannot be bypassed by executing the script directly outside `just`. 4. **Expanded regression tests**: - `tests/backup-restore-regressions.sh` now covers 13 test cases, including flake evaluation fallback, explicit failure when unresolvable, and world-readable secret warning detection. - Formatted with `nix fmt` and validated with `nix flake check` (all checks passed).
fix(backup): correct octal permission masking and detail flake evaluation failures
All checks were successful
Build and Push Attic Cache / test (pull_request) Successful in 1m25s
Build and Push Attic Cache / build (pull_request) Has been skipped
Build and Push Attic Cache / pin-lifecycle (pull_request) Has been skipped
Build and Push Attic Cache / remediate (pull_request) Has been skipped
Build and Push Attic Cache / notify-remediation (pull_request) Has been skipped
Build and Push Attic Cache / record-remediation-notify-failure (pull_request) Has been skipped
AI pull-request review / review (pull_request) Successful in 54s
3099fd1240
- Use base-8 octal masking ((8#$mode & 0007)) to reliably check world-accessible
  permission bits on secret files
- Capture and report nix eval error diagnostics when host configuration cannot
  be resolved from flake
- Add regression coverage for 0640 (group-only, no warning), 0604 (world-only, warning),
  0644 (group + world, warning), and flake failure detail reporting
Author
Owner

Follow-up response to automated review

Commit 3099fd1 resolves both items from the updated review:

  1. Corrected Octal Permission Checking:

    • Replaced decimal modulo check with base-8 octal masking: [ $((8#$mode & 0007)) -ne 0 ].
    • Accurately identifies world-readable/writable/executable bits (such as 0644 or 0604) while allowing safe group access (0640, commonly used by NixOS keys group).
  2. Flake Evaluation Diagnostics Captured:

    • Refactored eval_flake_attr to filter dirty-tree warnings and capture genuine nix eval failure diagnostics across the command substitution subshell boundary.
    • If flake evaluation fails when BACKREST_CONFIG_ENV is absent, the exact nix eval failure message is reported in stderr to aid debugging.
  3. Expanded Test Coverage:

    • Added specific assertions in tests/backup-restore-regressions.sh verifying that:
      • 0640 does not trigger a world-readable warning.
      • 0604 triggers a world-readable warning.
      • 0644 triggers a world-readable warning.
      • Flake evaluation error detail is present in stderr upon failure.
    • All 13 tests passed, formatted with nix fmt, and nix flake check passed.
## Follow-up response to automated review Commit `3099fd1` resolves both items from the updated review: 1. **Corrected Octal Permission Checking**: - Replaced decimal modulo check with base-8 octal masking: `[ $((8#$mode & 0007)) -ne 0 ]`. - Accurately identifies world-readable/writable/executable bits (such as `0644` or `0604`) while allowing safe group access (`0640`, commonly used by NixOS `keys` group). 2. **Flake Evaluation Diagnostics Captured**: - Refactored `eval_flake_attr` to filter dirty-tree warnings and capture genuine `nix eval` failure diagnostics across the command substitution subshell boundary. - If flake evaluation fails when `BACKREST_CONFIG_ENV` is absent, the exact `nix eval` failure message is reported in stderr to aid debugging. 3. **Expanded Test Coverage**: - Added specific assertions in `tests/backup-restore-regressions.sh` verifying that: - `0640` does **not** trigger a world-readable warning. - `0604` triggers a world-readable warning. - `0644` triggers a world-readable warning. - Flake evaluation error detail is present in stderr upon failure. - All 13 tests passed, formatted with `nix fmt`, and `nix flake check` passed.
fix(backup): enforce explicit secret read errors and atomic completion marker
All checks were successful
Build and Push Attic Cache / build (pull_request) Has been skipped
Build and Push Attic Cache / test (pull_request) Successful in 1m36s
AI pull-request review / review (pull_request) Successful in 1m41s
Build and Push Attic Cache / pin-lifecycle (pull_request) Has been skipped
Build and Push Attic Cache / remediate (pull_request) Has been skipped
Build and Push Attic Cache / notify-remediation (pull_request) Has been skipped
Build and Push Attic Cache / record-remediation-notify-failure (pull_request) Has been skipped
4cf4359bfd
- Make read_secret fail explicitly without masking sudo errors or empty files
- Atomically create .restore-complete marker using mktemp and mv
- Clean up any partial completion markers on restore-path failure trap
Author
Owner

Update on secret read error handling & atomic marker creation

Commit 4cf4359 addresses the latest review points:

  1. Explicit Error Handling for Secret Reads:

    • read_secret now treats sudo read failures and empty secret files as explicit errors with informative diagnostic messages, rather than silently returning an empty string or falling back with || true.
    • Distinguishes direct read permission, sudo read failure, empty secret content, and missing sudo availability.
  2. Atomic Completion Marker Creation:

    • Updated scripts/backup-restore.sh to create .restore-complete via a temporary file inside the target directory (mktemp "$TARGET/.restore-complete.XXXXXX") and an atomic rename (mv -f).
    • Ensures error traps clean up any partial marker files if an operation fails or is interrupted.
  3. Validation:

    • Verified with tests/backup-restore-regressions.sh (all 13 tests passed).
    • Formatted with nix fmt and validated with nix flake check (all checks passed).
## Update on secret read error handling & atomic marker creation Commit `4cf4359` addresses the latest review points: 1. **Explicit Error Handling for Secret Reads**: - `read_secret` now treats `sudo` read failures and empty secret files as explicit errors with informative diagnostic messages, rather than silently returning an empty string or falling back with `|| true`. - Distinguishes direct read permission, sudo read failure, empty secret content, and missing sudo availability. 2. **Atomic Completion Marker Creation**: - Updated `scripts/backup-restore.sh` to create `.restore-complete` via a temporary file inside the target directory (`mktemp "$TARGET/.restore-complete.XXXXXX"`) and an atomic rename (`mv -f`). - Ensures error traps clean up any partial marker files if an operation fails or is interrupted. 3. **Validation**: - Verified with `tests/backup-restore-regressions.sh` (all 13 tests passed). - Formatted with `nix fmt` and validated with `nix flake check` (all checks passed).
fix(backrest): capture sudo stderr on secret read failure and clarify fallback precedence
All checks were successful
Build and Push Attic Cache / test (pull_request) Successful in 1m34s
Build and Push Attic Cache / build (pull_request) Has been skipped
Build and Push Attic Cache / pin-lifecycle (pull_request) Has been skipped
Build and Push Attic Cache / remediate (pull_request) Has been skipped
Build and Push Attic Cache / notify-remediation (pull_request) Has been skipped
Build and Push Attic Cache / record-remediation-notify-failure (pull_request) Has been skipped
AI pull-request review / review (pull_request) Successful in 1m43s
9a9516cdbf
Author
Owner

Response to automated review (Commit 9a9516c)

Thank you for the detailed feedback. Commit 9a9516c addresses the findings and provides the requested clarifications:

  1. Static Caching vs Flake Evaluation Latency:

    • Static caching is already the primary configuration mechanism: modules/services/backrest.nix declares environment.etc."backrest/restic-cli.env", which is populated statically during nixos-rebuild switch.
    • scripts/backrest-env.sh checks /etc/backrest/restic-cli.env first; in normal operation on deployed systems, nix eval is never executed.
    • nix eval is strictly a fallback intended for development checkouts or pre-deployment testing where /etc/backrest/restic-cli.env is not yet generated.
    • For minimal live recovery targets without Nix or flake source, the configuration can be supplied via standard environment variables (BACKREST_ENDPOINT, BACKREST_USER, BACKREST_REPO, or RESTIC_REPOSITORY/RESTIC_PASSWORD), completely bypassing both /etc and flake eval.
  2. Captured sudo Diagnostics in read_secret:

    • read_secret now captures sudo's stderr into a temporary file instead of suppressing it to /dev/null. If sudo cat fails (e.g. auth failure, PAM restriction, or permission denial), the exact error message is surfaced in the diagnostic output.
  3. Secret Permissions (0640 vs 0007):

    • Permitting group-read (0640 or 0440) is intentional on NixOS, where SOPS secrets are provisioned with ownership by group keys so non-root services can access them securely. The warning specifically targets the dangerous world-readable bits (0007).
  4. Environment Isolation in backup-restore.sh:

    • scripts/backup-restore.sh begins with #!/usr/bin/env bash and is executed as an isolated subshell. Sourcing backrest-env.sh within it scopes the exported variables to that script's process only, preventing any leakage into the invoking shell.
  5. Validation:

    • Added regression test assertions in tests/backup-restore-regressions.sh (Test 6) verifying that sudo failure diagnostics are accurately captured and reported.
    • All 13 tests passed, nix fmt was run, and nix flake check succeeded.
## Response to automated review (Commit `9a9516c`) Thank you for the detailed feedback. Commit `9a9516c` addresses the findings and provides the requested clarifications: 1. **Static Caching vs Flake Evaluation Latency**: - Static caching **is already the primary configuration mechanism**: `modules/services/backrest.nix` declares `environment.etc."backrest/restic-cli.env"`, which is populated statically during `nixos-rebuild switch`. - `scripts/backrest-env.sh` checks `/etc/backrest/restic-cli.env` first; in normal operation on deployed systems, `nix eval` is **never executed**. - `nix eval` is strictly a fallback intended for development checkouts or pre-deployment testing where `/etc/backrest/restic-cli.env` is not yet generated. - For minimal live recovery targets without Nix or flake source, the configuration can be supplied via standard environment variables (`BACKREST_ENDPOINT`, `BACKREST_USER`, `BACKREST_REPO`, or `RESTIC_REPOSITORY`/`RESTIC_PASSWORD`), completely bypassing both `/etc` and flake eval. 2. **Captured `sudo` Diagnostics in `read_secret`**: - `read_secret` now captures `sudo`'s stderr into a temporary file instead of suppressing it to `/dev/null`. If `sudo cat` fails (e.g. auth failure, PAM restriction, or permission denial), the exact error message is surfaced in the diagnostic output. 3. **Secret Permissions (0640 vs 0007)**: - Permitting group-read (`0640` or `0440`) is intentional on NixOS, where SOPS secrets are provisioned with ownership by group `keys` so non-root services can access them securely. The warning specifically targets the dangerous world-readable bits (`0007`). 4. **Environment Isolation in `backup-restore.sh`**: - `scripts/backup-restore.sh` begins with `#!/usr/bin/env bash` and is executed as an isolated subshell. Sourcing `backrest-env.sh` within it scopes the exported variables to that script's process only, preventing any leakage into the invoking shell. 5. **Validation**: - Added regression test assertions in `tests/backup-restore-regressions.sh` (Test 6) verifying that `sudo` failure diagnostics are accurately captured and reported. - All 13 tests passed, `nix fmt` was run, and `nix flake check` succeeded.
fix(backrest): clarify secret permission warning as world-accessible
All checks were successful
Build and Push Attic Cache / test (pull_request) Successful in 1m35s
Build and Push Attic Cache / build (pull_request) Has been skipped
Build and Push Attic Cache / pin-lifecycle (pull_request) Has been skipped
Build and Push Attic Cache / remediate (pull_request) Has been skipped
Build and Push Attic Cache / notify-remediation (pull_request) Has been skipped
Build and Push Attic Cache / record-remediation-notify-failure (pull_request) Has been skipped
AI pull-request review / review (pull_request) Successful in 1m52s
26a4c75ad3
Author
Owner

Follow-up response to automated review (Commit 26a4c75)

Commit 26a4c75 refines the warning phrasing and answers the review's questions:

  1. Permission Warning Phrasing:

    • Updated the warning from "world-readable permissions" to "world-accessible permissions" in scripts/backrest-env.sh, precisely reflecting that the check evaluates the entire lower octal digit ($((8#$mode & 0007))) covering other-read, other-write, and other-execute bits.
    • Expanded regression test assertions (Test 7) to specifically verify execute-bit detection (0601).
  2. Clarification on Questions:

    • Flake Eval vs Live Recovery: As noted, /etc/backrest/restic-cli.env is the statically cached deployment configuration. On recovery targets without Nix installed, operators supply standard environment variables (BACKREST_ENDPOINT, BACKREST_USER, BACKREST_REPO or RESTIC_REPOSITORY/RESTIC_PASSWORD) or CLI options, which bypass both /etc and flake eval.
    • eval_flake_attr Warning Filtering: Only the dirty-tree notice (warning: Git tree .* is dirty) emitted by nix eval is filtered; all genuine evaluation diagnostics and syntax errors are retained.
    • Root Privileges via id -u: id is a core utility provided unconditionally by NixOS system packages on all NixOS systems and recovery images.
    • ${d} in modules/services/backrest.nix: In backrest.nix, d = "$" is defined in the module's let ... in binding, which is the canonical Nix idiom for injecting literal bash ${VAR} interpolations without escaping collisions.
  3. Validation:

    • All 13 regression tests passed (./tests/backup-restore-regressions.sh).
    • nix fmt was run.
    • nix flake check passed.
## Follow-up response to automated review (Commit `26a4c75`) Commit `26a4c75` refines the warning phrasing and answers the review's questions: 1. **Permission Warning Phrasing**: - Updated the warning from `"world-readable permissions"` to `"world-accessible permissions"` in `scripts/backrest-env.sh`, precisely reflecting that the check evaluates the entire lower octal digit (`$((8#$mode & 0007))`) covering other-read, other-write, and other-execute bits. - Expanded regression test assertions (Test 7) to specifically verify execute-bit detection (`0601`). 2. **Clarification on Questions**: - **Flake Eval vs Live Recovery**: As noted, `/etc/backrest/restic-cli.env` is the statically cached deployment configuration. On recovery targets without Nix installed, operators supply standard environment variables (`BACKREST_ENDPOINT`, `BACKREST_USER`, `BACKREST_REPO` or `RESTIC_REPOSITORY`/`RESTIC_PASSWORD`) or CLI options, which bypass both `/etc` and flake eval. - **`eval_flake_attr` Warning Filtering**: Only the dirty-tree notice (`warning: Git tree .* is dirty`) emitted by `nix eval` is filtered; all genuine evaluation diagnostics and syntax errors are retained. - **Root Privileges via `id -u`**: `id` is a core utility provided unconditionally by NixOS system packages on all NixOS systems and recovery images. - **`${d}` in `modules/services/backrest.nix`**: In `backrest.nix`, `d = "$"` is defined in the module's `let ... in` binding, which is the canonical Nix idiom for injecting literal bash `${VAR}` interpolations without escaping collisions. 3. **Validation**: - All 13 regression tests passed (`./tests/backup-restore-regressions.sh`). - `nix fmt` was run. - `nix flake check` passed.
nimmo merged commit 29d6fcd3a7 into main 2026-10-04 11:17:04 +01:00
nimmo deleted branch fix/backrest-cli-restore-hardening 2026-10-04 11:17:05 +01:00
Sign in to join this conversation.
No reviewers
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
nimmo/nixos-config!265
No description provided.