1
0
mirror of https://github.com/systemd/systemd synced 2026-03-18 11:04:46 +01:00

Compare commits

..

2 Commits

Author SHA1 Message Date
Daan De Meyer
e901e256d9 machined: Don't insist on 0:0 for the state directory
We now support running machined unprivileged, so don't pass in 0:0
as the uid/gid unconditionally but just use the UID/GID we're running
as.
2026-01-12 19:08:00 +01:00
ZauberNerd
7bf0d0c46e mkfs-util: set hash_seed to seed derived value for reproducibility
When creating ext2/ext3/ext4 filesystems, mke2fs generates a random
hash_seed for htree directory indexing. This causes non-reproducible
images even when SOURCE_DATE_EPOCH is set and the same filesystem UUID
is used.

Set the hash_seed explicitly to match the filesystem UUID, ensuring
that repeated builds with the same seed produce bit-for-bit identical
images.

Also add a test case in TEST-58-REPART to verify ext4 reproducibility
by creating the same partition twice and comparing the results.

See https://vdwaa.nl/mkosi-reproducible-arch-images.html

I used claude ai to help me with this change.
2026-01-12 16:57:44 +01:00
3 changed files with 49 additions and 2 deletions

View File

@ -176,7 +176,7 @@ int machine_save(Machine *m) {
return log_oom(); return log_oom();
} }
r = mkdir_safe_label(m->manager->state_dir, 0755, 0, 0, MKDIR_WARN_MODE); r = mkdir_safe_label(m->manager->state_dir, 0755, UID_INVALID, GID_INVALID, MKDIR_WARN_MODE);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to create '%s': %m", m->manager->state_dir); return log_error_errno(r, "Failed to create '%s': %m", m->manager->state_dir);

View File

@ -421,12 +421,19 @@ int make_filesystem(
/* When changing this conditional, also adjust the log statement below. */ /* When changing this conditional, also adjust the log statement below. */
if (STR_IN_SET(fstype, "ext2", "ext3", "ext4")) { if (STR_IN_SET(fstype, "ext2", "ext3", "ext4")) {
const char *ext_e_opts;
/* Set hash_seed to the same value as the filesystem UUID for reproducibility */
ext_e_opts = strjoina(FLAGS_SET(flags, MKFS_DISCARD) ? "discard" : "nodiscard",
",lazy_itable_init=1,hash_seed=",
vol_id);
argv = strv_new(mkfs, argv = strv_new(mkfs,
"-L", label, "-L", label,
"-U", vol_id, "-U", vol_id,
"-I", "256", "-I", "256",
"-m", "0", "-m", "0",
"-E", FLAGS_SET(flags, MKFS_DISCARD) ? "discard,lazy_itable_init=1" : "nodiscard,lazy_itable_init=1", "-E", ext_e_opts,
"-b", "4096", "-b", "4096",
"-T", "default"); "-T", "default");
if (!argv) if (!argv)

View File

@ -1899,6 +1899,46 @@ testcase_luks2_integrity() {
_test_luks2_integrity "hmac-sha512" _test_luks2_integrity "hmac-sha512"
} }
testcase_ext_reproducibility() {
local defs imgs
# Online mode mounts the filesystem which updates inode timestamps non-deterministically
if [[ "$OFFLINE" != "yes" ]]; then
echo "Skipping ext reproducibility test in online mode."
return 0
fi
defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")"
imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")"
# shellcheck disable=SC2064
trap "rm -rf '$defs' '$imgs'" RETURN
tee "$defs/root.conf" <<EOF
[Partition]
Type=root
Format=ext4
EOF
# Build the image twice with the same seed and verify they are identical
systemd-repart --offline="$OFFLINE" \
--definitions="$defs" \
--empty=create \
--size=50M \
--seed="$seed" \
--dry-run=no \
"$imgs/test1.img"
systemd-repart --offline="$OFFLINE" \
--definitions="$defs" \
--empty=create \
--size=50M \
--seed="$seed" \
--dry-run=no \
"$imgs/test2.img"
cmp "$imgs/test1.img" "$imgs/test2.img"
}
OFFLINE="yes" OFFLINE="yes"
run_testcases run_testcases