11CephFS Fscrypt
2- ================
2+ ==============
33
44Fscrypt is an encryption implementation at the file system level. This file
55system encryption allows for encrypting on a per directory level. This allows
@@ -11,7 +11,7 @@ implementation. If you would like to see the full kernel specification
1111please visit: https://docs.kernel.org/filesystems/fscrypt.html
1212
1313Key Derivation Process
14- -------------------------
14+ ----------------------
1515The master key is the cornerstone to derive all keys within an fscrypt context.
1616
1717When an fscrypt policy is applied to an empty directory, a per-directory key
@@ -27,7 +27,7 @@ the size of 4K each. These block will each be encrypted a on a per-block
2727basis that is derived from the per-file key.
2828
2929Generating filenames
30- -------------------
30+ --------------------
3131When a new inode is created, the name provided is encrypted using the
3232per-directory key. The plaintext file name will be encrypted. This cipher
3333text is then converted to a base64 format. This is to ensure that there are no
@@ -38,7 +38,7 @@ the ``alternate_name`` field. This cipher text will then be truncated to a small
3838size to be base64 encoded and stored in the dname.
3939
4040Per-block encryption keys
41- -------------------
41+ -------------------------
4242When data blocks are written to a file each block will be written in fscrypt
4343block sized chunks (4096 bytes) with a unique key. Each per-block key will be
4444derived from the per-file key+block_num. This means that each encrypted block
@@ -65,8 +65,9 @@ in Figure 1, then a rmw workload is needed. First the block is read, then
6565decrypted based on the key+blocknum, then new data is merged with the plaintext
6666version and then encrypted before being written out to the osds.
6767
68- .. image :: cephfs_fscrypt_rmw_partially_aligned.svg
69- Figure 1
68+ .. figure :: cephfs_fscrypt_rmw_partially_aligned.svg
69+
70+ Figure 1
7071
7172To determine if a rmw is needed the offset and len of write is analyzed.
7273
@@ -81,22 +82,24 @@ To determine if a rmw is needed the offset and len of write is analyzed.
8182 be performed and any previous data read will not be needed. This behavior is
8283 shown in Figure 2. In this case, only blocks 3 and 5 will need to be read.
8384
84- .. image :: cephfs_fscrypt_rmw_3blocks.svg
85- Figure 2
85+ .. figure :: cephfs_fscrypt_rmw_3blocks.svg
86+
87+ Figure 2
8688
8789Space Amplification
88- ---------------------
90+ -------------------
8991In nearly all cases, using encryption will cause space amplification. Any data
9092sets that aren’t uniformly aligned to fscrypt block boundaries will have this.
9193The ``max_size `` quota is based off this amplified real size.
9294
9395Truncates
94- -------------------------
96+ ---------
9597In cases where a truncate call is not fscrypt block aligned, it will require
9698rmw on the end block. Since a truncate call is handled by the mds, this rmw
9799operation is partially handled by the mds. First, the client reads the last block.
98100Then, as shown in Figure 3, the client requests a truncate (1), mds then does the
99101write directly to the osds(2,3) before returning status back to the client(4).
100102
101- .. image :: cephfs_fscrypt_truncate_handshake.svg
102- Figure 3
103+ .. figure :: cephfs_fscrypt_truncate_handshake.svg
104+
105+ Figure 3
0 commit comments