fix(db): keep a read-only database read-only - #547
Open
kevintseng wants to merge 2 commits into
Open
kevintseng wants to merge 2 commits into
kevintseng wants to merge 2 commits into
Conversation
Opening the database set its file mode to 600, which gave the owner back the write permission on a database made read-only, so every later process wrote into it. Only access for other users is removed now; the owner's permissions are left as they are. Closes #520
A WAL database cannot be read without creating its -shm file, so a database in a folder the owner made read-only is refused with an error; opening it used to work only by making the folder writable again.
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.
Refs #520.
Opening a database you made read-only (for example
chmod 444on a snapshot or backup) no longer makes it writable. memesh set the database file, its-wal/-shmfiles and its folder to fixed modes (600/700) on every open, which gave the owner back the write permission, so every later hook, CLI or MCP process wrote into it. It now only removes access for other users and leaves the owner's permissions as they are. A world-readable database is still tightened to owner-only.A database whose folder is also read-only cannot be opened (a WAL database needs to create its
-shmfile), so it is now refused with an error instead of being made writable.Tests
New
tests/db-readonly-mode.test.ts: a444database stays non-writable across two opens, a644database is still tightened to600, and a read-only database in a read-only folder is refused with nothing made writable. The first two fail on the previous code.npm run verify: green.