benbjohnson / litestream

Streaming replication for SQLite.
https://litestream.io
Apache License 2.0
10.36k stars 232 forks source link

Encryption #88

Closed benbjohnson closed 1 year ago

benbjohnson commented 3 years ago

Currently, Litestream sends cleartext bytes to a replica such as S3. This works well enough for many use cases as S3 buckets are generally secured through IAM. However, other use cases require additional security measures to prevent attackers from obtaining raw data if a bucket is compromised.

Litestream could implement either encryption to prevent data theft and/or signatures to prevent data alteration.

oliverpool commented 3 years ago

Does this need to be implemented inside litestream, or could it be supported by an external "encryption proxy"? (like https://github.com/abustany/s3proxy - does not seem to be maintained anymore, but the idea seems nice)

benbjohnson commented 3 years ago

For basic replication, you could use a proxy and that'd probably work pretty well.

However, I'm planning on adding hot backups soon so you can have an external server that always has a live copy of your database ready to go instead of having to perform a full snapshot/replay to restore. For that use case, encryption would need to be in Litestream as it needs to encrypt the WAL page data but not the WAL headers. The nice thing about that setup is you could stream your data to an untrusted third-party service and still have everything encrypted.

hifi commented 1 year ago

We added age encryption support downstream for data storage at rest that fully supports normal replication and restore. A replicating Litestream only needs the public keys (recipients) for encryption. The age CLI tool can also be used to manually decrypt snapshots (and WALs) on a pinch.

I'm more than happy to upstream it as it is fairly trivial but it's based on v0.3.9. We've had it running for a while now without any issues replicating or restoring databases.

https://github.com/beeper/litestream/commit/ac9ad40d7154a6d282efc5ca8f26788daa871434

I suppose the hot backup feature was scrapped with LiteFS?

cal97g commented 1 year ago

Hey @hifi could you please push this code somewhere, would be super useful!

hifi commented 1 year ago

@cal97g I linked it in the previous comment.