Repository navigation
feat(encryption): bind ciphertexts to their job, config section, scheduled purge, TestQueue encryption (#38) - #39
Merged
Conversation
…duled purge (#38) - Job payloads are encrypted with AEAD associated data covering the job id, queue name, key id, algorithm, PII fields and encrypted fields, so swapped ciphertexts or a job moved to another queue fail to decrypt. The format is recorded as `format_version` in `encryption_metadata`; payloads without it (written before this change) still decrypt without associated data. - `[encryption]` section in HammerworkConfig (PayloadEncryptionConfig), consumed by JobQueue::from_config. Keys are only referenced (env://, aws://, gcp://, vault://, azure://), never stored, printed or saved. Fails closed on invalid sections. JobQueue::with_encrypted_queues encrypts whole queues. - WorkerPool::with_encrypted_job_purge / from_hammerwork_config schedule the retention purge. Maintenance passes (purge and stale-job reaper) run in their own task so shutdown never cancels one mid-transaction. - TestQueue applies the same sealing, redaction and decryption semantics. - Archived encrypted jobs must be restored to decrypt; decrypt_job says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CodingAnarchy
force-pushed
the
feat/encryption-followups
branch
from
October 8, 2026 13:35
0b88650 to
e7b2b9c
Compare
28 of 32 tasks
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.
Closes #38
Follow-ups to the payload encryption from #36.
Bind ciphertext to the job (security)
pii_fields, and the fields that were actually encrypted. The fields are length-prefixed (encryption::job_payload::job_associated_data). Decryption recomputes the associated data from the stored row. These changes make decryption fail:encrypted_payload/ nonce / tag between rowsEncryptionMetadata.format_version(#[serde(default)]) is written intoencryption_metadata.1(FORMAT_JOB_BOUND): written for every newly sealed job.0or missing (FORMAT_UNBOUND): decrypted without associated data, so payloads written by the current release still read. They are not re-encrypted.0does not bypass the binding, because the AEAD tag then fails.EncryptionEngine::{encrypt,decrypt}_payload_with_associated_data.EncryptionMetadataliteral inpostgres.rs/mysql.rs, which readsformat_version.[encryption]config sectionHammerworkConfig::encryption: PayloadEncryptionConfigis optional (#[serde(default)]), so existing files still load. Its fields:enabled,algorithm,key_source,key_id,compressiondefault_retention_secs,purge_interval_secsencrypted_queuesdecryption_keys(decrypt-only legacy keys)JobQueue::from_configcalls the newapply_encryption_config. It builds the engine withnew_with_pool, soaws://andgcp://keys work, adds the decryption keys, and setswith_encryptionand the newwith_encrypted_queues. A configured queue therefore encrypts without any code changes.KeySourceRef. The allowed forms areenv://VAR,aws://,gcp://,vault://andazure://. Static or raw keys are rejected at load, and the error does not echo the value.Debugandsave_to_fileonly ever contain the references.deny_unknown_fields) or an unknown algorithmencrypted_queuesset while disabledpurge_interval_secs = 0encryptionfeaturefrom_envreadsHAMMERWORK_ENCRYPTION_*and returns an error on invalid values.Scheduled retention purge
WorkerPool::with_encrypted_job_purge(interval)andwithout_encrypted_job_purge(). It is off by default.WorkerPool::from_hammerwork_config(worker, &config)takes the interval fromencryption.purge_interval_secs.spawn_periodic. Each pass is spawned as its own task and awaited, so neither the shutdown signal nor the supervisor'sabort()cancels a pass mid-transaction (the fix: never abandon database transactions on worker shutdown #35 pattern). The stale-job reaper now uses it too, because it previously ran the DB call inside theselect!.TestQueue encryption
TestQueue::with_encryption,with_encrypted_queues,encryption_engineanddecrypt_jobsharequeue::PayloadEncryption(new,pub(crate)) withJobQueue. That gives TestQueue the same behaviour as the database backends:purge_expired_encrypted_jobsagainst theMockClockArchived encrypted jobs
Decision: restore is required, and this is documented.
decrypt_jobon an archived job (no ciphertext loaded) now returns an error that says to callrestore_archived_job. Tests cover this on both backends and on TestQueue.Tests
job_payload: swapped ciphertexts, changed queue / PII fields / encrypted fields, format downgrade, unknown format, legacy decrypt, AAD unambiguityspawn_periodic: runs until shutdown, never cancels a pass in flighttests/payload_encryption_tests.rs):from_configencryptsencrypted_queues, decrypts old key ids, and fails closedVerified locally:
cargo fmt --checkand workspace clippy with--all-targets --all-features -D warnings--libtestscargo +1.91.1 check🤖 Generated with Claude Code