Skip to content

Commit 884686d

Browse files
authored
Docs: update encryptions.md (#6343)
1 parent b023378 commit 884686d

File tree

2 files changed

+224
-58
lines changed

2 files changed

+224
-58
lines changed

docs/en/security/encryption.md

Lines changed: 117 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,33 @@ juicefs format --storage s3 \
3838

3939
## Data Encryption At Rest {#at-rest}
4040

41-
JuiceFS supports Data Encryption At Rest. All data will be encrypted first before being uploaded to object storage. This allows JuiceFS to effectively prevent data leakage.
41+
JuiceFS provides Data Encryption At Rest support, which encrypts first, then uploads. All files stored in JuiceFS will be encrypted locally and then uploaded to object storage, effectively preventing data leakage when the object storage itself is compromised.
4242

43-
Data Encryption At Rest of JuiceFS adopts industry-standard encryption methods (AES-GCM and RSA). User only needs to provide a private key with a password while creating the file system, and the private key can be provided by setting the environment variable `JFS_RSA_PASSPHRASE`. For use, mount point is totally transparent to the client, i.e., access to file system will not be affected by encryption and decryption processes.
43+
JuiceFS Data Encryption At Rest adopts a hybrid encryption architecture: symmetric encryption handles data encryption, while asymmetric encryption (RSA) handles key protection. You only need to provide an RSA private key when creating the file system to enable data encryption functionality, and provide the private key password through the `JFS_RSA_PASSPHRASE` environment variable. In usage, the mount point is completely transparent to applications, meaning the encryption and decryption processes will not affect file system access.
4444

4545
:::caution
4646
The cached data on the client-side is **NOT** encrypted. Only the root user or owner can access this data. To encrypt the cached data, you can put the cached directory in an encrypted file system or block storage.
4747
:::
4848

49-
### Encryption algorithm
49+
### Encryption Principles
5050

51-
Data Encryption At Rest of JuiceFS combines symmetric encryption and asymmetric encryption, which requires user to create a global RSA private key `M` for the file system. Each object stored in the object storage will have its own random symmetric key `S`. The stored data is encrypted using AES-GCM algorithm with the symmetric key `S`, while `S` is encrypted with the global RSA private key `M`. At last, the RSA key is encrypted using a user-specified passphrase.
51+
#### Encryption Architecture Design
52+
53+
JuiceFS adopts a **hybrid encryption architecture** with two encryption layers:
54+
55+
1. **Data Encryption Layer** (Symmetric Encryption - AES-256-GCM or ChaCha20-Poly1305)
56+
- **Purpose**: Actually encrypts user data content
57+
- **Mechanism**: Each block generates a unique symmetric key `S` + random seed `N` (both use 256-bit keys)
58+
- **Advantage**: Both AES-256-GCM and ChaCha20-Poly1305 provide high-speed encryption and integrity verification (AEAD)
59+
- **Standard**: 256-bit key strength complies with NIST security standards, ChaCha20-Poly1305 is an RFC 8439 standard algorithm
60+
61+
2. **Key Protection Layer** (Asymmetric Encryption - RSA)
62+
- **Purpose**: Protects the secure distribution and storage of symmetric keys
63+
- **Mechanism**: Uses RSA private key `M` to encrypt each data block's symmetric key `S`
64+
- **Advantage**: Solves key distribution challenges and avoids key reuse risks
65+
- **Scheme**: Supports RSA-2048 or RSA-4096 keys, using OAEP padding to enhance security
66+
67+
Users need to create a global RSA private key `M` for the file system in advance. Each object stored in the object storage will have its own random symmetric key `S`.
5268

5369
Symbol explanation:
5470

@@ -59,20 +75,20 @@ Symbol explanation:
5975

6076
![Encryption At-rest](../images/encryption.png)
6177

62-
The detailed process of data encryption is as follows:
78+
#### Data Encryption Process
6379

64-
- Before writing to an object storage, data blocks are compressed using LZ4 or Zstandard.
80+
- Before writing to object storage, data blocks are compressed using LZ4 or Zstandard.
6581
- A random 256-bit symmetric key `S` and a random seed `N` are generated for each data block.
66-
- Each data block is encrypted into `encrypted_data` using AES-GCM algorithm with key `S` and seed `N`.
67-
- To avoid the symmetric key `S` from being transmitted in clear text over the network, the symmetric key `S` is encrypted into the cipher text `K` with the RSA key `M`.
82+
- Each data block is encrypted into `encrypted_data` using AES-256-GCM or ChaCha20-Poly1305 algorithm with key `S` and seed `N`.
83+
- To avoid the symmetric key `S` from being transmitted in clear text over the network, the symmetric key `S` is encrypted into the cipher text `K` with the RSA private key `M`.
6884
- The encrypted data `encrypted_data`, the ciphertext `K`, and the random seed `N` are combined into an object and then written to the object storage.
6985

70-
The steps for decrypting the data are as follows:
86+
#### Data Decryption Process
7187

7288
- Read the entire encrypted object (it may be a bit larger than 4MB).
7389
- Parse the object data to get the ciphertext `K`, the random seed `N`, and the encrypted data `encrypted_data`.
74-
- Decrypt `K` with RSA key to get symmetric key `S`.
75-
- Decrypt the data `encrypted_data` based on AES-GCM using `S` and `N` to get the data block plaintext.
90+
- Decrypt `K` with RSA private key to get symmetric key `S`.
91+
- Decrypt the data `encrypted_data` based on AES-256-GCM or ChaCha20-Poly1305 using `S` and `N` to get the data block plaintext.
7692
- Decompress the data block.
7793

7894
### Enable Data Encryption At Rest
@@ -81,45 +97,77 @@ The steps for decrypting the data are as follows:
8197
Data Encryption At Rest must be enabled when creating file system. The file system that was created without Data Encryption At Rest enabled cannot enable it later.
8298
:::
8399

84-
There are following steps to enable Data Encryption At Rest:
100+
The steps to enable Data Encryption At Rest are:
85101

86102
1. Create a RSA private key
87-
2. Run the encrypted file system that is created by the RSA private key
103+
2. Create an encrypted file system using the RSA private key
88104
3. Mount the file system
89105

90-
#### Step 1: create a RSA private key
106+
#### Step 1: Create a RSA private key
91107

92-
The RSA private key, usually manually generated by OpenSSL, plays a critical role in Data Encryption At Rest. The following command generates a 2048-bit RSA private key with a file name of `my-priv-key.pem` in the current directory using aes256 algorithm.
108+
The RSA private key is crucial for Data Encryption At Rest and is generally manually generated using OpenSSL. The following command will generate a 2048-bit RSA private key named `my-priv-key.pem` in the current directory using the aes256 algorithm:
93109

94110
```shell
95111
openssl genrsa -out my-priv-key.pem -aes256 2048
96112
```
97113

98-
Since the aes256 algorithm is in use, you will be prompted to enter a passphrase (at least 4 bits) to protect your private key. The passphrase can be considered as a password for encrypting the file of the RSA private key, which is also the last layer of security assurance for the RSA private key.
114+
Since the `aes256` encryption algorithm is used, the command line will require you to provide a `Passphrase` of at least 4 characters for this private key. You can simply think of it as a password used to encrypt the RSA private key file itself, which is also the last security safeguard for the RSA private key file.
99115

100-
:::caution
101-
The security of RSA private key is crucial when Data Encryption At Rest encryption is enabled. The leak of the key will put the data into a serious security risk. If the key is lost, **all the encrypted data will be lost and cannot be recovered**!
116+
:::caution Special Attention
117+
The security of the RSA private key is extremely important, and special attention needs to be paid to the following points:
118+
119+
- **Passphrase Leakage Risk**: If the private key's passphrase is leaked, attackers may decrypt the private key stored in the metadata engine, thereby jeopardizing the security of all encrypted data
120+
- **Private Key File Leakage**: If the encrypted private key file itself is leaked along with the passphrase, it will lead to serious security risks
121+
- **Data Irrecoverability**: If the correct passphrase cannot be provided to access the private key stored in the metadata engine, **all encrypted data will be permanently lost and unrecoverable**
122+
123+
It is recommended to focus on protecting the security of the passphrase and pass it through environment variables to avoid leakage in command line history.
102124
:::
103125

104-
#### Step 2: create an encrypted file system
126+
#### Step 2: Create an encrypted file system
127+
128+
Creating an encrypted file system requires using the `--encrypt-rsa-key` option to specify the RSA private key. The provided private key content will be written to the metadata engine. You need to use the environment variable `JFS_RSA_PASSPHRASE` to specify the private key's passphrase.
129+
130+
JuiceFS supports two encryption algorithm combinations, which can be specified via the `--encrypt-algo` option:
105131

106-
The option `--encrypt-rsa-key` is required to specify RSA private key when creating an encrypted file system. The provided private key content will be written to the metadata engine. Since passphrase is mandatory in the ase256-encrypted RSA private key, the environment variable `JFS_RSA_PASSPHRASE` is required to specify the passphrase of the private key before creating and mounting file system.
132+
- `aes256gcm-rsa` (default): Uses AES-256-GCM + RSA
133+
- `chacha20-rsa`: Uses ChaCha20-Poly1305 + RSA
107134

108135
1. Set passphrase using environment variable
109136

110137
```shell
111138
export JFS_RSA_PASSPHRASE=the-passwd-for-rsa
112139
```
113140

114-
2. Create file system
141+
2. Create file system (using default AES-256-GCM encryption)
115142

116-
```shell
143+
```shell {2}
117144
juicefs format --storage s3 \
118-
--encrypt-rsa-key my-priv-key.pem \
119-
...
145+
--encrypt-rsa-key my-priv-key.pem \
146+
...
120147
```
121148

122-
#### Step 3: mount file system
149+
Or explicitly specify ChaCha20-Poly1305 encryption:
150+
151+
```shell {2,3}
152+
juicefs format --storage s3 \
153+
--encrypt-rsa-key my-priv-key.pem \
154+
--encrypt-algo chacha20-rsa \
155+
...
156+
```
157+
158+
3. (Optional) Delete local RSA private key file
159+
160+
JuiceFS securely stores the RSA private key content in the metadata engine during file system formatting. Therefore, after completing file system creation (unless there are specific compliance requirements), we recommend deleting your local RSA private key file:
161+
162+
```shell
163+
rm my-priv-key.pem
164+
```
165+
166+
This way, you only need to ensure the security of the `JFS_RSA_PASSPHRASE` environment variable, and subsequent file system mounting and access only require providing the correct passphrase.
167+
168+
If you need to retain the RSA private key file due to compliance requirements or other reasons, please ensure the private key file is stored in a secure location with strict access permissions, and keep the private key file and passphrase separately.
169+
170+
#### Step 3: Mount file system
123171

124172
There is no need to specify extra options while mounting an encrypted file system. However, the passphrase of the private key needs to be set before mounting using environment variable.
125173

@@ -135,32 +183,57 @@ There is no need to specify extra options while mounting an encrypted file syste
135183
juicefs mount redis://127.0.0.1:6379/1 /mnt/myjfs
136184
```
137185

138-
When creating a new volume using `juicefs format`, static encryption can be enabled by specifying the RSA private key with the `-encrypt-rsa-key` parameter, which will be saved on the Metadata service. When the private key is password-protected, the password must be specified using the environment variable `JFS_RSA_PASSPHRASE`.
186+
### Performance Considerations
139187

140-
Usage:
188+
Enabling encryption does introduce some performance overhead, but modern hardware technologies have made this impact quite manageable. The specific performance impact depends on workload type, hardware configuration (particularly CPU encryption instruction set support), and data access patterns.
141189

142-
1. Generate RSA key
190+
Modern CPUs have specialized hardware optimizations for TLS, HTTPS, and AES-256 encryption technologies. In particular, modern Intel and AMD processors include AES-NI instruction sets that can perform AES encryption operations at near-native speeds, significantly reducing the performance impact of data encryption.
143191

144-
```shell
145-
openssl genrsa -out my-priv-key.pem -aes256 2048
146-
```
192+
#### Encryption Algorithm Selection Recommendations
147193

148-
or
194+
**AES-256-GCM** (default choice):
149195

150-
```shell
151-
openssl genpkey -algorithm RSA -out my-priv-key.pem -pkeyopt rsa_keygen_bits:2048 -aes-256-cbc
152-
```
196+
- Excellent performance on modern CPUs with AES-NI instruction set support
197+
- Widely supported and validated industry standard
198+
- Suitable for most production environments
153199

154-
2. Provide the key when formatting
200+
**ChaCha20-Poly1305**:
155201

156-
```shell
157-
juicefs format --encrypt-rsa-key my-priv-key.pem META-URL NAME
158-
```
202+
- May provide better performance on CPUs without AES-NI support
203+
- Suitable for ARM architectures or older x86 processors
204+
- Better resistance against timing attacks
205+
- Preferred algorithm by companies like Google for mobile devices and certain server environments
206+
207+
When selecting encryption keys, we recommend using RSA-2048 keys, which provide a good balance between security strength and performance. RSA-4096 provides higher security, but its decryption operations are slower and may impact performance in high-concurrency read scenarios.
208+
209+
It's worth mentioning that encrypted data will be slightly larger than the original data, primarily because both AES-256-GCM and ChaCha20-Poly1305 encryption algorithms require adding authentication tags (16 bytes) and other encryption metadata.
210+
211+
### Security Best Practices
212+
213+
The security of an encryption scheme depends not only on the algorithms themselves but also on how encryption keys are properly managed and used. Here are some important security practice recommendations:
214+
215+
**Key management is at the core of security**. The passphrase you set for your RSA private key should be strong enough—we recommend using at least 16 characters with a combination of uppercase and lowercase letters, numbers, and special symbols. We recommend passing the passphrase through environment variables to avoid leakage in command line history.
216+
217+
While regularly rotating keys is a good practice, it's important to note that changing RSA keys requires reformatting the entire file system. Therefore, when planning key rotation strategies, you need to balance security requirements with business continuity.
218+
219+
**Access control is equally important**. Ensure your metadata engine (whether Redis, MySQL, or another database) is configured with appropriate authentication and authorization mechanisms. Object storage access permissions should also follow the principle of least privilege, granting only necessary operational permissions.
220+
221+
At the network level, try to use VPC or private networks to isolate communication traffic between the metadata engine and object storage, reducing the risk of man-in-the-middle attacks.
222+
223+
**Monitoring and auditing** can help you detect abnormal situations promptly. We recommend logging all encryption-related operations, regularly checking key usage patterns, and establishing abnormal access detection mechanisms. This way, even if a security incident occurs, you can respond quickly and take appropriate measures.
224+
225+
### Important Considerations
226+
227+
When using JuiceFS encryption features, there are several important technical limitations to be aware of:
228+
229+
First, client-side local cached data is **NOT encrypted**. Although only root users or file owners can access this cached data, if your use case requires end-to-end full encryption, you'll need to consider additional protection measures, such as placing the cache directory on an encrypted file system or block storage.
230+
231+
Secondly, encryption functionality has some inherent limitations. File metadata (such as filenames, sizes, permissions, etc.) is not encrypted, and decrypted data exists in plaintext in memory. Most importantly, once encryption is enabled for a file system, it cannot be turned off—encryption is an irreversible operation.
232+
233+
In deployment planning, please consider that encryption brings additional CPU and memory overhead. To ensure optimal compatibility and stability, we recommend that all clients accessing encrypted file systems use the same or compatible versions of JuiceFS.
159234
160-
:::note
161-
If the private key is password-protected, an environment variable `JFS_RSA_PASSPHRASE` should be exported first before executing `juicefs mount`.
162-
:::
235+
### Usage Scenario Analysis
163236
164-
### Performance
237+
JuiceFS encryption features are particularly suitable for these scenarios: protecting sensitive data in cloud object storage, meeting compliance requirements such as GDPR and HIPAA, long-term secure storage of important business data, and achieving data isolation in multi-tenant environments.
165238
166-
TLS, HTTPS, and AES-256 are implemented very efficiently in modern CPUs. Therefore, enabling encryption does not have a significant impact on file system performance. Because of the relatively low performance of RSA algorithm, it is recommended to use 2048-bit RSA keys for storage encryption, and using 4096-bit keys may have a significant impact on reading performance.
239+
However, if you need client-side local cache encryption, or want to add encryption functionality to existing file systems later, this solution may not be suitable. Similarly, for applications with extremely demanding performance requirements, or scenarios that require frequent key rotation but cannot accept reformatting, careful consideration is needed.

0 commit comments

Comments
 (0)