Scope remote-db keypairs by vault - #832
Open
cyc60 wants to merge 3 commits into
Open
Conversation
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.
Description
Scope remote-db keypairs by vault
KeyPairsCrudfiltered the{network}_keypairstable only by network, never by vault, even though the CLI is invoked per vault. When two vaults share one remote Postgres database, one vault's process could read, decrypt, and export another vault's validator private keys, andremote-db cleanupdeleted every vault's rows at once.Every query is now scoped to
settings.vault:create_tablerestores thevaultcolumn with aUNIQUE (vault, public_key)constraint (previously a global per-columnUNIQUE), plus an idempotentALTER TABLE ... ADD COLUMN IF NOT EXISTS vaultso an existing table without the column is upgraded in place rather than crashing on the new queries.get_keypairs_count,get_first_keypair, andget_keypairsfilterWHERE vault = ..., so key export and the encryption-key check operate only on the current vault's rows.remove_keypairsalways filters by vault, socleanupremoves only the current vault's keys.upload_keypairsinserts thevaultcolumn. This also corrects the INSERT, which named three columns but supplied four%splaceholders and three-tuple rows — it raised on any real insert, soremote-db upload-keypairshad been non-functional.RemoteDatabaseKeyPairis unchanged: the vault is process context, supplied directly in SQL. The previous tests mocked the database connection wholesale, so the SQL was never exercised; the newtest_database.pydrivesKeyPairsCrudwith a fake cursor that records the emitted SQL and parameters, asserting vault-scoping on every read/delete and the INSERT column/placeholder arity.