
Disk encryption on NetBSD: achieving secrecy
A guide at netbsd.org explains disk encryption for secrecy if a device is stolen or lost. It keeps a small unencrypted root and moves /home, /var, and /usr to an encrypted cgd partition while using the standard install and boot process.
A guide at netbsd.org/~nia/disk-encrypt/ describes one approach to keeping data on a NetBSD machine secret if it is stolen or lost. It keeps a small unencrypted root file system and moves the directories that change most onto an encrypted cgd partition, without leaving the standard NetBSD installation and boot process. Both disklabel and GPT wedge setups are covered, followed by copying the data across and replacing the original directories with symbolic links.
Threat model and sensitive directories
Two threat models are named at the start: a lost or stolen device whose contents must stay secret, and a tampered device that must become unusable. The text works on the first and sets tamper-proofing aside as very hard, since it depends on hardware and on which attacker is realistic. System files are mostly unmodified and often identical from one user to the next, so the protection is aimed at user-modified data. The locations listed as sensitive are /home, /var, /root, /usr/pkg, /usr/local and /etc. Encrypting only /home may not be enough: a crash dump holds a snapshot of system memory, log files from any server that ran may be sensitive, and mail about interrupted vi sessions can reveal file names. The cgdroot alternative uses only a small unencrypted ramdisk to pivot into an encrypted file system, at the cost of significantly changed startup routines and rescue options that may become harder. The middle path taken here keeps a standard install and boot process.
Installation layout
The installer builds a small unencrypted root and reserves a large encrypted partition. The example takes a 4096 MB (4 GB) root file system and an 11263 MB (11 GB) partition allocated for /var, with the type of the secondary partition switched to cgd and its mount point set to "-"; /usr and /var are later made to share that partition. A complete NetBSD installation including development tools is tiny once growth in /usr, /var and /home is ignored, so 4 GB should be more than enough. A sparc64 virtual machine supplies the examples, but the process is basically the same on amd64.
Configuring the encrypted partition
In the disklabel example the reserved slice is /dev/wd0d. Parameters are generated with the command cgdconfig -g -k argon2id -o /etc/cgd/wd0d adiantum 256, then loaded with cgdconfig -V re-enter cgd0 /dev/wd0d, after which cgd0 looks like another disk whose traffic the kernel encrypts and decrypts. Adiantum is the cipher used in this example, which the text presents as the alternative for CPUs that lack AES acceleration in hardware. A nested disklabel inside cgd0 gives the password check something valid to look for, so verify_method is set to disklabel and /etc/cgd/cgd.conf gains a line that creates cgd0 at boot. On GPT systems the reserved wedge is /dev/dk2 instead; there the parameters file uses aes-cbc 256, a GPT table is nested inside cgd0, verify_method becomes gpt, and the single partition added inside it carries the label encfs. The file system may be LFS, created with newfs_lfs, or the more common and better tested FFSv2ea, created with newfs -O2ea, and /etc/fstab then gets a matching entry for /encfs, with "ffs" instead of "lfs" and the options rw,log,noatime if FFS is used.
Mounting and moving data
The encrypted file system is mounted at /encfs. /home, /var and /usr are copied into it, /encfs/lib is linked to /lib so the relative links under /usr/lib still resolve, and the originals are then moved aside and replaced with symlinks into /encfs. Adding /encfs to critical_filesystems_local in /etc/rc.conf makes it mount early enough for /usr and /var to be available during init. A closing caveat: the installer does not know the encrypted partition exists during upgrades, so upgrades have to be done online, for example with sysupgrade, rather than from an installer booted off removable media. The author also notes the guide was written by one person and may contain errors.
Sources: netbsd.org
SiTech — AI-powered web development
We build fast, modern websites and bring AI into real business workflows. Have a project or a question? We'd love to help.