Repository navigation
Closed
Description
Found while making the lib tests hermetic (#7). Once the KeyManager DB tests in src/encryption/key_manager.rs get a master key and a real database, 12 of the 14 fail. Each failure comes from library code, not from the tests. Key persistence has never worked against either backend; before this, the tests stopped earlier on the missing HAMMERWORK_MASTER_KEY or on the MySQL #[sqlx::test] pool timeout.
Bugs
- The generic DB methods are stubs that always fail.
store_key,load_key,retire_key_version,cleanup_old_key_versions,record_key_usageandrecord_audit_eventinimpl<DB: Database> KeyManager<DB>all returnKeyManagement("Database-specific implementation required"). The Postgres and MySQL versions (store_key_postgres,store_key_mysqland so on) exist but are never called; they are marked#[allow(dead_code)]. As a result these public methods always fail:generate_key/generate_key_with_options, throughstore_keyget_key, throughload_keyandrecord_key_usagerotate_key, throughload_keygenerate_master_keywhenaudit_enabled(the default), throughrecord_audit_event
perform_automatic_rotationdoes nothing. The generic version logs a warning and returnsvec![]. Nothing calls the backend-specificget_keys_due_for_rotation.generate_master_keykeeps the key only in memory. It never writes it to the database, sofind_master_key_id_in_databasecannot return it.key_sourceviolates the schema CHECK constraint.store_key_*bindsKeySource'sDisplayoutput, for exampleGenerated(rotation). Both schemas only allow'Environment' | 'External' | 'Generated' | 'Derived' | 'Static', andparse_key_sourceexpects the parenthesised form back. ForKeySource::Static(key), thatDisplayoutput also writes the raw key string into the table.- Postgres
rotation_intervaluses the wrong type.store_key_postgresbinds aStringsuch as"2592000 seconds"into anINTERVALcolumn, which fails withcolumn "rotation_interval" is of type interval but expression is of type text.load_key_postgresreads the column asOption<String>, which will also fail on anINTERVAL.
Affected tests
These are #[ignore]d in the hermetic-tests PR with a reason that points here:
test_master_key_storage_{postgres,mysql}: bugs 1 and 3test_key_rotation_{postgres,mysql}: bug 1test_rotation_scheduling_{postgres,mysql},test_database_statistics_{postgres,mysql},test_refresh_stats_integration_{postgres,mysql}: bug 5 (Postgres), bug 4 (MySQL)test_automatic_rotation_{postgres,mysql}: bugs 4 and 5, then bug 2
test_get_or_create_master_key_id_{postgres,mysql} pass.
Done when
All 14 encryption::key_manager::tests::*_{postgres,mysql} tests pass with cargo test --all-features --lib -- --include-ignored, DATABASE_URL and MYSQL_DATABASE_URL set, and the blocked by ignore reasons removed.
Metadata
Metadata
Assignees
Labels
No labels
Activity
test: gate #9-blocked key manager tests behind HAMMERWORK_TEST_KNOWN_…
test: make lib tests pass without external services
test: gate #9-blocked key manager tests behind HAMMERWORK_TEST_KNOWN_…
test: make lib tests hermetic (#7) (#13)
fix(encryption): fail closed on key loading and implement KeyManager …
fix(encryption): fail closed on key loading, implement KeyManager per…