Skip to content

fix: Restore authorized_keys atomically so an interrupt cannot empty it - #311

Draft
lauri-amd wants to merge 1 commit into
mainfrom
fix-eai-8239
Draft

fix: Restore authorized_keys atomically so an interrupt cannot empty it#311
lauri-amd wants to merge 1 commit into
mainfrom
fix-eai-8239

Conversation

@lauri-amd

Copy link
Copy Markdown
Contributor

Cleanup restored the user's authorized_keys with an O_TRUNC copy, leaving the file empty for the duration of the write. Interrupting bloom during that window made the truncation permanent and could lock an operator out of the node. Observed in the field.

Restore (and install) now write a temp file in the same directory and rename it into place, so a reader only ever sees the old or new content. Cleanup takes a mutex, since interrupt handling gives it three concurrent callers, and a failed restore now returns an error instead of nil so the caller stops reporting success over a file it did not restore.

Cleanup restored the user's authorized_keys with an O_TRUNC copy, leaving
the file empty for the duration of the write. Interrupting bloom during
that window made the truncation permanent and could lock an operator out
of the node. Observed in the field.

Restore (and install) now write a temp file in the same directory and
rename it into place, so a reader only ever sees the old or new content.
Cleanup takes a mutex, since interrupt handling gives it three concurrent
callers, and a failed restore now returns an error instead of nil so the
caller stops reporting success over a file it did not restore.
Comment thread pkg/ssh/ephemeral.go
// that window makes the truncation permanent, and for authorized_keys that
// locks the operator out of the node. Pass uid/gid as -1 to leave ownership to
// the caller.
func writeFileAtomically(path string, content []byte, mode os.FileMode, uid, gid int) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atomicWriteFile already exists in pkg/ansible/runtime/fstab.go - perhaps combine the implementation in one place?

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.

2 participants