Portainer backup restoration – missing automatic integrity verification before activation
0 reputation · 03 Oct 2022, 19:50 UTC
0 reputation · 03 Oct 2022, 19:50 UTC
When restoring a Portainer backup, the administrator imports an SQLite database file to recover stack definitions, user settings, and endpoint configurations. The current feature does not automatically verify that the imported file is intact or unaltered before it becomes the active database, leaving the verification step to the operator.
This raises the question of whether Portainer should enforce an integrity check (e.g., a SHA‑256 comparison) as part of the restore process, and what permission boundaries should govern any override or bypass of that check.
33775 reputation · 03 Oct 2022, 22:11 UTC
Portainer does not currently enforce an automatic integrity check on the SQLite database before activating a restored backup. To prevent the activation of corrupted or altered data, administrators should implement a manual verification pipeline before replacing the active /data directory.
Because the restoration process typically involves replacing the existing data volume, verification must occur in a temporary staging area. Follow these steps to ensure backup health:
portainer.db and settings.json) are present using: tar -tzf backup_file.tar.gzsqlite3 /path/to/extracted/portainer.db "PRAGMA integrity_check;"ok. Any other output indicates a corrupted database that should not be activated./data directory with the verified files, and restart the container.To address the lack of native automation, the following logic is recommended for future implementation or external scripting:
This guidance assumes the use of the standard Portainer SQLite backend. If using an external database, these steps do not apply. One critical diagnostic detail is missing: Does your current backup routine include a sidecar checksum file? If a manifest already exists, the manual PRAGMA check is secondary to the checksum validation.
Use comments to ask for clarification. Post a solution as an answer.
33,775 reputation · 04 Oct 2022, 07:43 UTC
Instead of relying on manual staging, Portainer could expose a small pre‑restore hook that reads a .sha256 manifest bundled with the archive. The hook would compute sha256sum of the uploaded file, compare it to the manifest, and only allow the swap if the values match. This keeps the active database untouched until the checksum succeeds, reducing the risk of silent corruption.
Allowing a bypass should be limited to the highest‑level “Admin” role. The UI can prompt for a second confirmation and record the action in the audit log with the user’s ID and timestamp, ensuring traceability.
When the checksum fails, the restore dialog should display a clear error and block the operation. If a webhook or email notification is configured, the failure can be pushed there automatically.