Add SsoProvider to security:backfill_encryption task
Closed
IT
17d ago+91+91+01234567890123456789-0-0-0123456789
Summary
SsoProvider#client_secretis encrypted (app/models/sso_provider.rb:9), butsecurity:backfill_encryptionnever coveredSsoProvider— it backfills users, invitations, sessions, mobile devices, and provider items/accounts, but the model was missing from the list.- Result: existing rows kept plaintext
client_secretvalues. Any subsequent read (validation runs on everyupdate!, includingAdmin::SsoProvidersController#toggle) tried to decrypt the plaintext as an encrypted JSON envelope and raisedActiveRecord::Encryption::Errors::Decryption, causing production 500s. - Fix: add
results[:sso_providers] = backfill_model(SsoProvider, %i[client_secret], batch_size, dry_run)to the task.client_secretis a plainstringcolumn, so the existingsafe_read_fieldraw-value fallback (no jsonb parsing needed) already handles it.
Fixes the crash reported in Sentry issue 7733832060.
Test plan
- Added a regression test (
test/lib/tasks/security_backfill_test.rb) that seeds a plaintextclient_secret, runs the task, and asserts the value round-trips through decryption and is stored as ciphertext. -
ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=test ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=test ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=test bin/rails test test/lib/tasks/security_backfill_test.rb— 3 runs, 0 failures.
🤖 Generated with Claude Code
Summary by CodeRabbit
-
Bug Fixes
- The security backfill now encrypts plaintext SSO provider client secrets while keeping them readable.
- Secrets that are already encrypted remain unchanged on subsequent backfill runs.
- Plaintext secrets are encrypted even when the system allows unencrypted data to be read.
- Existing batch processing and dry-run behavior remain supported.
-
Tests
- Added coverage for encrypting plaintext secrets, preserving existing ciphertext, and handling configurations that allow unencrypted data.