Repository navigation
fix(encryption): close the encryption and data-safety gaps of #64 (W3) - #67
Merged
Merged
Conversation
Part of #64 (workstream W3): C3, H1, H2, H4, M14, M15, M17. - C3: `backup create` writes every column of hammerwork_jobs (read from information_schema, one encoding for both backends) and `backup restore` writes them back in one transaction, skipping existing ids. Encrypted payloads, cron, timeouts, retry strategies, dependencies, workflows, batches, results, tracing and retention round-trip. - H1: the CLI and the dashboard load the application's [encryption] settings (PayloadEncryptionConfig::load) and fail instead of writing plaintext; JobQueue::with_plaintext_guard refuses plaintext jobs on queues that hold encrypted jobs. `job enqueue --encrypt/--pii-field`. - H2: get_dead_jobs / get_dead_jobs_by_queue select the full row, so decrypt_job works on dead jobs. - H4: KMS-backed engines reload stored key versions on a decryption failure (and reload_kms_keys), so workers survive a rotation by another process. - M14: redacting Debug for configs holding database URLs, webhook, alert, streaming and KMS secrets and the dashboard password hash; webhook URLs are logged without their path; `config show` masks the password. - M15: Vault and Azure key material must be exactly 32 bytes. - M17: key material is held in zeroize::Zeroizing and shared, not copied. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CodingAnarchy
force-pushed
the
fix/encryption-data-safety
branch
from
October 9, 2026 23:01
411f0bc to
ec9a5db
Compare
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.
Part of #64: workstream W3 (encryption and data safety). Fixes findings C3, H1, H2, H4, M14, M15, M17.
What changes
C3:
cargo hammerwork backuploses encrypted payloads and most job attributesbackup create(JSON, format2.0) now writes every column ofhammerwork_jobs. The column list comes frominformation_schema, so new columns from future migrations are included without anyone keeping a list in sync. A column type the backup can't copy is an error, never silently dropped.backup restorewrites every column back:INSERT IGNORE, which turned conversion errors into warnings. It now does a plainINSERTand treats a duplicate-key error as "skipped".1.0backups still restore.cargo-hammerwork/src/utils/job_rows.rs.H1: the CLI and the dashboard enqueue plaintext on encrypted queues
PayloadEncryptionConfig::load(path). It reads only the[encryption]section of the application'shammerwork.toml, then appliesHAMMERWORK_ENCRYPTION_*.config set encryption_config <path>orHAMMERWORK_ENCRYPTION_CONFIG. These commands now build their queue withapply_encryption_config:job enqueuebatch enqueuecron createworkflow createHAMMERWORK_ENCRYPTION_CONFIGis read where the queue is built inserver.rs. The web change is kept to queue construction plus the M14Debugimpls, to avoid colliding with W1.JobQueue::with_plaintext_guard(true). Used by both tools; off by default for applications. When on,enqueue,enqueue_batch,enqueue_workflowandenqueue_cron_jobrefuse to store a plaintext job on a queue that already holds encrypted jobs, and write nothing. This also covers tools that were given no settings at all. A queue that has never held an encrypted job can't be detected this way, which the docs say.job enqueue --encrypt/--pii-field <f>encrypt a job with the application's key on any queue.cargo-hammerworkandhammerwork-webnow enable hammerwork'sencryptionfeature.cargo-hammerworkgainsaws-kms,gcp-kms,vault-kmsandazure-kvpass-through features.H2:
get_dead_jobs/get_dead_jobs_by_queuedrop the encryption metadataJOB_SELECT_FIELDSintoJobRow.DeadJobRowis removed.TestQueue, then decrypt it:get_jobget_ready_jobsget_dead_jobsget_dead_jobs_by_queueget_jobs_completed_in_rangeget_batch_jobsget_workflow_jobsget_recurring_jobsH4: KMS data-key rotation sends other workers' jobs to Dead
new_with_poolkeep an owned store (PoolStore).EncryptionEngine::reload_kms_keys().M14: secrets in
Debugoutput, logs andconfig showDebugimpls:DatabaseConfigWebhookConfigandWebhookAuthAlertTargetStreamBackendExternalKmsConfigConfigDashboardConfigandAuthConfigconfig showmasks the database password.hammerwork::config::redact_urlandredact_url_path. The CLI'sredact_urlnow delegates to the library one.Debugoutput does not contain the secret.M15: Vault/Azure key material is padded instead of rejected
keyfield) and Azure material must be exactly 32 bytes, otherwiseEncryptionError::InvalidConfiguration.KeyManagermaster keys alike. Passphrases are no longer hashed into keys.M17: key material is never zeroized
zeroizewas already inCargo.lock(1.9.1). It is added as an optional dependency of theencryptionfeature.Arc<Zeroizing<Vec<u8>>>, shared rather than cloned per operation.Zeroizing:KeyManagermaster, root, retired and cached keysVec<u8>(KeyManager::get_key) still do; the caller owns that copy.Behaviour changes for users
vault://andazure://keys that relied on padding or passphrase hashing no longer load. Jobs encrypted under the old derived key need draining or re-enqueueing before the switch. This is in the CHANGELOG upgrade notes.2.0(all columns;priorityis numeric). Restore still reads1.0.POST /api/jobs, now error instead of storing plaintext on a queue that holds encrypted jobs. The dashboard doesn't start if its configured key can't be loaded.Tests
Run locally against PostgreSQL 16 and MySQL 8, the way CI runs them:
cargo test --workspace --all-features --no-fail-fast -- --include-ignored --skip mysql: 1755 passed, 0 failedcargo test --workspace --all-features --no-fail-fast -- --include-ignored mysql, with both URLs pointing at MySQL: 145 passed, 0 failedcargo run -p postgres-integrationandcargo run -p mysql-integration: passcargo test -p hammerwork --doc --all-features(523 passed) andcargo test -p hammerwork --doc(186 passed)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean"",postgres,mysql,postgres,mysql,postgres,encryption,mysql,tracing,postgres,streaming,postgres,webhooks) withclippy -p hammerwork --lib --tests --no-default-features: cleancargo +1.91.1 check --workspace --all-features --all-targets --lockedandcargo metadata --locked: pass. Lockfile diff: two dependency entries.New database tests (each on both backends):
backup_restores_every_column: compares full-row fingerprints computed by the database before and after a wipe and restore. Encrypted jobs still decrypt afterwards, a second restore is a no-op, and a backup carrying an unknown column restores nothing.enqueue_follows_the_application_encryptionevery_read_path_keeps_the_ciphertextplaintext_guard_refuses_plaintext_on_encrypted_queuesworker_survives_a_rotation_by_another_processDocs updated:
docs/encryption.md(fleet rotation, Vault/Azure key size, the new "The CLI and the web dashboard" section, read paths, memory protection), README, the CLI README and the web README. CHANGELOG has entries under Security and Changed (upgrade notes).🤖 Generated with Claude Code