Skip to content

Commit 795cfbc

Browse files
committed
logging: fix FSS journal rotation after key setup
Per systemd documentation, journalctl --rotate is required after --setup-keys to create a new journal file that uses the FSS keys. Without rotation, entries in the existing journal remain unsealed. Changes: - Add journalctl --rotate after FSS key generation - Update test script to use verification key for sealed journals - Simplify service dependencies (no socket ordering needed) Signed-off-by: Julius Koskela <julius.koskela@unikie.com>
1 parent 86f7c16 commit 795cfbc

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

modules/common/logging/fss.nix

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
# Operational Notes:
3838
# -----------------
3939
# 1. First Boot (per component):
40-
# - journal-fss-setup.service runs before systemd-journald
40+
# - journal-fss-setup.service runs after systemd-journald is ready
4141
# - Generates sealing keys with configured seal interval
42+
# - Rotates journal to start using FSS keys immediately
4243
# - Extracts verification key to cfg.keyPath/<hostname>/verification-key
4344
# - Each component creates its own subdirectory with independent keys
4445
# - CRITICAL: Backup all verification-keys to secure offline storage
@@ -157,6 +158,14 @@ let
157158
exit 1
158159
fi
159160
161+
# Rotate journal to start using FSS keys immediately
162+
# Per systemd documentation, rotation is required after --setup-keys
163+
# to create a new journal file that uses the FSS keys
164+
echo "Rotating journal to enable sealing..."
165+
if ! journalctl --rotate; then
166+
echo "Warning: Journal rotation failed - sealing may not start until next natural rotation"
167+
fi
168+
160169
# Create sentinel file to prevent re-initialization
161170
touch "$INIT_FILE"
162171
chmod 0644 "$INIT_FILE"
@@ -414,21 +423,18 @@ in
414423
];
415424

416425
# One-shot service to generate FSS keys on first boot
426+
# Runs after journald is ready, then rotates journal to enable sealing
417427
systemd.services.journal-fss-setup = {
418428
description = "Setup Forward Secure Sealing keys for systemd journal";
419429
documentation = [ "man:journalctl(1)" ];
420430

421-
wantedBy = [ "sysinit.target" ];
422-
before = [ "systemd-journald.service" ];
423-
after = [ "local-fs.target" ];
431+
wantedBy = [ "multi-user.target" ];
432+
after = [ "systemd-journald.service" ];
433+
wants = [ "systemd-journald.service" ];
424434

425435
unitConfig = {
426-
# Prevent implicit After=basic.target which creates ordering cycle
427-
DefaultDependencies = false;
428436
# Only run if not already initialized
429437
ConditionPathExists = "!${cfg.keyPath}/initialized";
430-
# Ensure journal directory is ready and writable
431-
ConditionPathIsReadWrite = "/var/log/journal";
432438
};
433439

434440
serviceConfig = {

tests/logging/test_scripts/fss-test.nix

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,31 @@ writeShellApplication {
141141
142142
# Test 5: Run journal verification
143143
info "Test 5: Running journal verification..."
144+
145+
# Find and use verification key (same logic as verify service)
146+
# Without the key, sealed journals will fail verification with "Required key not available"
147+
VERIFY_KEY=""
148+
for KEY_PATH in \
149+
"/persist/common/journal-fss/$HOSTNAME/verification-key" \
150+
"/etc/common/journal-fss/$HOSTNAME/verification-key"; do
151+
if [ -f "$KEY_PATH" ] && [ -s "$KEY_PATH" ]; then
152+
VERIFY_KEY=$(cat "$KEY_PATH")
153+
echo " Using verification key from $KEY_PATH"
154+
break
155+
fi
156+
done
157+
158+
VERIFY_CMD="journalctl --verify"
159+
if [ -n "$VERIFY_KEY" ]; then
160+
VERIFY_CMD="journalctl --verify --verify-key=$VERIFY_KEY"
161+
else
162+
echo " WARNING: No verification key found - sealed journals may fail verification"
163+
fi
164+
144165
VERIFY_OUTPUT=""
145166
VERIFY_EXIT=0
146167
147-
if VERIFY_OUTPUT=$(journalctl --verify 2>&1); then
168+
if VERIFY_OUTPUT=$($VERIFY_CMD 2>&1); then
148169
VERIFY_EXIT=0
149170
else
150171
VERIFY_EXIT=$?
@@ -174,7 +195,7 @@ writeShellApplication {
174195
175196
# Test 6: Check verification timer
176197
info "Test 6: Checking verification timer..."
177-
if systemctl list-unit-files | grep -q "journal-fss-verify.timer"; then
198+
if systemctl list-unit-files 2>/dev/null | grep -q "journal-fss-verify.timer"; then
178199
if systemctl is-active --quiet journal-fss-verify.timer; then
179200
pass "journal-fss-verify.timer is active"
180201
NEXT_RUN=$(systemctl list-timers journal-fss-verify --no-pager 2>/dev/null | grep journal-fss-verify | awk '{print $1, $2}' || echo "unknown")

0 commit comments

Comments
 (0)