@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1@title Configuring Encryption
2@group config
3
4Setup guide for configuring encryption.
5
6Overview
7========
8
9Phorge supports at-rest encryption of uploaded file data stored in the
10"Files" application.
11
12Configuring at-rest file data encryption does not encrypt any other data or
13resources. In particular, it does not encrypt the database and does not encrypt
14Passphrase credentials.
15
16Attackers who compromise a Phorge host can read the master key and decrypt
17the data. In most configurations, this does not represent a significant
18barrier above and beyond accessing the file data. Thus, configuring at-rest
19encryption is primarily useful for two types of installs:
20
21 - If you maintain your own webserver and database hardware but want to use
22 Amazon S3 or a similar cloud provider as a blind storage server, file data
23 encryption can let you do so without needing to trust the cloud provider.
24 - If you face a regulatory or compliance need to encrypt data at rest but do
25 not need to actually secure this data, encrypting the data and placing the
26 master key in plaintext next to it may satisfy compliance requirements.
27
28The remainder of this document discusses how to configure at-rest encryption.
29
30
31Quick Start
32===========
33
34To configure encryption, you will generally follow these steps:
35
36 - Generate a master key with `bin/files generate-key`.
37 - Add the master key it to the `keyring`, but don't mark it as `default` yet.
38 - Use `bin/files encode ...` to test encrypting a few files.
39 - Mark the key as `default` to automatically encrypt new files.
40 - Use `bin/files encode --all ...` to encrypt any existing files.
41
42See the following sections for detailed guidance on these steps.
43
44
45Configuring a Keyring
46=====================
47
48To configure a keyring, set `keyring` with `bin/config` or by using another
49configuration source. This option should be a list of keys in this format:
50
51```lang=json
52...
53"keyring": [
54 {
55 "name": "master.key",
56 "type": "aes-256-cbc",
57 "material.base64": "UcHUJqq8MhZRwhvDV8sJwHj7bNJoM4tWfOIi..."
58 "default": true
59 },
60 ...
61]
62...
63```
64
65Each key should have these properties:
66
67 - `name`: //Required string.// A unique key name.
68 - `type`: //Required string.// Type of the key. Only `aes-256-cbc` is
69 supported.
70 - `material.base64`: //Required string.// The key material. See below for
71 details.
72 - `default`: //Optional bool.// Optionally, mark exactly one key as the
73 default key to enable encryption of newly uploaded file data.
74
75The key material is sensitive and an attacker who learns it can decrypt data
76from the storage engine.
77
78
79Format: Raw Data
80================
81
82The `raw` storage format is automatically selected for all newly uploaded
83file data if no key is marked as the `default` key in the keyring. This is
84the behavior of Phorge if you haven't configured anything.
85
86This format stores raw data without modification.
87
88
89Format: AES256
90==============
91
92The `aes-256-cbc` storage format is automatically selected for all newly
93uploaded file data if an AES256 key is marked as the `default` key in the
94keyring.
95
96This format uses AES256 in CBC mode. Each block of file data is encrypted with
97a unique, randomly generated private key. That key is then encrypted with the
98master key. Among other motivations, this strategy allows the master key to be
99cycled relatively cheaply later (see "Cycling Master Keys" below).
100
101AES256 keys should be randomly generated and 256 bits (32 characters) in
102length, then base64 encoded when represented in `keyring`.
103
104You can generate a valid, properly encoded AES256 master key with this command:
105
106```
107phorge/ $ ./bin/files generate-key --type aes-256-cbc
108```
109
110This mode is generally similar to the default server-side encryption mode
111supported by Amazon S3.
112
113
114Format: ROT13
115=============
116
117The `rot13` format is a test format that is never selected by default. You can
118select this format explicitly with `bin/files encode` to test storage and
119encryption behavior.
120
121This format applies ROT13 encoding to file data.
122
123
124Changing File Storage Formats
125=============================
126
127To test configuration, you can explicitly change the storage format of a file.
128
129This will read the file data, decrypt it if necessary, write a new copy of the
130data with the desired encryption, then update the file to point at the new
131data. You can use this to make sure encryption works before turning it on by
132default.
133
134To change the format of an individual file, run this command:
135
136```
137phorge/ $ ./bin/files encode --as <format> F123 [--key <key>]
138```
139
140This will change the storage format of the specified file.
141
142
143Verifying Storage Formats
144=========================
145
146You can review the storage format of a file from the web UI, in the
147{nav Storage} tab under "Format". You can also use the "Engine" and "Handle"
148properties to identify where the underlying data is stored and verify that
149it is encrypted or encoded in the way you expect.
150
151See @{article:Configuring File Storage} for more information on storage
152engines.
153
154
155Cycling Master Keys
156===================
157
158If you need to cycle your master key, some storage formats support key cycling.
159
160Cycling a file's encryption key decodes the local key for the data using the
161old master key, then re-encodes it using the new master key. This is primarily
162useful if you believe your master key may have been compromised.
163
164First, add a new key to the keyring and mark it as the default key. You need
165to leave the old key in place for now so existing data can be decrypted.
166
167To cycle an individual file, run this command:
168
169```
170phorge/ $ ./bin/files cycle F123
171```
172
173Verify that cycling worked properly by examining the command output and
174accessing the file to check that the data is present and decryptable. You
175can cycle additional files to gain additional confidence.
176
177You can cycle all files with this command:
178
179```
180phorge/ $ ./bin/files cycle --all
181```
182
183Once all files have been cycled, remove the old master key from the keyring.
184
185Not all storage formats support key cycling: cycling a file only has an effect
186if the storage format is an encrypted format. For example, cycling a file that
187uses the `raw` storage format has no effect.
188
189
190Next Steps
191==========
192
193Continue by:
194
195 - understanding storage engines with @{article:Configuring File Storage}; or
196 - returning to the @{article:Configuration Guide}.