Skip to content

fix(enclave): write the LUKS keyfile atomically (tmp + rename)#198

Merged
samlaf merged 2 commits into
seismicfrom
atomic-luks-keyfile-write
Jul 2, 2026
Merged

fix(enclave): write the LUKS keyfile atomically (tmp + rename)#198
samlaf merged 2 commits into
seismicfrom
atomic-luks-keyfile-write

Conversation

@samlaf

@samlaf samlaf commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

setup-persistent-luks (seismic-images) polls for this exact path at 1Hz, but create+truncate+write makes the file visible at open(), an instant before its 64 bytes land — a poller waking inside that window reads a short keyfile. Write to luks-keys.tmp and rename into place so existence implies fully written; the script-side wait now relies on exactly that.

rename also fixes a pre-existing restart wrinkle: the keyfile is mode 0400, so reopening it with truncate(true) is EACCES even for the owner — an enclave-server restart before the script consumed the previous keyfile would have failed here. rename replaces the stale file without opening it. The stale .tmp from a crashed earlier run is removed up front, since create_new would refuse it for the same permission reason (and it holds key material worth scrubbing).

setup-persistent-luks (seismic-images) polls for this exact path at
1Hz, but create+truncate+write makes the file visible at open(), an
instant before its 64 bytes land — a poller waking inside that window
reads a short keyfile. Write to luks-keys.tmp and rename into place so
existence implies fully written; the script-side wait now relies on
exactly that.

rename also fixes a pre-existing restart wrinkle: the keyfile is mode
0400, so reopening it with truncate(true) is EACCES even for the owner
— an enclave-server restart before the script consumed the previous
keyfile would have failed here. rename replaces the stale file without
opening it. The stale .tmp from a crashed earlier run is removed up
front, since create_new would refuse it for the same permission reason
(and it holds key material worth scrubbing).
@samlaf samlaf requested a review from cdrappi as a code owner July 2, 2026 11:11
@samlaf samlaf merged commit 4fa1b5f into seismic Jul 2, 2026
5 of 6 checks passed
@samlaf samlaf deleted the atomic-luks-keyfile-write branch July 2, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant