ND-0020 / LINUX OPERATIONS
The Checksum Passed. Can the Service Read the Restored File?
Two copies of a restored configuration file both pass the SHA-256 check. One copy has group-read permission. The other doesn’t. If the service depends on that permission, the restore can look good in a ticket and still fail at startup. Predict the two modes Archive a file with mode 0640. Restore it twice under umask […]
Two copies of a restored configuration file both pass the SHA-256 check. One copy has group-read permission. The other doesn’t. If the service depends on that permission, the restore can look good in a ticket and still fail at startup.
Predict the two modes
Archive a file with mode 0640. Restore it twice under umask 0077 as an ordinary user. What mode will each copy have? GNU tar can apply the current umask on ordinary extraction. --same-permissions asks it to restore the archived mode bits. Both extractions use the same bytes. GNU tar permission reference
Run a disposable restore
Run this in a disposable Linux shell as a non-root user with GNU tar and Coreutils. It creates its own harmless archive and extracts it only into fresh directories. It does not alter your shell’s umask or read production files.
(
set -eu
test "$(id -u)" -ne 0
lab=$(mktemp -d)
trap 'rm -rf -- "$lab"' EXIT
cd "$lab"
mkdir source masked preserved
printf 'mode=demo\n' > source/service.conf
chmod 0640 source/service.conf
(cd source && sha256sum service.conf) > expected.sha256
tar -cf backup.tar -C source service.conf
(
umask 0077
tar -xf backup.tar -C masked
tar --same-permissions -xf backup.tar -C preserved
)
stat -c '%a %n' source/service.conf masked/service.conf preserved/service.conf
(cd masked && sha256sum -c ../expected.sha256)
(cd preserved && sha256sum -c ../expected.sha256)
)
What we verified
On Debian 13, GNU tar 1.35 and Coreutils 9.7 reported source mode 640, ordinary restore 600, and preserve-mode restore 640. Both copies reported service.conf: OK. The ordinary restore lost the group-read bit. We did not test a separate service identity, ACLs, mandatory access controls, ownership restoration, or service recovery.
Make service access a separate pass condition
Check the intended owner and group, parent directory traversal, ACLs, and any applicable SELinux or AppArmor policy. Then make a benign read through an isolated instance running as the intended service identity. Do not blindly restore permissive archived modes or make the file world-readable to force a pass. Record content integrity, intended access, and the application result separately. For the baseline exercise, see Restore a Backup Before You Need It.