1 Encrypted iSCSI Devices on NetBSD
2 =================================
4 This document shows how to set up and run an encrypted iSCSI device on
5 NetBSD. Encryption of devices can be used for maintaining privacy on
6 devices located remotely, possibly on co-located hardware, for
7 instance, or on machines which could be stolen, or to which others
10 To encrypt the iSCSI device, we use the NetBSD iSCSI initiator,
11 available in NetBSD-current, and the standard cgd device. In all,
12 setting up an encrypted device in this manner should take less than 15
13 minutes, even for someone unfamiliar with iSCSI or cgd.
15 The approach is to layer a vnd on top of the "storage" file presented
16 by the iSCSI target. This is exactly the same as normal. On top of that
17 vnd, we layer a cgd device, which ensures that all data is encrypted
21 1. Device Initialisation
22 ========================
24 This first section shows how to initialise the device, a one-time
27 Firstly, the initiator is started, pointing at the machine which is
28 presenting the iSCSI storage (i.e. the machine on which the iSCSI
29 target is running). In this example, the target is running on the
30 same machine as the initiator (a laptop called, in a moment of
31 inspiration, inspiron1300). A 50 MB iSCSI target is being presented
34 # obj/iscsifs -u agc -h inspiron1300.wherever.co.uk /mnt &
38 Filesystem 1K-blocks Used Avail %Cap Mounted on
39 /dev/dk0 28101396 20862004 5834324 78% /
40 kernfs 1 1 0 100% /kern
41 procfs 4 4 0 100% /proc
42 ptyfs 1 1 0 100% /dev/pts
43 /dev/puffs 0 0 0 100% /mnt
46 Looking at the last line, we can see that the initiator is running
49 We now add a vnd device on top of the storage which the target is
52 # vnconfig vnd0 /mnt/inspiron1300.wherever.co.uk/target1/storage
55 We now add a disklabel, which is offset 63 blocks into the iSCSI device.
56 This is so that the encrypted device which we shall put on top of the vnd
57 does not clash with the vnd's label. Chapter 14 of the NetBSD guide, on
58 setting up a cgd device, recommends that the cgd's type be "ccd".
70 sectors/cylinder: 2048
77 headswitch: 0 # microseconds
78 track-to-track seek: 0 # microseconds
82 # size offset fstype [fsize bsize cpg/sgs]
83 a: 102336 63 ccd 2048 16384 28360 # (Cyl. 0 - 49)
84 d: 102400 0 unused 0 0 # (Cyl. 0 - 49)
86 === EdDk.a11098a [confmode] is /tmp/EdDk.a11098a ================(22,11) 95% ==
89 We now set up the cgd device, pointing it at the vnd device.
91 # priv cgdconfig -s cgd0 /dev/vnd0a aes-cbc 128 < /dev/urandom
94 and then zero the cgd device's storage.
96 # dd if=/dev/zero of=/dev/rcgd0d bs=32k
97 dd: /dev/rcgd0d: Invalid argument
100 52428800 bytes transferred in 16.633 secs (3152095 bytes/sec)
103 We now unconfigure the cgd device.
108 and then write using the disklabel verification method onto the cgd. Sometimes,
109 this process does not always complete properly, and so it has to be repeated.
111 # cgdconfig -g -V disklabel -o /etc/cgd/vnd0a aes-cbc 256
112 cgdconfig: could not calibrate pkcs5_pbkdf2
113 cgdconfig: Failed to generate defaults for keygen
114 # cgdconfig -g -V disklabel -o /etc/cgd/vnd0a aes-cbc 256
117 Now we have to add the password to the cgd device
119 # cgdconfig -V re-enter cgd0 /dev/vnd0a
120 /dev/vnd0a's passphrase:
121 re-enter device's passphrase:
124 and disklabel inside the cgd itself:
126 # disklabel -I -e cgd0
136 sectors/cylinder: 2048
138 total sectors: 102336
143 headswitch: 0 # microseconds
144 track-to-track seek: 0 # microseconds
148 # size offset fstype [fsize bsize cpg/sgs]
149 a: 102336 0 4.2BSD 2048 16384 28360 # (Cyl. 0 - 49*)
150 d: 102336 0 unused 0 0 # (Cyl. 0 - 49*)
153 === EdDk.a11253a [confmode] is /tmp/EdDk.a11253a =================(22,53) 95% ==
156 Having placed a disklabel inside the cgd, we can now make a filesystem on there:
159 /dev/rcgd0a: 50.0MB (102336 sectors) block size 8192, fragment size 1024
160 using 4 cylinder groups of 12.49MB, 1599 blks, 3136 inodes.
161 super-block backups (for fsck_ffs -b #) at:
162 32, 25616, 51200, 76784,
165 we can then mount the new file system in the cgd on the /iscsi mount
169 Filesystem 1K-blocks Used Avail %Cap Mounted on
170 /dev/dk0 28101396 20910216 5786112 78% /
171 kernfs 1 1 0 100% /kern
172 procfs 4 4 0 100% /proc
173 ptyfs 1 1 0 100% /dev/pts
174 /dev/puffs 0 0 0 100% /mnt
175 # mount /dev/cgd0a /iscsi
177 Filesystem 1K-blocks Used Avail %Cap Mounted on
178 /dev/dk0 28101396 20910216 5786112 78% /
179 kernfs 1 1 0 100% /kern
180 procfs 4 4 0 100% /proc
181 ptyfs 1 1 0 100% /dev/pts
182 /dev/puffs 0 0 0 100% /mnt
183 /dev/cgd0a 49519 1 47043 0% /iscsi
186 The new file system, mounted on /iscsi, can now be used as normal.
189 2. Unmounting the Encrypted Device
190 ==================================
192 The device can be freed up using the following commands:
202 In normal usage, the device can be mounted. Firstly, the initiator
203 must be configured to connect to the device:
205 # vnconfig vnd0 /mnt/inspiron1300.wherever.co.uk/target1/storage
206 # cgdconfig cgd0 /dev/vnd0a
207 /dev/vnd0a's passphrase:
210 I'm using dk devices on this machine, so I now have to access the cgd
211 device using the dk that was assigned in the cgdconfig step. If I
212 wasn't using dk devices, then I'd use the cgd device.
214 !!!SO PICK ONE OF THE FOLLOWING TWO COMMANDS!!!
216 # mount /dev/cgd0a /iscsi OR
217 # mount /dev/dk3 /iscsi
220 drwxr-xr-x 2 root wheel 512 Jan 1 1970 .
221 drwxr-xr-x 35 root wheel 1536 Jan 5 08:59 ..
223 Filesystem 1K-blocks Used Avail %Cap Mounted on
224 /dev/dk0 28101396 20910100 5786228 78% /
225 kernfs 1 1 0 100% /kern
226 procfs 4 4 0 100% /proc
227 ptyfs 1 1 0 100% /dev/pts
228 /dev/puffs 0 0 0 100% /mnt
229 /dev/dk3 49519 1 47043 0% /iscsi
236 An iSCSI disk can be in a location over which complete control
237 cannot be assured. In order to ensure privacy, the cgd device
238 can be used to encrypt the data on the iSCSI device.
240 This document has shown how to set up a cgd device on top of the
241 iSCSI device, and how to mount and unmount on a regular basis.
245 Sat Jan 5 22:08:32 GMT 2008