Skip to content

Validate complete transfer archives before stopping services or restoring files #3

Open

Description

@LunaStev

Problem

import-server.sh checks archive entry names through a loop fed by process substitution:

while IFS= read -r entry; do
  # allowed-entry checks
  ...
done < <(tar -tzf "$archive_path")

The exit status of the tar process is not checked by the loop. A corrupt archive can therefore pass this phase with no entries and reach docker compose down before extraction fails. set -Eeuo pipefail does not make that asynchronous producer's failure the loop's exit status.

The entry allowlist also checks only names that exist. A readable archive containing .env but no data/ payload is accepted, and the script proceeds to start the application without the data that a transfer is meant to restore.

Code references:

Reproduction

Run the script in a disposable directory representing a fresh clone, with no existing .env or data. Put a docker test double on PATH that records arguments and returns success. Use dummy environment contents, not production credentials.

Two focused shell executions produced:

Archive Script result Docker commands reached
Plain text named transfer.tar.gz exit 2, extraction failure compose down --remove-orphans
Valid gzip/tar containing only .env exit 0, no restored data directory compose down, compose up, compose ps

These observations exercise the actual Bash and tar control flow with a Docker command double; they are not a production deployment test.

Expected behavior and scope

Verify archive readability and the required transfer structure before any Docker operation or publication into the destination tree. Treat an archive missing either the environment file or its data payload as an invalid transfer rather than a successful fresh installation.

Check producer exit statuses explicitly. Validate and extract into temporary staging as needed so truncated or otherwise unusable input is rejected before service shutdown or destination writes. Preserve the current allowed-path restrictions and refusal to replace an existing installation.

Completion criteria

  • Corrupt, truncated, empty, and incomplete archives fail before docker compose down or any other Docker command.
  • Require the documented environment file and data directory/payload without inventing a fixed list of database-internal filenames.
  • Preserve rejection of unexpected entries and existing destination .env or nonempty data.
  • Failed validation or staging leaves the destination installation untouched and cleans up temporary files containing dummy/real configuration.
  • A valid complete transfer restores exact fixture contents and restrictive environment-file permissions before startup.
  • Handle staging, extraction, and publication errors with a nonzero status and actionable diagnostics; do not print successful restoration on partial work.
  • Add shell integration tests using temporary directories and a Docker test double, asserting both filesystem state and the exact command sequence.

Difficulty: medium. Backup archive publication is a separate export-side task.

Activity

  1. added
    bug
    help wanted
    on Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions