Add spacetime lock/unlock to prevent accidental database deletion#4502
Open
clockwork-labs-bot wants to merge 2 commits intomasterfrom
Open
Add spacetime lock/unlock to prevent accidental database deletion#4502clockwork-labs-bot wants to merge 2 commits intomasterfrom
spacetime lock/unlock to prevent accidental database deletion#4502clockwork-labs-bot wants to merge 2 commits intomasterfrom
Conversation
Adds a database lock mechanism to protect production databases from accidental deletion via `spacetime delete`. ## Changes ### Server (client-api + standalone) - Add `is_database_locked` to `ControlStateReadAccess` trait - Add `set_database_lock` to `ControlStateWriteAccess` trait - Implement both in standalone control DB using a `database_locks` sled tree (separate from the Database struct to avoid migration) - Add `POST /v1/database/:name_or_identity/lock` route - Add `POST /v1/database/:name_or_identity/unlock` route - Check lock state in `delete_database` route handler; return 403 with descriptive error if locked ### CLI - Add `spacetime lock [database]` subcommand - Add `spacetime unlock [database]` subcommand - Both support `--server` and `--no-config` flags - Both resolve database from spacetime.json when no argument given ## Usage ```bash # Lock a database spacetime lock my-database # Attempt to delete (fails with 403) spacetime delete my-database # Error: Database is locked and cannot be deleted. # Run \`spacetime unlock\` first. # Unlock when you really want to delete spacetime unlock my-database spacetime delete my-database ```
Lock now also prevents the reset route (which publish --delete-data delegates to). Returns 403 with a message telling the user to unlock.
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.
Motivation
Feature request: "Is there any way we can lock a module to prevent it from being deleted? A bit concerned about some fat finger risk of accidentally deleting prod."
Solution
Adds a database lock mechanism. A locked database cannot be deleted until explicitly unlocked.
New CLI Commands
Both commands support
--serverand--no-configflags, and resolve the database fromspacetime.jsonwhen no argument is given (same asspacetime delete).New HTTP API
POST /v1/database/:name_or_identity/lock-- Lock a databasePOST /v1/database/:name_or_identity/unlock-- Unlock a databaseBoth require the same authorization as
DELETE(owner only).Implementation
database_lockssled tree in the standalone control DB (avoids changing theDatabasestruct and needing a data migration)ControlStateReadAccess::is_database_locked()andControlStateWriteAccess::set_database_lock()added to the traitdelete_databaseroute checks lock state before proceeding; returns403 Forbiddenwith a descriptive message if lockedWhat is NOT locked
spacetime publish(updating module code) still works on locked databasesspacetime deleteis blockedThis matches the intent: protect prod from accidental destruction while allowing normal deployments.