Skip to content

chore: test ENCRYPTION_SALT_KEYS multi-key and two-step rotation#61038

Merged
Piccirello merged 1 commit into
masterfrom
tom/encryption-salt-keys-rotation-tests
Jun 1, 2026
Merged

chore: test ENCRYPTION_SALT_KEYS multi-key and two-step rotation#61038
Piccirello merged 1 commit into
masterfrom
tom/encryption-salt-keys-rotation-tests

Conversation

@Piccirello
Copy link
Copy Markdown
Member

Problem

We're rotating ENCRYPTION_SALT_KEYS. The key list is consumed by two independent implementations — Django (MultiFernet) and the Node.js services (fernet-nodejs) — and the rotation rolls out across apps that cannot be guaranteed to redeploy at the same moment. Before rotating, we want automated proof that the multi-key contract and the staged rollout behave safely in both implementations.

Changes

Tests only — no production code changes.

  • Python (posthog/helpers/tests/test_encrypted_fields.py): cover the multi-key ENCRYPTION_SALT_KEYS contract and the two-step rotation.
  • Node.js (nodejs/src/cdp/utils/encryption-utils.test.ts): matching coverage for the same contract.

Both suites assert the shared contract and the rollout safety property:

  • the first key encrypts; every key is tried for decryption;
  • modelling the rollout as [old] → [old,new] → [new,old], within each step's mixed-version window every coexisting app can decrypt whatever any other app writes;
  • a direct one-step jump ([old] → [new,old]) would break an un-upgraded [old]-only app — the negative case that justifies doing it in two steps.

How did you test this code?

I'm an agent (Claude Code). No manual testing — only the automated tests below, run locally and passing:

  • hogli test posthog/helpers/tests/test_encrypted_fields.py::TestEncryptedFieldsMultiKey and ::TestEncryptionKeyRotationTwoStep
  • hogli test nodejs/src/cdp/utils/encryption-utils.test.ts (14 passed)

Both new suites are database-free (SimpleTestCase / jest unit tests).

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Docs update

Tests only; no docs impact.

🤖 Agent context

Authored with Claude Code (Opus). The work verifies the encryption-key-rotation behavior in both implementations independently, since they're separate codebases that must honor the same first-key-encrypts / try-all-keys-to-decrypt contract. The rollout is expressed as coexisting app states (parameterized in Python, it.each in Node) so the safety invariant is asserted directly rather than described.

Scope decision: a companion re-encryption management command (and its database-backed tests) was developed alongside these tests but is intentionally excluded from this PR by request — this PR is the self-contained behavior tests only. Agent-authored; requires human review.

Add coverage for the multi-key ENCRYPTION_SALT_KEYS contract shared by the
Python (MultiFernet) and Node.js (fernet-nodejs) implementations: the first key
encrypts, every key is tried for decryption.

Also verify the two-step rollout used to rotate the key across independently
deployed apps ([old] -> [old,new] -> [new,old]): within each step's mixed-version
window every running app can decrypt what any other writes, and a direct one-step
jump would break an un-upgraded app.

Tests only; no production code changes.
@assign-reviewers-posthog assign-reviewers-posthog Bot requested a review from a team June 1, 2026 23:20
@Piccirello Piccirello added the stamphog Request AI review from stamphog label Jun 1, 2026
@Piccirello Piccirello removed the request for review from a team June 1, 2026 23:21
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test-only additions covering multi-key encryption and two-step key rotation — no production code touched, no risk of regressions.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 1, 2026

Reviews (1): Last reviewed commit: "chore: test ENCRYPTION_SALT_KEYS multi-k..." | Re-trigger Greptile

@Piccirello Piccirello merged commit 4a4c3e5 into master Jun 1, 2026
258 of 269 checks passed
@Piccirello Piccirello deleted the tom/encryption-salt-keys-rotation-tests branch June 1, 2026 23:35
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

🎭 Playwright report · View test results →

⚠️ 2 flaky tests:

  • create experiment via wizard, add metrics, and launch (chromium)
  • Can delete a person (chromium)

These issues are not necessarily caused by your changes.
Annoyed by this comment? Help fix flakies and failures and it'll disappear!

@deployment-status-posthog
Copy link
Copy Markdown

deployment-status-posthog Bot commented Jun 1, 2026

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-06-01 23:56 UTC Run
prod-us ✅ Deployed 2026-06-02 10:18 UTC Run
prod-eu ✅ Deployed 2026-06-02 10:20 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stamphog Request AI review from stamphog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant