Update clients to interact with (new) server encrypted databases#2113
Merged
penberg merged 5 commits intotursodatabase:mainfrom Jul 4, 2025
Merged
Update clients to interact with (new) server encrypted databases#2113penberg merged 5 commits intotursodatabase:mainfrom
penberg merged 5 commits intotursodatabase:mainfrom
Conversation
1271b0c to
3d73ecf
Compare
1d319a3 to
e6a1bdc
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR enables clients to provide an optional encryption context so that the x-turso-encryption-key header is sent on all sync/remote database requests.
- Introduce
EncryptionContextandEncryptionKeytypes and export them in the public API - Extend
SyncContext, HTTP sender, and builders to accept and propagate the encryption context - Update tests and examples to pass the new
remote_encryptionparameter
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| libsql/src/sync/test.rs | Updated test calls to include the new remote_encryption parameter |
| libsql/src/sync.rs | Added remote_encryption field and header injection in sync logic |
| libsql/src/local/database.rs | Propagate remote_encryption when constructing SyncContext |
| libsql/src/lib.rs | Export EncryptionContext and EncryptionKey types |
| libsql/src/hrana/hyper.rs | Add remote_encryption to HTTP sender and include header in requests |
| libsql/src/database/builder.rs | Set default remote_encryption and add builders for encryption |
| libsql/src/database.rs | Define EncryptionKey/EncryptionContext and update DB variants |
| libsql/examples/encryption_sync.rs | New example demonstrating encrypted sync usage |
| libsql/Cargo.toml | Added base64 dependency for encryption encoding |
Comments suppressed due to low confidence (2)
libsql/src/database/builder.rs:309
- [nitpick] The
remote_encryptionsetter onBuilder<RemoteReplica>takesEncryptionContextwhere other builders acceptOption<EncryptionContext>. Consider unifying these signatures for consistency across builder APIs.
pub fn remote_encryption(mut self, encryption_context: EncryptionContext) -> Builder<RemoteReplica> {
libsql/src/lib.rs:135
EncryptionContextandEncryptionKeyare only exported under thesyncfeature, but they’re also needed for remote-only scenarios. Consider exporting them underremote(and/orreplication) features so they’re available whensyncis disabled.
pub use database::EncryptionContext;
Comment on lines
+310
to
315
| if let Some(remote_encryption) = &self.remote_encryption { | ||
| req = req.header("x-turso-encryption-key", remote_encryption.key.as_string()); | ||
| } | ||
|
|
||
| let req = req.body(body.clone().into()).expect("valid body"); | ||
|
|
There was a problem hiding this comment.
[nitpick] The code for adding the x-turso-encryption-key header is duplicated across multiple methods in SyncContext. Consider extracting this into a helper method to reduce duplication and improve maintainability.
Suggested change
| if let Some(remote_encryption) = &self.remote_encryption { | |
| req = req.header("x-turso-encryption-key", remote_encryption.key.as_string()); | |
| } | |
| let req = req.body(body.clone().into()).expect("valid body"); | |
| self.add_encryption_header(&mut req); |
e6a1bdc to
3c42428
Compare
Closed
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.
This patch enables client to send encryption key header for encrypted databases. The header we are required to send is
x-turso-encryption-key.To connect with encrypted database, either remote or offline write, you may use the builder pattern to provide the encryption context. Ex.:
This patch also comes with a full example: https://github.com/avinassh/libsql/blob/5b95a1928b821855fced3880caf7871ce032c58b/libsql/examples/encryption_sync.rs