Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazily evaluate regional encryptor KMS ciphertext #11876

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aduth
Copy link
Contributor

@aduth aduth commented Feb 13, 2025

🛠 Summary of changes

Updates encryptor classes to lazily evaluate regional KMS ciphertexts.

Since #9047, we've added support for multi-region KMS encryption, with fallback to single-region encryption in a few specific cases where multi-region is not possible (e.g. legacy personal keys). The fallback is such that we only ever use one of the two ciphertexts, but prior to the changes proposed here, we would always eagerly evaluate the ciphertext for both single-region and multi-region.

With these changes, we defer the KMS encryption until after we've evaluated which regional digest to work with, so that only a single KMS encryption occurs.

📜 Testing Plan

TBD

changelog: Internal, Performance, Lazily evaluate regional encryptor ciphertext
Copy link
Contributor

@mitchellhenke mitchellhenke left a comment

Choose a reason for hiding this comment

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

Took a bit for me to digest this, but I think I'm following it.

Previously, we'd:

  1. Have some text we need to encrypt with KMS (either a password or PII blob)
  2. We'd encrypt the text with both the single region KMS key and multi region KMS key
  3. Save the multi-region key encrypted text to the database

These changes pull up the processing of the text so that we don't encrypt with both keys, which makes sense. I'm aware that there are elements that need to be decrypted with the single-region key, but it's not clear if there are any cases we're encrypting with the single-region key. Should we be instantiating the objects with the single-region key unless we're decrypting?

Comment on lines +34 to +37
def encrypted_data
self[:encrypted_data] ||
kms_client.encrypt(aes_encrypted_ciphertext, user_kms_encryption_context)
end
Copy link
Contributor

@mitchellhenke mitchellhenke Feb 14, 2025

Choose a reason for hiding this comment

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

This and encrypted_password give me some pause. It doesn't feel super clear that calling it will potentially take the action of encrypting. I'm not really sure what approach would be preferable. I'm not sure if separating it (e.g. something like encrypt_data!) so that the setting and getting are separate would be better?

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.

2 participants