Background: I'm investigating methods for encrypted storage on untrusted machines. My current setup uses sshfs to access a LUKS-encrypted image on the remote machine, which is decrypted locally and mounted as ext3. (If I were to use sshfs only, someone gaining access to the remote machine could see my data.) Here's my example setup:
# On the local machine: sshfs remote:/home/crypt /home/crypt cryptsetup luksOpen /home/crypt/container.img container mount /dev/mapper/container /home/crypt-open # Place cleartext files in /home/crypt-open, # then reverse the above steps to unmount.
I want to make this resilient against network failures. To do this, I'd like to understand what caching / buffering happens with this setup. Consider these two commands:
dd if=/dev/random of=/home/crypt-open/test.dat bs=1000000 count=100 dd if=/dev/random of=/home/crypt-open/test.dat bs=1000000 count=100 conv=fsync
The first command returns very quickly, and I can see from the network traffic that the data is still being transmitted after the command has returned. The second command seems to wait until the data is finished transferring.
Concrete questions: What guarantees does
fsync() make under this setup? When
fsync() returns, how far along these layers is the data guaranteed to be synced? And what can I do to guarantee that it gets synced all the way down to the remote machine's hard drive?
--- /home/crypt-open on the local machine | | (ext3 fs) | --- /dev/mapper/container on the local machine | | (LUKS) | --- /home/crypt/container.img on the local machine | | (sshfs) | --- /home/crypt/container.img on the remote machine | | (ext3 fs) | --- hard drive on the remote machine