Repository navigation
fix: read an existing vault key without writing to the data folder - #54
Open
leninworld wants to merge 1 commit into
Open
leninworld wants to merge 1 commit into
leninworld wants to merge 1 commit into
Conversation
Store::vault_key created and synced a temporary key file in the data folder before it looked at vault.key, and read the existing key only when saving the new one failed. A data folder that cannot be written, such as read-only media served with --read-only, could not read a stored credential, although its key was there. Read an existing key first, with the same checks, and create one only when it is missing. Signed-off-by: Lenin Mookiah <2639584+leninworld@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Store::vault_key(crates/graphicle/src/vault.rs) always created and synced aNamedTempFilein the data folder first, and read an existingvault.keyonly whenpersist_noclobberthen failed withAlreadyExists. So every read of a stored credential (Store::secret, used for a model whose key issecret:IDor anoauth:account) wrote a temporary file into the data folder, and on a folder that cannot be written it failed withLocal I/O failed: Permission deniedalthough the key was there. That is the read-only media casedocs/configuration.mdgives for--read-only: the store opens, then the credential read fails.vault.keyis now read first, through the same checks as before (moved into one helper:O_NOFOLLOW, a regular 32-byte file, owner-only permissions on Unix). A key is only created when the file is missing, exactly as before, including theAlreadyExistsre-read for two processes creating it at once. Error messages are unchanged; an extension that holds the key still answers first.Not changed: with
--read-onlyand novault.keyat all, a key is still created (and the credential then fails its integrity check), as onmain; refusing that would be a separate change. A key on media that reports group or other permission bits (FAT, exFAT) is still refused as not owner-only.Test plan
vault::tests::an_existing_vault_key_is_read_from_a_directory_that_cannot_be_written(Unix): saves a secret, makes the temp data folder0o500(and checks a probe file cannot be created there), then reads the key and checks the folder listing is unchanged. Onmain'svault_keyit fails withPermission deniedat the temporary file; with this change it passes.Store::secreton a store reopened with--read-onlysemantics from an unwritable folder fails onmainwith the samePermission deniedand returns the saved value with this change.cargo test --locked --test extensionkeeps the vault-key cases (Invalid local vault keyfor a key that holds no key) passing.cargo fmt --check,cargo clippy --locked --all-targets -- -D warnings,cargo clippy --locked --all-targets --features local-inference -- -D warningsandcargo test --locked --all-targetsincrates/graphicle(lib 507 passed, it 566 passed / 3 ignored, extension 27 passed; Rust 1.95.0, macOS). Linux and Windows run in CI.