Skip to content

Security: KMS master-key loaders silently fall back to a derivable key #16

Closed

Description

@CodingAnarchy

Severity: high (security). With the encryption feature and a KMS-backed master key, any failure to load the key silently replaces it with a key that anyone who knows the configuration can derive.

Where

src/encryption/key_manager.rs, all four external master-key loaders:

  • load_master_key_from_aws (~1583): generate_deterministic_key("aws-kms-master-key", &[key_id, region])
  • load_master_key_from_vault (~1696): generate_deterministic_key("vault-master-key", &[secret_path, &vault_addr])
  • load_master_key_from_gcp (~1779): generate_deterministic_key("gcp-kms-master-key", &[key_resource])
  • load_master_key_from_azure (~1852): generate_deterministic_key("azure-kv-master-key", &[&vault_url, key_name])

Each one logs the error (error!("Failed to load key from AWS KMS: …")) and falls through to the deterministic key. The same happens when the matching cargo feature (aws-kms, vault-kms, …) is not enabled: a kms:// / vault:// config then quietly runs on a derived key with only a warn!.

Impact

  • A KMS outage, an expired credential, an IAM misconfiguration or a typo in the key id all lead to data encrypted under a key derived from public, non-secret inputs (key id/ARN, region, Vault path/address, GCP resource name, Azure vault URL plus key name).
  • Data encrypted during the outage can't be decrypted once the real key is back, or it all ends up under the weak key.
  • No error reaches the caller, so operators don't know it happened.

Expected

  • The loaders return Result<Vec<u8>, HammerworkError> and propagate KMS failures. KeyManager::new / key loading fails closed.
  • Configuring a KMS source without the matching cargo feature is a hard configuration error.
  • If a deterministic development key is still wanted, it takes an explicit opt-in (e.g. KeySource::InsecureDevelopment), and a warning names it as insecure.
  • Tests cover each loader's failure path returning an error. They can use an unreachable endpoint or invalid credentials and need no real cloud access.

Found by the panic and error-handling audit for #7. Related to #9 and #11 (encryption pipeline).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions