BlocktreeCloudPaper.tex 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. \documentclass{article}
  2. \usepackage[scale=0.8]{geometry}
  3. \usepackage{hyperref}
  4. \usepackage{graphicx}
  5. \title{The Blocktree Cloud Orchestration Platform}
  6. \author{Matthew Carr}
  7. \begin{document}
  8. \maketitle
  9. \begin{abstract}
  10. This document is a proposal for a novel cloud platform called Blocktree.
  11. The system is described in terms of the actor model,
  12. where tasks and services are implemented as actors.
  13. The platform is responsible for orchestrating these actors on a set of native operating system processes.
  14. A service is provdied to actors which allows them access to a highly available distributed file system,
  15. which serves as the only source of persistent state for the system.
  16. High availability is achieved using the Raft consensus protocol to synchronize the state of files between processes.
  17. All data stored in the filesystem is secured with strong integrity and optional confidentiality protections.
  18. A network block device like interface allows for fast low-level read and write access to the encrypted data,
  19. with full support for client-side encryption.
  20. Well-known cryptographic primitives and constructions are employed to provide this protection,
  21. the system does not attempt to innovate in terms of cryptography.
  22. The system's trust model allows for mutual TLS authentication between all processes in the system,
  23. even those which are controlled by different owners.
  24. By integrating these ideas into a single platform,
  25. the system aims to advance the status quo in the security and reliability of software systems.
  26. \end{abstract}
  27. \section{Introduction}
  28. % The "Big" Picture.
  29. Blocktree is an attempt to extend the Unix philosophy that everything is a file
  30. to the entire distributed system that comprises modern IT infrastructure.
  31. The system is organized around a global distributed filesystem which defines security
  32. principals, resources, and their authorization attributes.
  33. This filesystem provides a language for access control that can be used to securely grant principals
  34. access to resources from different organizations, without the need to setup federation.
  35. The system provides an actor runtime for orchestrating services.
  36. Resources are represented by actors, and actors are grouped into operating system processes.
  37. Each process has its own credentials which authenticate it as a unique security principal,
  38. and which specify the filesystem path where the process is located.
  39. A process has authorization attributes which determine the set of processes that may communicate with it.
  40. Every connection between processes is established using mutual TLS authentication,
  41. which is accomplished without the need to trust any third-party certificate authorities.
  42. The cryptographic mechanisms which make this possible are described in detail in section 3.
  43. Messages addressed to actors in a different process are forwarded over these connections,
  44. while messages delivered to actors in the same process are delivered with zero-copying.
  45. % Self-certifying paths and the chain of trust.
  46. The single global Blocktree filesystem is partitioned into disjoint domains of authority.
  47. Each domain is controlled by a root principal.
  48. As is the case for all principals,
  49. a root principal is authenticated by a public-private key pair,
  50. and is identified by a hash of its public key.
  51. The domain of authority for a given absolute path is determined by its first component,
  52. which is the identifier of the root principal who controls the domain.
  53. Because there is no meaning to the directory "/",
  54. a directory consisting of only a single component equal to a root principal's identifier is
  55. referred to as the root directory of that root principal.
  56. The root principal delegates its authority to write files to subordinate principals by issuing
  57. them certificates which specify the path that the authority of the subordinate is limited to.
  58. File data is signed for authenticity and a certificate chain is contained in its metadata.
  59. This certificate chain must lead back to the root principal
  60. and consist of certificates with correctly scoped authority in order for the file to be authentic.
  61. Given the path of a file and the file's contents,
  62. this system allows the file to be validated by anyone without the need to trust a third-party.
  63. Blocktree paths are referred to as self-certifying for this reason.
  64. % Persistent state provided by the filesystem.
  65. One of the major challenges in distributed systems is managing persistent state.
  66. Blocktree solves this issue using its distributed filesystem.
  67. Files are broken into segments called sectors.
  68. The sector size of a file can be configured when it is created,
  69. but cannot be changed after the fact.
  70. Reads and writes of individual sectors are guaranteed to be atomic.
  71. The sectors which comprise a file and its metadata are replicated by a set of processes running
  72. the sector service.
  73. This service is responsible for storing the sectors of files which are contained in the directory
  74. containing the process in which it is running.
  75. The actors providing the sector service in a given directory coordinate with one another using
  76. the Raft protocol to synchronize the state of the sectors they store.
  77. This method of partitioning the data in the filesystem based on directory
  78. allows the system to scale beyond the capabilities of a single consensus cluster.
  79. Sectors are secured with strong integrity protection,
  80. which allows anyone to verify that their contents were written by an authorized principal.
  81. Encryption can be optionally applied to sectors,
  82. with the system handling key management.
  83. The cryptographic mechanisms used to implement these protections are described in section 3.
  84. To reduce load on the sector service, and to allow the system to scale to a larger number of users,
  85. a peer-to-peer distribution system is implemented in the filesystem service.
  86. This system allows filesystem actors to download sectors from other filesystem actors
  87. that have the sectors in their local cache.
  88. The threat of malicious actors serving bad sector data is mitigated by the strong integrity
  89. protections applied to sectors.
  90. By using peer-to-peer distribution, the system can serve as a content delivery network.
  91. % Protocol contracts.
  92. One of the design goals of Blocktree is to facilitate the creation of composable distributed
  93. systems.
  94. A major challenge to building such systems is the difficulty in pinning down bugs when they
  95. inevitably occur.
  96. Research into session types (a.k.a. Behavioral Types) promises to bring the safety benefits
  97. of type checking to actor communication.
  98. Blocktree integrates a session typing system that allows protocol contracts to be defined that
  99. specify the communication patterns of a set of actors.
  100. This model allows the state space of the set of actors participating in a computation to be defined,
  101. and the state transitions which occur to be specified based on the types of received messages.
  102. These contracts are used to verify protocol adherence statically and dynamically.
  103. This system is implemented using compile time code generation,
  104. making it a zero-cost abstraction.
  105. This frees the developer from dealing with the numerous failure modes that can occur in a
  106. communication protocol.
  107. % Implementation language and project links.
  108. Blocktree is implemented in the Rust programming language.
  109. Its source code is licensed under the Affero GNU Public License Version 3.
  110. It can be downloaded at the project homepage at \url{https://blocktree.systems}.
  111. Anyone interested in contributing to development is welcome to submit a pull request
  112. to \url{https://gogs.delease.com/Delease/Blocktree}.
  113. If you have larger changes or architectural suggestions,
  114. please submit an issue for discussion prior to spending time implementing your idea.
  115. % Outline of the rest of the paper.
  116. The remainder of this paper is structured as follows:
  117. \begin{itemize}
  118. \item Section 2 describes the actor runtime, service and task orchestration, and service
  119. discovery.
  120. \item Section 3 discusses the filesystem, its concurrency semantics and implementation.
  121. \item Section 4 details the cryptographic mechanisms used to secure communication between
  122. actor runtimes and to protect sector data.
  123. \item Section 5 is a set of examples describing ways that Blocktree can be used to build systems.
  124. \item Section 6 provides some concluding remarks.
  125. \end{itemize}
  126. \section{Actor Runtime}
  127. % Motivation for using the actor model.
  128. Building scalable fault tolerant systems requires us to distribute computation over
  129. multiple computers.
  130. Rather than switching to a different programming model when an application scales beyond the
  131. capacity of a single computer,
  132. it is beneficial in terms of programmer time and program simplicity to begin with a model that
  133. enables multi-computer scalability.
  134. Fundamentally, all communication over an IP network involves the exchange of messages,
  135. namely IP packets.
  136. So if we wish to build scalable fault-tolerant systems,
  137. it makes sense to choose a programming model built on message passing,
  138. as this will ensure low impedance with the underlying networking technology.
  139. % Overview of message passing interface.
  140. That is why Blocktree is built on the actor model
  141. and why its actor runtime is at the core of its architecture.
  142. The runtime can be used to register services and dispatch messages.
  143. Messages can be dispatched in two different ways: with \texttt{send} and \texttt{call}.
  144. A message is dispatched with the \texttt{send} method when no reply is required,
  145. and with \texttt{call} when exactly one is.
  146. The \texttt{Future} returned by \texttt{call} can be awaited to obtain the reply.
  147. If a timeout occurs while waiting for the reply,
  148. the \texttt{Future} completes with an error.
  149. The name \texttt{call} was chosen to bring to mind a remote procedure call,
  150. which is the primary use case this method was intended for.
  151. Awaiting replies to messages serves as a simple way to synchronize a distributed computation.
  152. % Description of virtual actor system.
  153. One of the challenges when building actor systems is supervising and managing actor's lifecycles.
  154. This is handled in Erlang through the use of supervision trees,
  155. but Blocktree takes a different approach inspired by Microsoft's Orleans framework.
  156. Orleans introduced the concept of virtual actors,
  157. which are purely logical entities that exist perpetually.
  158. In Orleans, one does not need to spawn actors nor worry about respawing them should they crash,
  159. the framework takes care of spawning an actor when a message is dispatched to it.
  160. This model also gives the framework the flexibility to deactivate actors when they are idle
  161. and to load balance actors across different computers.
  162. In Blocktree a similar system is used,
  163. which is possible because messages are only addressed to services.
  164. The Blocktree runtime takes care of routing these messages to the appropriate actors,
  165. spawning them if needed.
  166. % The runtime is implemented using tokio.
  167. The actor runtime is currently implemented using the Rust asynchronous runtime tokio.
  168. Actors are spawned as tasks in the tokio runtime,
  169. and multi-producer single consumer channels are used for message delivery.
  170. Because actors are just tasks,
  171. they can do anything a task can do,
  172. including awaiting other futures.
  173. Because of this, there is no need for the actor runtime to support short-lived worker tasks,
  174. as any such use-case can be accomplished by awaiting a set of \texttt{Future}s.
  175. This allows the runtime to focus on providing support for services.
  176. Using tokio also means that we have access to a high performance multi-threaded runtime with
  177. evented IO.
  178. This asynchronous programming model ensures that resources are efficiently utilized,
  179. and is ideal for a system focused on orchestrating services which may be used by many clients.
  180. % Delivering messages over the network.
  181. Messages can be forwarded between actor runtimes using a secure transport layer called
  182. \texttt{bttp}.
  183. Messages are addressed using \emph{actor names}.
  184. An actor name consists of the following fields:
  185. \begin{enumerate}
  186. \item \texttt{service}: The path identifying the receiving service.
  187. \item \texttt{scope}: A filesystem path used to specify the intended recipient.
  188. \item \texttt{rootwards}: An enum describing whether message delivery is attempted towards or
  189. away from the root of the filesystem tree. A value of
  190. \texttt{false} indicates that the message is intended for a runtime directly contained in the
  191. scope. A value of \texttt{true} indicates that the message is intended for a runtime contained
  192. in a parent directory of the scope and should be delivered to a runtime which has the requested
  193. service registered and is closest to the scope.
  194. \item \texttt{id}: An identifier for a specific service provider.
  195. \end{enumerate}
  196. The ID can be a \texttt{Uuid} or a \texttt{String}.
  197. It is treated as an opaque identifier by the runtime,
  198. but a service is free to associate additional meaning to it.
  199. Every message has a header containing the name of the sender and receiver.
  200. The transport is implemented using the QUIC protocol, which integrates TLS for security.
  201. A \texttt{bttp} client may connect anonymously or using credentials.
  202. If an anonymous connection is attempted,
  203. the client has no authorization attributes associated with it.
  204. Only runtimes which grant others the execute permission allow connections from such clients.
  205. If these permissions are not granted in the runtime's file,
  206. anonymous connections are rejected.
  207. When a client connects with credentials,
  208. mutual TLS authentication is performed as part of the connection handshake,
  209. which cryptographically verifies the credentials of each runtime.
  210. These credentials contain the filesystem paths where each runtime is located,
  211. which ensures that messages addressed to a specific path will only be delivered to that path.
  212. The \texttt{bttp} server is always authenticated during the handshake,
  213. even when the client is connecting anonymously.
  214. Because QUIC supports the concurrent use of many different streams,
  215. it serves as an ideal transport for a message oriented system.
  216. \texttt{bttp} uses different streams for independent messages,
  217. ensuring that head of line blocking does not occur.
  218. The same stream is used for sending the reply to a message dispatched with \texttt{call}.
  219. Once a connection is established,
  220. message may flow both directions (provided both runtimes have execute permissions for the other),
  221. regardless of which runtime is acting as the client or the server.
  222. % Delivering messages locally.
  223. When a message is sent between actors in the same runtime it is delivered into the queue of the recipient without any copying,
  224. while ensuring immutability (i.e. move semantics).
  225. This is possible thanks to the Rust ownership system,
  226. because the message sender gives ownership to the runtime when it dispatches the message,
  227. and the runtime gives ownership to the recipient when it delivers the message.
  228. % Security model based on filesystem permissions.
  229. A runtime is represented in the filesystem as a file.
  230. This file contains the authorization attributes which are associated with the runtime's security
  231. principal.
  232. The credentials used by the runtime specify the file, so other runtimes are able to locate it.
  233. The metadata of the file contains authorization attributes just like any other file
  234. (e.g. UID, GID, and mode bits).
  235. In order for a principal to be able to send a message to an actor in the runtime,
  236. it must have execute permissions for this file.
  237. Thus communication between runtimes can be controlled using simple filesystem permissions.
  238. Permissions checking is done during the \texttt{bttp} handshake.
  239. Note that it is possible for messages to be sent in one direction in a \texttt{bttp} connection
  240. but not in the other.
  241. In this situation replies are permitted but unsolicited messages are not.
  242. An important trade-off which was made when designing this model was that messages which are
  243. sent between actors in the same runtime are not subject to any authorization checks.
  244. This was done for two reasons: performance and security.
  245. By eliminating authorization checks messages can be more efficiently delivered between actors in the
  246. same process,
  247. which helps to reduce the performance penalty of the actor runtime over directly using threads.
  248. Security is enhanced by this decision because it forces the user to separate actors with different
  249. security requirements into different operating system processes,
  250. which ensures all of the process isolation machinery in the operating system will be used to
  251. isolate them.
  252. % Representing resources as actors.
  253. As in other actor systems, it is convenient to represent resources in Blocktree using actors.
  254. This allows the same security model used to control communication between actors to be used for
  255. controlling access to resources,
  256. and for resources to be shared by many actors.
  257. For instance, a Point-to-Point Protocol connection could be owned by an actor.
  258. This actor could forward traffic delivered to it in messages over this connection.
  259. The set of actors which are able to access the connection is controlled by setting the filesystem
  260. permissions on the file for the runtime executing the actor owning the connection.
  261. % Message routing to services.
  262. A service is identified by a Blocktree path.
  263. Only one service implementation can be registered in a particular runtime,
  264. though this implementation may be used to spawn many actors as providers for the service,
  265. each associated with a different ID.
  266. The runtime spawns a new actor when it finds no service provider associated with the ID in the
  267. message it is delivering.
  268. Some services may only have one service provider in a given runtime,
  269. as is the case for the sector and filesystem services.
  270. Services are reactive,
  271. they don't do anything until they receive a message to process.
  272. The \texttt{scope} and \texttt{rootward} field in an actor name specify the set of runtimes to
  273. which a message may be delivered.
  274. They allow the sender to express their intended recipient,
  275. while still affording enough flexibility to the runtime to route messages as needed.
  276. If \texttt{rootward} is \texttt{false},
  277. the message is delivered to a service provider in a runtime that is directly contained in
  278. \texttt{scope}.
  279. If \texttt{rootward} is \texttt{true},
  280. the parent directories of scope are searched,
  281. working towards the root of the filesystem tree,
  282. and the message is delivered to the first provider of \texttt{service} which is found.
  283. When there are multiple service providers to which a given message could be delivered,
  284. the one to which it is actually delivered is unspecified,
  285. which allows the runtime to balance load.
  286. Delivery will occur for at most one recipient,
  287. even in the case that there are multiple potential recipients.
  288. In order to contact other runtimes and deliver messages to them,
  289. their IP addresses need to be known.
  290. This is achieved by maintaining a file with a runtime's IP address in the same directory as the
  291. runtime.
  292. The runtime is granted write permissions on the file,
  293. and it is updated by \texttt{bttp} when it begins listening on a new endpoint.
  294. The services which are allowed to be registered in a given runtime are specified in the runtime's
  295. file.
  296. The runtime reads this list and uses it to deny service registrations for unauthorized services.
  297. The list is also read by other runtime's when they are searching a directory for service providers.
  298. % The sector and filesystem service.
  299. The filesystem is itself implemented as a service.
  300. A filesystem service provider can be passed messages to delete files, list directory contents,
  301. open files, or perform several other standard filesystem operations.
  302. When a file is opened,
  303. a new actor is spawned which owns the newly created file handle and its name is returned to the
  304. caller in a reply.
  305. Subsequent read and write messages are sent to this actor.
  306. The filesystem service does not persist any data itself,
  307. its job is to function as an integration layer,
  308. conglomerating sector data from many different sources into a single unified interface.
  309. The sector service is what is ultimately responsible for storing data,
  310. and thus maintaining the persistent state of the system.
  311. It stores sector data in the local filesystem of each computer on which it is registered.
  312. The details of how this is accomplished are deferred to the next section.
  313. % Runtime network discovery.
  314. While it is possible to resolve runtime paths to IP addresses when the filesystem is available,
  315. a different mechanism is needed to allow the filesystem and sector services to discover service
  316. providers.
  317. To facilitate this,
  318. runtimes are able to query one another to learn about other runtimes.
  319. Because queries are intended to facilitate message delivery,
  320. the query fields and their meanings mirror those used for addressing messages:
  321. \begin{enumerate}
  322. \item \texttt{service} The path of the service whose providers are sought.
  323. Only runtimes with this service registered will be returned.
  324. \item \texttt{scope} The filesystem path relative to which the query will be processed.
  325. \item \texttt{rootward} Indicates if the query should search for runtimes from \texttt{scope}
  326. toward the root.
  327. \end{enumerate}
  328. The semantics of \texttt{scope} and \texttt{rootward} in a query are identical to their use in an
  329. actor name.
  330. As long as at least one other runtime is known,
  331. a query can be issued to learn of more runtimes.
  332. A runtime which receives a query may not be able to answer it directly.
  333. If it cannot,
  334. it returns the IP address of the next runtime to which the query should be sent.
  335. In order to bootstrap the discovery processes,
  336. another mechanism is needed to find the first peer to query.
  337. There were several possibilities explored for doing this.
  338. One way is to use a blockchain to store the IP addresses of the runtimes hosting the sector service
  339. in the root directory.
  340. As long as these runtimes could be located,
  341. then all others could be found using the filesystem.
  342. This idea may be worth revisiting in the future,
  343. but the author wanted to avoid the complexity of implementing a new proof of work blockchain.
  344. Another idea was to use multicast link-local addressing to discover other runtimes,
  345. similar to how mDNS operates.
  346. This approach has several advantages.
  347. It avoids any dependency on centralized internet infrastructure
  348. and keeps network load local to the segment on which the runtimes are connected.
  349. But, it will not work over a wide area network,
  350. making it unsuitable for the general case.
  351. Instead, the design which was decided on was to use DNS to resolve a fully qualified domain name
  352. (FQDN) derived from the root principal's identifier.
  353. This FQDN is expected to resolve to the public IP addresses of the runtimes hosting the
  354. sector service in the root directory of the root principal.
  355. Each process is configured with a search domain which is used as a suffix of the FQDN.
  356. The leading labels in the FQDN are computed by base32 encoding a hash of the root
  357. principal's public key.
  358. If the encoded string is longer than 63 bytes (the limit for each label in a hostname),
  359. it is separated into the fewest number of labels possible,
  360. working from left to right along the string.
  361. A dot followed by the search domain is concatenated onto the end of this string to form the FQDN.
  362. This method has the advantages of being simple to implement
  363. and allowing runtimes to discover each other over the internet.
  364. Implementing this system would be facilitated by hosting DNS servers in actors in the same
  365. runtimes as the root sector service providers.
  366. Then, A or AAAA records could be served which point to these runtimes.
  367. These runtimes would also need to be configured with static IP addresses,
  368. and the NS records for the search domain would need to point to them.
  369. Of course it is also possible to build such a system without hosting DNS inside of Blocktree.
  370. The downside of using DNS is that it couples Blocktree with a centralized,
  371. albeit distributed, system.
  372. % Security model for queries.
  373. To allow runtimes which are not permitted to execute the root directory to query for other runtimes,
  374. authorization logic which is specific to queries is needed.
  375. If a process is connected with credentials
  376. and the path in the credentials contains the scope of the query,
  377. the query is permitted.
  378. If a process is connected anonymously,
  379. its query will only be answered if the query scope
  380. and all of its parent directories,
  381. grant others the execute permission.
  382. Queries from authenticated processes can be authorized using only the information in the query,
  383. but anonymous queries require knowledge of filesystem permissions,
  384. some of which may not be known to the answering runtime.
  385. When authorizing an anonymous query,
  386. an answering runtime should check that that the execute permission is granted on all directories
  387. that it is responsible for storing.
  388. If all these checks pass, it should forward the querier to the next runtime as usual.
  389. % Overview of protocol contracts and runtime checking of protocol adherence.
  390. To facilitate the creation of composable systems,
  391. a protocol contract checking system based on session types has been designed.
  392. This system models a communication protocol as a directed graph representing state transitions
  393. based on types of received messages.
  394. The protocol author defines the states that the actors participating in the protocol can be in using
  395. Rust traits.
  396. These traits define handler methods for each message type the actor is expected to handle in that
  397. state.
  398. A top-level trait which represents the entire protocol is defined that contains the types of the
  399. initial state of every actor in the protocol.
  400. A macro is used to generate the message handling loop for the each of the parties to the protocol,
  401. as well as enums to represent all possible states that the parties can be in and the messages that
  402. they exchange.
  403. The generated code is responsible for ensuring that errors are generated when a message of an
  404. unexpected type is received,
  405. eliminating the need for ad-hoc error handling code to be written by application developers.
  406. % Example of a protocol contract.
  407. % TODO: I don't find this example very compelling. It would be more impressive to show a pub-sub
  408. % protocol, that would look cool.
  409. Let us explore the use of this system through a simple example using the HTTP/1.1 protocol.
  410. It is a state-less client-server protocol,
  411. essentially just an RPC from client to server.
  412. We can model this in for the contract checker by defining a trait representing the protocol:
  413. \begin{verbatim}
  414. pub trait Http {
  415. type Server: ServerInit;
  416. }
  417. \end{verbatim}
  418. The purpose of this top-level trait is to specify the initial state of every party to the
  419. communications protocol.
  420. In this case we're only modeling the state of the server,
  421. as the client will just \texttt{call} a method on the server.
  422. The initial state for the server is defined as follows:
  423. \begin{verbatim}
  424. pub trait ServerInit {
  425. type AfterActivate: Listening;
  426. type Fut: Future<Output = Result<Self::AfterActivate>>;
  427. fn handle_activate(self, msg: Activate) -> Self::Fut;
  428. }
  429. \end{verbatim}
  430. \texttt{Activate} is a message sent by the generated code to allow the actor access to the
  431. runtime and the actor's ID.
  432. It is defined as follows:
  433. \begin{verbatim}
  434. pub struct Activate {
  435. rt: &'static Runtime,
  436. act_id: Uuid,
  437. }
  438. \end{verbatim}
  439. We represent the statelessness of HTTP by having the requests to the \texttt{Listening} state
  440. return another \texttt{Listening} state.
  441. \begin{verbatim}
  442. pub trait Listening {
  443. type AfterRequest: Listening;
  444. type Fut: Future<Output = Result<Self::AfterRequest>>;
  445. fn handle_request(self, msg: Envelope<Request>) -> Self::Fut;
  446. }
  447. \end{verbatim}
  448. The \texttt{Envelope} type is a wrapper around a message which contains information about who sent
  449. it and a method which can be used to send a reply.
  450. In general a new type could be returned after each message received,
  451. with the returned type being dependent on the type of the message.
  452. The state graph of this protocol can be visualized as follows:
  453. \begin{center}
  454. \includegraphics[height=1.5in]{HttpStateGraph.pdf}
  455. \end{center}
  456. % Implementing actors in languages other than Rust.
  457. Today the actor runtime only supports executing actors implemented in Rust.
  458. A WebAssembly (Wasm) plugin system is planned to allow any language which can compile to Wasm to be
  459. used to implement an actor.
  460. This work is blocked pending the standardization of the WebAssembly Component Model,
  461. which promises to provide an interface definition language which will allow type safe actors to be
  462. defined in many different languages.
  463. % Running containers using actors.
  464. Blocktree allows containers to be run by encapsulating them using a supervising actor.
  465. This actor is responsible for starting the container and managing the container's kernel namespace.
  466. Logically, it owns any kernel resources created by the container, including all spawned operating
  467. system processes.
  468. When the actor halts,
  469. all of these resources are destroyed.
  470. All network communication to the container is controlled by the supervising actor.
  471. The supervisor can be configured to bind container ports to host ports,
  472. as is commonly done today,
  473. but it can also be used to encapsulate traffic to and from the container in Blocktree messages.
  474. These messages are routed to other actors based on the configuration of the supervisor.
  475. This essentially creates a VPN for containers,
  476. ensuring that regardless of well secured their communication is,
  477. they will be safe to communicate over any network.
  478. This network encapsulation system could be used in other actors as well,
  479. allowing a lightweight and secure VPN system to built.
  480. \section{Filesystem}
  481. % The division of responsibilities between the sector and filesystem services.
  482. The responsibility for storing data in the system is shared between the filesystem and sector
  483. services.
  484. Most actors will access the filesystem through the filesystem service,
  485. which provides a high-level interface that takes care of the cryptographic operations necessary to
  486. read and write files.
  487. The filesystem service relies on the sector service for actually persisting data.
  488. The individual sectors which make up a file are read from and written to the sector service,
  489. which stores them in the local filesystem of the computer on which it is running.
  490. A sector is the atomic unit of data storage.
  491. The sector service only supports reading and writing entire sectors at once.
  492. File actors spawned by the filesystem service buffer reads and writes so until there is enough
  493. data to fill a sector.
  494. Because cryptographic operations are only performed on full sectors,
  495. the cost of providing these protections is amortized over the size of the sector.
  496. Thus there is tradeoff between latency and throughput when selecting the sector size of a file.
  497. A smaller sector size means less latency while a larger one enables more throughput.
  498. % Types of sectors: metadata, integrity, and data.
  499. A file has a single metadata sector, a Merkle sector, and zero or more data sectors.
  500. The sector size of a file can be specified when it is created,
  501. but cannot be changed later.
  502. Every data sector contains the ciphertext of the number of bytes equal to the sector size,
  503. but the metadata and Merkle sectors contain a variable amount of data.
  504. The metadata sector contains all of the filesystem metadata associated with the file.
  505. In addition to the usual metadata present in any Unix filesystem (the contents of the \texttt{stat} struct),
  506. cryptographic information necessary to verify and decrypt the contents of the file are also stored.
  507. The Merkle sector of a file contains a Merkle tree over the data sectors of a file.
  508. The hash function used by this tree can be configured at file creation,
  509. but cannot be changed after the fact.
  510. % How sectors are identified.
  511. When sector service providers are contained in the same directory they connect to each other to form
  512. a consensus cluster.
  513. This cluster is identified by a \texttt{u64} called the cluster's \emph{generation}.
  514. Every file is identified by a pair of \texttt{u64}, its generation and its inode.
  515. The sectors within a file are identified by an enum which specifies which type they are,
  516. and in the case of data sectors, their index.
  517. \begin{verbatim}
  518. pub enum SectorKind {
  519. Meta,
  520. Merkle,
  521. Data(u64),
  522. }
  523. \end{verbatim}
  524. The offset in the plaintext of the file at which each data sector begins can be calculated by
  525. multiplying the sectors offset by the sector size of the file.
  526. % Scaling horizontally: using Raft to create consensus cluster. Additional replication methods.
  527. When multiple multiple sector service providers are contained in the same directory,
  528. the sector service providers connect to each other to form a consensus cluster.
  529. This cluster uses the Raft protocol to synchronize the state of the sectors it stores.
  530. The system is currently designed to replicate all data to each of the service providers in the
  531. cluster.
  532. Additional replication methods are planned for implementation,
  533. such as consisting hashing and erasure encoding,
  534. which allow for different tradeoffs between data durability and storage utilization.
  535. % Scaling vertically: how different generations are stitched together.
  536. The creation of a new generation of the sector service is accomplished with several steps.
  537. First, a new directory is created in which the generation will be located.
  538. Next, one or more processes are credentialed for this directory,
  539. using a procedure which is described in the next section.
  540. The credentialing process produces files for each of the processes stored in the new directory.
  541. The sector service provider in each of the new processes uses service discovery to establish
  542. communication with its peers in the other processes.
  543. Finally, the service provider which is elected leader contacts the cluster in the root directory
  544. and requests a new generation number.
  545. Once this number is known it is stored in the superblock for the generation,
  546. which is the file identified by the new generation number and inode 2.
  547. Note that the superblock is not contained in any directory and cannot be accessed by actors
  548. outside of the sector service.
  549. The superblock also contains information used to assign a inodes when a files are created.
  550. % Sector service discovery. Paths.
  551. % The filesystem service is responsible for cryptographic operations. Client-side encryption.
  552. The sector service is relied upon by the filesystem service to read and write sectors.
  553. Filesystem service providers communicate with the sector service to open files, read and write
  554. their contents, and update their metadata.
  555. These providers are responsible for verifying and decrypting the information contained in sectors
  556. and providing it to downstream actors.
  557. They are also responsible for encrypting and integrity protecting data written by downstream actors.
  558. Most of the complexity of implementing a filesystem is handled in the filesystem service.
  559. Most messages sent to the sector service only specify the operation (read or write), the identifier
  560. for the sector, and the sector contents.
  561. Every time a data sector is written an updated metadata sector is required to be sent in the same
  562. message.
  563. This requirement exists because a signature over the root of the file's Merkle tree is contained in
  564. the metadata,
  565. and since this root changes with every modification, it must be updated during every write.
  566. When the sector service commits a write it hashes the sector contents,
  567. updates the Merkle sector of the file, and updates the metadata sector.
  568. In order for the filesystem service to produce a signature over the root of the file's Merkle tree,
  569. it maintains a copy of the tree in memory.
  570. This copy is loaded from the sector service when the file is opened.
  571. While this does mean duplicating data between the sector and filesystem services,
  572. this design was chosen to reduce the network traffic between the two services,
  573. as the entire Merkle tree does not need to be transmitted on every write.
  574. Encapsulating all cryptographic operations in the filesystem service allows the computer storing
  575. data to be different from the computer encrypting it.
  576. This approach allows client-side encryption to be done on more capable computers
  577. and for this task to be delegated to a storage server on low powered devices.
  578. % Description of how the filesystem layer: opens a file, reads, and writes.
  579. % Peer-to-peer data distribution in the filesystem service.
  580. % Streaming replication.
  581. \section{Cryptography}
  582. % The underlying trust model: self-certifying paths.
  583. % Verifying sector contents on read and certifying on write.
  584. % Confidentiality protecting files with readcaps. Single pubkey operation to read a dir tree.
  585. % Give example of how these mechanisms allow data to be shared without any prior federation.
  586. % Description of bttp handshake and the authentication data which is provided by both parties.
  587. % Requesting and issuing credentials. Multicast link-local network discovery.
  588. \section{Examples}
  589. This section contains examples of systems built using Blocktree. The hope is to illustrate how this
  590. platform can be used to implement existing applications more easily and to make it possible to
  591. implement systems which are currently out of reach.
  592. \subsection{A personal cloud for a home user.}
  593. % Describe my idealized home Blocktree setup.
  594. \subsection{An ecommerce website.}
  595. % Describe a blocktree which runs a cluster of webservers, a manufacturing process, a warehouse
  596. % inventory management system, and an order fulfillment system.
  597. \subsection{A smart home.}
  598. \subsection{A realtime geo-spacial environment.}
  599. % Explain my vision of the metaverse.
  600. \section{Conclusion}
  601. % Blocktree serves as the basis for building a cloud-level distributed operating system.
  602. % The system enables individuals to self-host the services they rely on.
  603. % It also gives business a freeer choice of whether to own or lease computing resources.
  604. % The system advances the status quo in secure computing.
  605. % Composability leads to emergent benefits.
  606. \end{document}