Skip to content

fix: harden database encryption with AES/GCM and key rotation - #441

Open
santhoshalpha wants to merge 1 commit into
reshaprio:mainfrom
santhoshalpha:feature/427-aes-gcm-encryption
Open

santhoshalpha wants to merge 1 commit into
reshaprio:mainfrom
santhoshalpha:feature/427-aes-gcm-encryption

Conversation

@santhoshalpha

Copy link
Copy Markdown

Replace AES/ECB/PKCS5Padding with AES/GCM/NoPadding (AEAD: confidentiality + integrity, random IV per value). Ciphertext is now self-describing as ":<base64(iv||ct||tag)>", so multiple keys can coexist and be rotated by adding a new key id and switching the active key, without a big-bang re-encryption. Values encrypted by the previous AES/ECB scheme keep decrypting via a configured legacy key for backward compatibility.

Closes #427

Replace AES/ECB/PKCS5Padding with AES/GCM/NoPadding (AEAD: confidentiality
+ integrity, random IV per value). Ciphertext is now self-describing as
"<kid>:<base64(iv||ct||tag)>", so multiple keys can coexist and be rotated
by adding a new key id and switching the active key, without a big-bang
re-encryption. Values encrypted by the previous AES/ECB scheme keep
decrypting via a configured legacy key for backward compatibility.

Closes reshaprio#427

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CZykTGjxi8FEzPNyw9pd3k
Signed-off-by: santhoshalpha <santhoshpkraja2004@gmail.com>
@santhoshalpha
santhoshalpha force-pushed the feature/427-aes-gcm-encryption branch from bb88185 to 061e2bf Compare September 14, 2026 15:37
@santhoshalpha

Copy link
Copy Markdown
Author

@lbroudoux Heads up — the design comment on #427 was accidentally posted from my work GitHub account (raja-pyt) instead of this one. This PR is the correct account (santhoshalpha) going forward. Apologies for the confusion!

@lbroudoux lbroudoux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for pushing this! It looks great. These are the foundations of the changes. We'll need to complete it with a KeyRotationService and an admin-only API KeyRotationResource that allows launching the re-encryption (from legacy) and the rotation of keys (when moving from v1 and v2).

Please check my comments and apply changes if you can. Otherwise, I'll probably merge this as is and apply the refactoring on tomorrow.

Cheers,

Comment on lines +66 to +68
@ConfigProperty(name = "reshapr.encryption.keys") Map<String, String> encryptionKeys,
@ConfigProperty(name = "reshapr.encryption.active-key-id") String activeKeyId,
@ConfigProperty(name = "reshapr.encryption.legacy-key") Optional<String> legacyKey) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would have created a dedicated EncryptionConfig interface for this, wrapping the 3 properties, in the io.reshapr.ctrl.config package.

encryptionKeyBytes = encryptionKey.getBytes();
if (encryptionKeyBytes == null || !isKeySizeValid(encryptionKeyBytes.length)) {
throw new IllegalArgumentException("Encryption key must 16, 24 or 32 characters long");
if (encryptionKeys == null || encryptionKeys.isEmpty()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Keeping the @PostConstruct initialize() method is usually more readable because it dissociates retrieving configuration properties from validating them. I think it makes things easier to troubleshoot later on.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Harden database encryption: replace AES/ECB and enable key rotation

2 participants