]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - docs/architecture.txt
3d4d90c017727e66349b0884fdbb313f13fcf6f2
[tahoe-lafs/tahoe-lafs.git] / docs / architecture.txt
1
2    Tahoe-LAFS Architecture
3
4 (See the docs/specifications directory for more details.)
5
6 OVERVIEW
7
8 There are three layers: the key-value store, the filesystem, and the
9 application.
10
11 The lowest layer is the key-value store. The keys are "capabilities" -- short
12 ascii strings -- and the values are sequences of data bytes. This data is
13 encrypted and distributed across a number of nodes, such that it will survive
14 the loss of most of the nodes. There are no hard limits on the size of the
15 values, but there may be performance issues with extremely large values (just
16 due to the limitation of network bandwidth). In practice, values as small as
17 a few bytes and as large as tens of gigabytes are in common use.
18
19 The middle layer is the decentralized filesystem: a directed graph in which
20 the intermediate nodes are directories and the leaf nodes are files. The leaf
21 nodes contain only the data -- they contain no metadata other than the length
22 in bytes. The edges leading to leaf nodes have metadata attached to them
23 about the file they point to. Therefore, the same file may be associated with
24 different metadata if it is referred to through different edges.
25
26 The top layer consists of the applications using the filesystem.
27 Allmydata.com uses it for a backup service: the application periodically
28 copies files from the local disk onto the decentralized filesystem. We later
29 provide read-only access to those files, allowing users to recover them.
30 There are several other applications built on top of the Tahoe-LAFS
31 filesystem (see the RelatedProjects page of the wiki for a list).
32
33
34 THE KEY-VALUE STORE
35
36 The key-value store is implemented by a grid of Tahoe-LAFS storage servers --
37 user-space processes. Tahoe-LAFS storage clients communicate with the storage
38 servers over TCP.
39
40 Storage servers hold data in the form of "shares". Shares are encoded pieces
41 of files. There are a configurable number of shares for each file, 10 by
42 default. Normally, each share is stored on a separate server, but in some
43 cases a single server can hold multiple shares of a file.
44
45 Nodes learn about each other through an "introducer". Each server connects to
46 the introducer at startup and announces its presence. Each client connects to
47 the introducer at startup, and receives a list of all servers from it. Each
48 client then connects to every server, creating a "bi-clique" topology. In the
49 current release, nodes behind NAT boxes will connect to all nodes that they
50 can open connections to, but they cannot open connections to other nodes
51 behind NAT boxes. Therefore, the more nodes behind NAT boxes, the less the
52 topology resembles the intended bi-clique topology.
53
54 The introducer is a Single Point of Failure ("SPoF"), in that clients who
55 never connect to the introducer will be unable to connect to any storage
56 servers, but once a client has been introduced to everybody, it does not need
57 the introducer again until it is restarted. The danger of a SPoF is further
58 reduced in two ways. First, the introducer is defined by a hostname and a
59 private key, which are easy to move to a new host in case the original one
60 suffers an unrecoverable hardware problem. Second, even if the private key is
61 lost, clients can be reconfigured to use a new introducer.
62
63 For future releases, we have plans to decentralize introduction, allowing any
64 server to tell a new client about all the others.
65
66
67 FILE ENCODING
68
69 When a client stores a file on the grid, it first encrypts the file. It then
70 breaks the encrypted file into small segments, in order to reduce the memory
71 footprint, and to decrease the lag between initiating a download and
72 receiving the first part of the file; for example the lag between hitting
73 "play" and a movie actually starting.
74
75 The client then erasure-codes each segment, producing blocks of which only a
76 subset are needed to reconstruct the segment (3 out of 10, with the default
77 settings).
78
79 It sends one block from each segment to a given server. The set of blocks on
80 a given server constitutes a "share". Therefore a subset f the shares (3 out
81 of 10, by default) are needed to reconstruct the file.
82
83 A hash of the encryption key is used to form the "storage index", which is
84 used for both server selection (described below) and to index shares within
85 the Storage Servers on the selected nodes.
86
87 The client computes secure hashes of the ciphertext and of the shares. It
88 uses Merkle Trees so that it is possible to verify the correctness of a
89 subset of the data without requiring all of the data. For example, this
90 allows you to verify the correctness of the first segment of a movie file and
91 then begin playing the movie file in your movie viewer before the entire
92 movie file has been downloaded.
93
94 These hashes are stored in a small datastructure named the Capability
95 Extension Block which is stored on the storage servers alongside each share.
96
97 The capability contains the encryption key, the hash of the Capability
98 Extension Block, and any encoding parameters necessary to perform the
99 eventual decoding process. For convenience, it also contains the size of the
100 file being stored.
101
102 To download, the client that wishes to turn a capability into a sequence of
103 bytes will obtain the blocks from storage servers, use erasure-decoding to
104 turn them into segments of ciphertext, use the decryption key to convert that
105 into plaintext, then emit the plaintext bytes to the output target.
106
107
108 CAPABILITIES
109
110 Capabilities to immutable files represent a specific set of bytes. Think of
111 it like a hash function: you feed in a bunch of bytes, and you get out a
112 capability, which is deterministically derived from the input data: changing
113 even one bit of the input data will result in a completely different
114 capability.
115
116 Read-only capabilities to mutable files represent the ability to get a set of
117 bytes representing some version of the file, most likely the latest version.
118 Each read-only capability is unique. In fact, each mutable file has a unique
119 public/private key pair created when the mutable file is created, and the
120 read-only capability to that file includes a secure hash of the public key.
121
122 Read-write capabilities to mutable files represent the ability to read the
123 file (just like a read-only capability) and also to write a new version of
124 the file, overwriting any extant version. Read-write capabilities are unique
125 -- each one includes the secure hash of the private key associated with that
126 mutable file.
127
128 The capability provides both "location" and "identification": you can use it
129 to retrieve a set of bytes, and then you can use it to validate ("identify")
130 that these potential bytes are indeed the ones that you were looking for.
131
132 The "key-value store" layer doesn't include human-meaningful names.
133 Capabilities sit on the "global+secure" edge of Zooko's Triangle[1]. They are
134 self-authenticating, meaning that nobody can trick you into accepting a file
135 that doesn't match the capability you used to refer to that file. The
136 filesystem layer (described below) adds human-meaningful names atop the
137 key-value layer.
138
139
140 SERVER SELECTION
141
142 When a file is uploaded, the encoded shares are sent to other nodes. But to
143 which ones? The "server selection" algorithm is used to make this choice.
144
145 In the current version, the storage index is used to consistently-permute the
146 set of all peer nodes (by sorting the peer nodes by
147 HASH(storage_index+peerid)). Each file gets a different permutation, which
148 (on average) will evenly distribute shares among the grid and avoid hotspots.
149 We first remove any peer nodes that cannot hold an encoded share for our file,
150 and then ask some of the peers that we have removed if they are already
151 holding encoded shares for our file; we use this information later. This step
152 helps conserve space, time, and bandwidth by making the upload process less
153 likely to upload encoded shares that already exist.
154
155 We then use this permuted list of nodes to ask each node, in turn, if it will
156 hold a share for us, by sending an 'allocate_buckets() query' to each one.
157 Some will say yes, others (those who have become full since the start of peer
158 selection) will say no: when a node refuses our request, we just take that
159 share to the next node on the list. We keep going until we run out of shares
160 to place. At the end of the process, we'll have a table that maps each share
161 number to a node, and then we can begin the encode+push phase, using the table
162 to decide where each share should be sent.
163
164 Most of the time, this will result in one share per node, which gives us
165 maximum reliability (since it disperses the failures as widely as possible).
166 If there are fewer useable nodes than there are shares, we'll be forced to
167 loop around, eventually giving multiple shares to a single node. This reduces
168 reliability, so it isn't the sort of thing we want to happen all the time,
169 and either indicates that the default encoding parameters are set incorrectly
170 (creating more shares than you have nodes), or that the grid does not have
171 enough space (many nodes are full). But apart from that, it doesn't hurt. If
172 we have to loop through the node list a second time, we accelerate the query
173 process, by asking each node to hold multiple shares on the second pass. In
174 most cases, this means we'll never send more than two queries to any given
175 node.
176
177 If a node is unreachable, or has an error, or refuses to accept any of our
178 shares, we remove them from the permuted list, so we won't query them a
179 second time for this file. If a node already has shares for the file we're
180 uploading (or if someone else is currently sending them shares), we add that
181 information to the share-to-peer-node table. This lets us do less work for
182 files which have been uploaded once before, while making sure we still wind
183 up with as many shares as we desire.
184
185 If we are unable to place every share that we want, but we still managed to
186 place a quantity known as "servers of happiness" that each map to a unique
187 server, we'll do the upload anyways. If we cannot place at least this many
188 in this way, the upload is declared a failure.
189
190 The current defaults use k=3, shares_of_happiness=7, and N=10, meaning that
191 we'll try to place 10 shares, we'll be happy if we can place shares on enough
192 servers that there are 7 different servers, the correct functioning of any 3 of
193 which guarantee the availability of the file, and we need to get back any 3 to
194 recover the file. This results in a 3.3x expansion factor. On a small grid, you
195 should set N about equal to the number of storage servers in your grid; on a
196 large grid, you might set it to something smaller to avoid the overhead of
197 contacting every server to place a file. In either case, you should then set k
198 such that N/k reflects your desired availability goals. The correct value for
199 servers_of_happiness will depend on how you use Tahoe-LAFS. In a friendnet with
200 a variable number of servers, it might make sense to set it to the smallest
201 number of servers that you expect to have online and accepting shares at any
202 given time. In a stable environment without much server churn, it may make
203 sense to set servers_of_happiness = N.
204
205 When downloading a file, the current version just asks all known servers for
206 any shares they might have. Once it has received enough responses that it
207 knows where to find the needed k shares, it downloads the shares from those
208 servers. (This means that it tends to download shares from the fastest
209 servers.)
210
211   *future work*
212
213   A future release will use the server selection algorithm to reduce the
214   number of queries that must be sent out.
215
216   Other peer-node selection algorithms are possible. One earlier version
217   (known as "Tahoe 3") used the permutation to place the nodes around a large
218   ring, distributed the shares evenly around the same ring, then walked
219   clockwise from 0 with a basket. Each time it encountered a share, it put it
220   in the basket, each time it encountered a server, give it as many shares
221   from the basket as they'd accept. This reduced the number of queries
222   (usually to 1) for small grids (where N is larger than the number of
223   nodes), but resulted in extremely non-uniform share distribution, which
224   significantly hurt reliability (sometimes the permutation resulted in most
225   of the shares being dumped on a single node).
226
227   Another algorithm (known as "denver airport"[2]) uses the permuted hash to
228   decide on an approximate target for each share, then sends lease requests
229   via Chord routing. The request includes the contact information of the
230   uploading node, and asks that the node which eventually accepts the lease
231   should contact the uploader directly. The shares are then transferred over
232   direct connections rather than through multiple Chord hops. Download uses
233   the same approach. This allows nodes to avoid maintaining a large number of
234   long-term connections, at the expense of complexity and latency.
235
236
237 SWARMING DOWNLOAD, TRICKLING UPLOAD
238
239 Because the shares being downloaded are distributed across a large number of
240 nodes, the download process will pull from many of them at the same time. The
241 current encoding parameters require 3 shares to be retrieved for each
242 segment, which means that up to 3 nodes will be used simultaneously. For
243 larger networks, 8-of-22 encoding could be used, meaning 8 nodes can be used
244 simultaneously. This allows the download process to use the sum of the
245 available nodes' upload bandwidths, resulting in downloads that take full
246 advantage of the common 8x disparity between download and upload bandwith on
247 modern ADSL lines.
248
249 On the other hand, uploads are hampered by the need to upload encoded shares
250 that are larger than the original data (3.3x larger with the current default
251 encoding parameters), through the slow end of the asymmetric connection. This
252 means that on a typical 8x ADSL line, uploading a file will take about 32
253 times longer than downloading it again later.
254
255 Smaller expansion ratios can reduce this upload penalty, at the expense of
256 reliability (see RELIABILITY, below). By using an "upload helper", this
257 penalty is eliminated: the client does a 1x upload of encrypted data to the
258 helper, then the helper performs encoding and pushes the shares to the
259 storage servers. This is an improvement if the helper has significantly
260 higher upload bandwidth than the client, so it makes the most sense for a
261 commercially-run grid for which all of the storage servers are in a colo
262 facility with high interconnect bandwidth. In this case, the helper is placed
263 in the same facility, so the helper-to-storage-server bandwidth is huge.
264
265 See "helper.txt" for details about the upload helper.
266
267
268 THE FILESYSTEM LAYER
269
270 The "filesystem" layer is responsible for mapping human-meaningful pathnames
271 (directories and filenames) to pieces of data. The actual bytes inside these
272 files are referenced by capability, but the filesystem layer is where the
273 directory names, file names, and metadata are kept.
274
275 The filesystem layer is a graph of directories. Each directory contains a
276 table of named children. These children are either other directories or
277 files. All children are referenced by their capability.
278
279 A directory has two forms of capability: read-write caps and read-only caps.
280 The table of children inside the directory has a read-write and read-only
281 capability for each child. If you have a read-only capability for a given
282 directory, you will not be able to access the read-write capability of its
283 children. This results in "transitively read-only" directory access.
284
285 By having two different capabilities, you can choose which you want to share
286 with someone else. If you create a new directory and share the read-write
287 capability for it with a friend, then you will both be able to modify its
288 contents. If instead you give them the read-only capability, then they will
289 *not* be able to modify the contents. Any capability that you receive can be
290 linked in to any directory that you can modify, so very powerful
291 shared+published directory structures can be built from these components.
292
293 This structure enable individual users to have their own personal space, with
294 links to spaces that are shared with specific other users, and other spaces
295 that are globally visible.
296
297
298 LEASES, REFRESHING, GARBAGE COLLECTION
299
300 When a file or directory in the virtual filesystem is no longer referenced,
301 the space that its shares occupied on each storage server can be freed,
302 making room for other shares. Tahoe-LAFS uses a garbage collection ("GC")
303 mechanism to implement this space-reclamation process. Each share has one or
304 more "leases", which are managed by clients who want the file/directory to be
305 retained. The storage server accepts each share for a pre-defined period of
306 time, and is allowed to delete the share if all of the leases are cancelled
307 or allowed to expire.
308
309 Garbage collection is not enabled by default: storage servers will not delete
310 shares without being explicitly configured to do so. When GC is enabled,
311 clients are responsible for renewing their leases on a periodic basis at
312 least frequently enough to prevent any of the leases from expiring before the
313 next renewal pass.
314
315 See docs/garbage-collection.txt for further information, and how to configure
316 garbage collection.
317
318
319 FILE REPAIRER
320
321 Shares may go away because the storage server hosting them has suffered a
322 failure: either temporary downtime (affecting availability of the file), or a
323 permanent data loss (affecting the preservation of the file). Hard drives
324 crash, power supplies explode, coffee spills, and asteroids strike. The goal
325 of a robust distributed filesystem is to survive these setbacks.
326
327 To work against this slow, continual loss of shares, a File Checker is used
328 to periodically count the number of shares still available for any given
329 file. A more extensive form of checking known as the File Verifier can
330 download the ciphertext of the target file and perform integrity checks
331 (using strong hashes) to make sure the data is stil intact. When the file is
332 found to have decayed below some threshold, the File Repairer can be used to
333 regenerate and re-upload the missing shares. These processes are conceptually
334 distinct (the repairer is only run if the checker/verifier decides it is
335 necessary), but in practice they will be closely related, and may run in the
336 same process.
337
338 The repairer process does not get the full capability of the file to be
339 maintained: it merely gets the "repairer capability" subset, which does not
340 include the decryption key. The File Verifier uses that data to find out
341 which nodes ought to hold shares for this file, and to see if those nodes are
342 still around and willing to provide the data. If the file is not healthy
343 enough, the File Repairer is invoked to download the ciphertext, regenerate
344 any missing shares, and upload them to new nodes. The goal of the File
345 Repairer is to finish up with a full set of "N" shares.
346
347 There are a number of engineering issues to be resolved here. The bandwidth,
348 disk IO, and CPU time consumed by the verification/repair process must be
349 balanced against the robustness that it provides to the grid. The nodes
350 involved in repair will have very different access patterns than normal
351 nodes, such that these processes may need to be run on hosts with more memory
352 or network connectivity than usual. The frequency of repair will directly
353 affect the resources consumed. In some cases, verification of multiple files
354 can be performed at the same time, and repair of files can be delegated off
355 to other nodes.
356
357   *future work*
358
359   Currently there are two modes of checking on the health of your file:
360   "Checker" simply asks storage servers which shares they have and does
361   nothing to try to verify that they aren't lying. "Verifier" downloads and
362   cryptographically verifies every bit of every share of the file from every
363   server, which costs a lot of network and CPU. A future improvement would be
364   to make a random-sampling verifier which downloads and cryptographically
365   verifies only a few randomly-chosen blocks from each server. This would
366   require much less network and CPU but it could make it extremely unlikely
367   that any sort of corruption -- even malicious corruption intended to evade
368   detection -- would evade detection. This would be an instance of a
369   cryptographic notion called "Proof of Retrievability". Note that to implement
370   this requires no change to the server or to the cryptographic data structure
371   -- with the current data structure and the current protocol it is up to the
372   client which blocks they choose to download, so this would be solely a change
373   in client behavior.
374
375
376 SECURITY
377
378 The design goal for this project is that an attacker may be able to deny
379 service (i.e. prevent you from recovering a file that was uploaded earlier)
380 but can accomplish none of the following three attacks:
381
382  1) violate confidentiality: the attacker gets to view data to which you have
383     not granted them access
384  2) violate integrity: the attacker convinces you that the wrong data is
385     actually the data you were intending to retrieve
386  3) violate unforgeability: the attacker gets to modify a mutable file or
387     directory (either the pathnames or the file contents) to which you have
388     not given them write permission
389
390 Integrity (the promise that the downloaded data will match the uploaded data)
391 is provided by the hashes embedded in the capability (for immutable files) or
392 the digital signature (for mutable files). Confidentiality (the promise that
393 the data is only readable by people with the capability) is provided by the
394 encryption key embedded in the capability (for both immutable and mutable
395 files). Data availability (the hope that data which has been uploaded in the
396 past will be downloadable in the future) is provided by the grid, which
397 distributes failures in a way that reduces the correlation between individual
398 node failure and overall file recovery failure, and by the erasure-coding
399 technique used to generate shares.
400
401 Many of these security properties depend upon the usual cryptographic
402 assumptions: the resistance of AES and RSA to attack, the resistance of
403 SHA-256 to collision attacks and pre-image attacks, and upon the proximity of
404 2^-128 and 2^-256 to zero. A break in AES would allow a confidentiality
405 violation, a collision break in SHA-256 would allow a consistency violation,
406 and a break in RSA would allow a mutability violation.
407
408 There is no attempt made to provide anonymity, neither of the origin of a
409 piece of data nor the identity of the subsequent downloaders. In general,
410 anyone who already knows the contents of a file will be in a strong position
411 to determine who else is uploading or downloading it. Also, it is quite easy
412 for a sufficiently large coalition of nodes to correlate the set of nodes who
413 are all uploading or downloading the same file, even if the attacker does not
414 know the contents of the file in question.
415
416 Also note that the file size and (when convergence is being used) a keyed
417 hash of the plaintext are not protected. Many people can determine the size
418 of the file you are accessing, and if they already know the contents of a
419 given file, they will be able to determine that you are uploading or
420 downloading the same one.
421
422 The capability-based security model is used throughout this project.
423 Directory operations are expressed in terms of distinct read- and write-
424 capabilities. Knowing the read-capability of a file is equivalent to the
425 ability to read the corresponding data. The capability to validate the
426 correctness of a file is strictly weaker than the read-capability (possession
427 of read-capability automatically grants you possession of
428 validate-capability, but not vice versa). These capabilities may be expressly
429 delegated (irrevocably) by simply transferring the relevant secrets.
430
431 The application layer can provide whatever access model is desired, built on
432 top of this capability access model. The first big user of this system so far
433 is allmydata.com. The allmydata.com access model currently works like a
434 normal web site, using username and password to give a user access to her
435 "virtual drive". In addition, allmydata.com users can share individual files
436 (using a file sharing interface built on top of the immutable file read
437 capabilities).
438
439
440 RELIABILITY
441
442 File encoding and peer-node selection parameters can be adjusted to achieve
443 different goals. Each choice results in a number of properties; there are
444 many tradeoffs.
445
446 First, some terms: the erasure-coding algorithm is described as K-out-of-N
447 (for this release, the default values are K=3 and N=10). Each grid will have
448 some number of nodes; this number will rise and fall over time as nodes join,
449 drop out, come back, and leave forever. Files are of various sizes, some are
450 popular, others are unpopular. Nodes have various capacities, variable
451 upload/download bandwidths, and network latency. Most of the mathematical
452 models that look at node failure assume some average (and independent)
453 probability 'P' of a given node being available: this can be high (servers
454 tend to be online and available >90% of the time) or low (laptops tend to be
455 turned on for an hour then disappear for several days). Files are encoded in
456 segments of a given maximum size, which affects memory usage.
457
458 The ratio of N/K is the "expansion factor". Higher expansion factors improve
459 reliability very quickly (the binomial distribution curve is very sharp), but
460 consumes much more grid capacity. When P=50%, the absolute value of K affects
461 the granularity of the binomial curve (1-out-of-2 is much worse than
462 50-out-of-100), but high values asymptotically approach a constant (i.e.
463 500-of-1000 is not much better than 50-of-100). When P is high and the
464 expansion factor is held at a constant, higher values of K and N give much
465 better reliability (for P=99%, 50-out-of-100 is much much better than
466 5-of-10, roughly 10^50 times better), because there are more shares that can
467 be lost without losing the file.
468
469 Likewise, the total number of nodes in the network affects the same
470 granularity: having only one node means a single point of failure, no matter
471 how many copies of the file you make. Independent nodes (with uncorrelated
472 failures) are necessary to hit the mathematical ideals: if you have 100 nodes
473 but they are all in the same office building, then a single power failure
474 will take out all of them at once. The "Sybil Attack" is where a single
475 attacker convinces you that they are actually multiple servers, so that you
476 think you are using a large number of independent nodes, but in fact you have
477 a single point of failure (where the attacker turns off all their machines at
478 once). Large grids, with lots of truly independent nodes, will enable the use
479 of lower expansion factors to achieve the same reliability, but will increase
480 overhead because each node needs to know something about every other, and the
481 rate at which nodes come and go will be higher (requiring network maintenance
482 traffic). Also, the File Repairer work will increase with larger grids,
483 although then the job can be distributed out to more nodes.
484
485 Higher values of N increase overhead: more shares means more Merkle hashes
486 that must be included with the data, and more nodes to contact to retrieve
487 the shares. Smaller segment sizes reduce memory usage (since each segment
488 must be held in memory while erasure coding runs) and improves "alacrity"
489 (since downloading can validate a smaller piece of data faster, delivering it
490 to the target sooner), but also increase overhead (because more blocks means
491 more Merkle hashes to validate them).
492
493 In general, small private grids should work well, but the participants will
494 have to decide between storage overhead and reliability. Large stable grids
495 will be able to reduce the expansion factor down to a bare minimum while
496 still retaining high reliability, but large unstable grids (where nodes are
497 coming and going very quickly) may require more repair/verification bandwidth
498 than actual upload/download traffic.
499
500 Tahoe-LAFS nodes that run a webserver have a page dedicated to provisioning
501 decisions: this tool may help you evaluate different expansion factors and
502 view the disk consumption of each. It is also acquiring some sections with
503 availability/reliability numbers, as well as preliminary cost analysis data.
504 This tool will continue to evolve as our analysis improves.
505
506 ------------------------------
507
508 [1]: http://en.wikipedia.org/wiki/Zooko%27s_triangle
509
510 [2]: all of these names are derived from the location where they were
511      concocted, in this case in a car ride from Boulder to DEN. To be
512      precise, "Tahoe 1" was an unworkable scheme in which everyone who holds
513      shares for a given file would form a sort of cabal which kept track of
514      all the others, "Tahoe 2" is the first-100-nodes in the permuted hash
515      described in this document, and "Tahoe 3" (or perhaps "Potrero hill 1")
516      was the abandoned ring-with-many-hands approach.
517