Skip to content

fix: read an existing vault key without writing to the data folder - #54

Open
leninworld wants to merge 1 commit into
Graphicle-AI:mainfrom
leninworld:fix-vault-key-read-only-folder
Open

leninworld wants to merge 1 commit into
Graphicle-AI:mainfrom
leninworld:fix-vault-key-read-only-folder

Conversation

@leninworld

Copy link
Copy Markdown
Contributor

Summary

  • Store::vault_key (crates/graphicle/src/vault.rs) always created and synced a NamedTempFile in the data folder first, and read an existing vault.key only when persist_noclobber then failed with AlreadyExists. So every read of a stored credential (Store::secret, used for a model whose key is secret:ID or an oauth: account) wrote a temporary file into the data folder, and on a folder that cannot be written it failed with Local I/O failed: Permission denied although the key was there. That is the read-only media case docs/configuration.md gives for --read-only: the store opens, then the credential read fails.
  • An existing vault.key is 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 the AlreadyExists re-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-only and no vault.key at all, a key is still created (and the credential then fails its integrity check), as on main; 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

  • New vault::tests::an_existing_vault_key_is_read_from_a_directory_that_cannot_be_written (Unix): saves a secret, makes the temp data folder 0o500 (and checks a probe file cannot be created there), then reads the key and checks the folder listing is unchanged. On main's vault_key it fails with Permission denied at the temporary file; with this change it passes.
  • One-off check, not committed (it sets the process-wide read-only flag): Store::secret on a store reopened with --read-only semantics from an unwritable folder fails on main with the same Permission denied and returns the saved value with this change.
  • cargo test --locked --test extension keeps the vault-key cases (Invalid local vault key for 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 warnings and cargo test --locked --all-targets in crates/graphicle (lib 507 passed, it 566 passed / 3 ignored, extension 27 passed; Rust 1.95.0, macOS). Linux and Windows run in CI.

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

No deployments
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