Security and data durability
By Roberto Arato of aratoingegneria.it
What NEXFS guarantees to the programs that use it, and how. Every guarantee on this page is verified by a lab test with the real processes and, for failures, with machines switched off abruptly.
When data is safe
fsync means on the disk of all copies
fsync and fdatasync return 0 only when the data is on the disk of all
copies and the file size is recorded in the metadata. Not "in the servers'
memory", not "on the majority": on all of them. It is the same promise as a
local disk, kept across several machines.
fsync on a folder makes durable the names created, deleted or renamed in
it: it returns when they are on the disk of the majority of the meta nodes.
A client that has been cut off from the network, or whose rights have
expired, never receives confirmation for data that the cluster has
discarded: its fsync, or its file close, returns an error. A confirmation
from NEXFS is never taken back.
close is not a durability confirmation, just as on a local disk: in a
folder where a node works alone it returns at once, and the data reaches the
copies a moment later. A write error that arrives after the close is not
lost: the next fsync, or the next close of the same file, returns it.
Unmounting (umount) first sends everything still pending; if instead the
client machine loses power, writes without fsync that had not left yet are
lost, as with the cache of a local disk. To know that data is safe, use
fsync.
Two durability levels for metadata, chosen per folder
| Durability | How it works | What it is for |
|---|---|---|
| group (default) | a change to names is confirmed when it is in the memory of the majority of the meta nodes, and goes to disk in groups, within fractions of a second; a node working alone in a folder makes the change locally and sends the changes in groups | everyday work: builds, caches, thousands of small files |
| full | every create, delete or rename is on the disk of the majority when the call returns | data that must not lose even the last operation without fsync |
Full durability is turned on for a folder and applies to everything under it:
setfattr -n nexfs.dir.durability -v full /nex/accounting
With group durability, whatever has not had an fsync behaves as on a local
disk that loses power: a meta node shutting down loses nothing; if the
majority of the meta nodes, or the node that was working alone in a folder,
shut down at the same time, the last fractions of a second of changes
without fsync can be lost. What remains is always a state the filesystem
really went through, never a mix. With fsync, or with full durability,
nothing is lost.
Copies per folder
Every block has 1, 2 or 3 copies, on different data nodes. The number is chosen for the cluster and, if needed, for each folder:
nexfsctl copies 3 /home # real data: three copies
nexfsctl copies 1 /cache # things that can be rebuilt: one copy, faster
nexfsctl copies default /cache # back to the cluster number
The change applies immediately to new files and, in the background, to existing ones.
When something fails
| What happens | What NEXFS does |
|---|---|
| A data node shuts down | writes resume on the other copies within a few seconds; if it does not come back within 10 minutes (configurable) its copies are rebuilt elsewhere |
| The data node comes back | only the blocks that changed in the meantime are brought back in line |
| The leader meta node shuts down | the others elect a new one within a few seconds; no confirmed change is lost |
| A client disappears | its rights (leases on files and folders, locks) expire by themselves within 15 seconds: the others carry on, with no manual eviction |
| The network splits | only the side with the majority of the meta nodes keeps working: never two sides each writing on their own |
| Everything shuts down | when power comes back the cluster restarts by itself |
| A disk returns wrong data | every 64 KiB piece has its own checksum (CRC32C): the read notices, reads another copy and repairs the damaged one |
| A disk fails | the node carries on with the other disks; the blocks that were on it are rebuilt from another copy |
Scrub
Every data node periodically re-reads all its copies, verifies the checksums and compares the copies with each other: a damaged block in a corner nobody reads is found and rebuilt before it is needed. Scrub has a maximum speed (32 MiB/s by default) so as not to disturb the work, and starts over every week; both are set in the configuration.
Offline check
nexfsctl check checks the disks of a stopped node: the metadata store (page
checksums, key order, structure), the consensus log entry by entry and, disk
by disk, every block with the checksums of its pieces. It writes nothing: it
reports what it found, in JSON.
Who can do what
- Mutual TLS 1.3 on every connection. Every node and every client has its own certificate, signed by the cluster's CA (with NEX, the NEX one): no shared secret to distribute.
- Roles. The meta nodes and the certificates listed in
"admins"administer; a data node joins the cluster only if an administrator has admitted it (nexfsctl node allow NAME); a client uses the filesystem and the control store, but cannot change the cluster map. - The server decides permissions. Owners, groups, ACLs: they are checked by the meta node, not just by the client.
- An expired client does not write. A client that has lost its session is refused by the data nodes too, even if it can still reach them.
- Unprivileged daemons.
nexfsdruns as thenexfsuser, with no capabilities, with the system read-only for it; the key of its certificate is passed to it by systemd. Only the FUSE client runs as root. - Damaged or malicious messages. The protocol is tested with fuzzing, against the meta nodes and against the data nodes: a malformed message does not stop any node.
Encryption at rest
Optional, per data node: the blocks on the disks are encrypted with AES-256-XTS, one 64 KiB piece at a time. The key is kept off the data disks (a system file, or a systemd credential):
head -c 64 /dev/urandom > /etc/nexfs/blocks.key && chmod 600 /etc/nexfs/blocks.key
nexfsctl node add ... --encryption-key /etc/nexfs/blocks.key
Every disk remembers the fingerprint of its key: a node started with a different key refuses to start instead of reading meaningless data. A stolen disk, or one taken out of a decommissioned server, reveals nothing about what it contained.
Upgrading without stopping
- One node at a time. During an upgrade the cluster works with nodes on different versions; a node that is stopping or starting answers "try again", and the clients move to another one by themselves.
- The client without unmounting. A
SIGHUPtonexfs-clientrestarts it with the new program keeping the filesystem mounted: open files stay open, locks stay held, whoever was waiting for a lock keeps waiting for it. The pause seen by programs is a tenth of a second. - You can roll back. If the new version does not convince you, you put the previous one back in the same way.