[BACK]Return to encrypted-iscsi.xml CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / htdocs / docs

File: [cvs.NetBSD.org] / htdocs / docs / encrypted-iscsi.xml (download)

Revision 1.2, Sun Jan 6 00:37:01 2008 UTC (13 years, 9 months ago) by dsieger
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +6 -2 lines

Note that Alistar Crooks is the author.

<?xml version="1.0"?>
<!DOCTYPE webpage
PUBLIC "-//NetBSD//DTD Website-based NetBSD Extension//EN"
"http://www.NetBSD.org/XML/htdocs/lang/share/xml/website-netbsd.dtd">

<webpage id="docs-encrypted-iscsi">
  <config param="desc" value="Encrypted iSCSI on NetBSD" />
  <config param="cvstag" value="$NetBSD: encrypted-iscsi.xml,v 1.2 2008/01/06 00:37:01 dsieger Exp $" />
  <config param="rcsdate" value="$Date: 2008/01/06 00:37:01 $" />
  <head>
    <title>Encrypted iSCSI Devices on NetBSD</title>
  </head>

  <sect1 id="intro">
    <title>Introduction</title>

    <para>
      This document shows how to set up and run an encrypted iSCSI device on
      NetBSD.  Encryption of devices can be used for maintaining privacy on
      devices located remotely, possibly on co-located hardware, for
      instance, or on machines which could be stolen, or to which others
      could gain access.
    </para>

    <para>
      To encrypt the iSCSI device, we use the NetBSD iSCSI initiator,
      available in NetBSD-current, and the standard cgd device.  In all,
      setting up an encrypted device in this manner should take less than 15
      minutes, even for someone unfamiliar with iSCSI or cgd.
    </para>

    <para>
      The approach is to layer a vnd on top of the "storage" file presented
      by the iSCSI target. This is exactly the same as normal. On top of that
      vnd, we layer a cgd device, which ensures that all data is encrypted
      on the iSCSI device.
    </para>

    <sect2 id="devinit">
      <title>Device Initialisation</title>

      <para>
	This first section shows how to initialise the device, a one-time
	operation.
      </para>

      <para>
	Firstly, the initiator is started, pointing at the machine which is
	presenting the iSCSI storage (i.e.  the machine on which the iSCSI
	target is running).  In this example, the target is running on the
	same machine as the initiator (a laptop called, in a moment of
	inspiration, inspiron1300).  A 50 MB iSCSI target is being presented
	as target1.
      </para>

      <screen>
	# obj/iscsifs -u agc -h inspiron1300.wherever.co.uk /mnt &amp;
	[1] 11196
	#
	# df
	Filesystem   1K-blocks       Used      Avail %Cap Mounted on
	/dev/dk0      28101396   20862004    5834324  78% /
	kernfs               1          1          0 100% /kern
	procfs               4          4          0 100% /proc
	ptyfs                1          1          0 100% /dev/pts
	/dev/puffs           0          0          0 100% /mnt
	#
      </screen>

      <para>
	Looking at the last line, we can see that the initiator is running
	via the puffs device.
      </para>

      <para>
	We now add a vnd device on top of the storage which the target is
	presenting:
      </para>

      <screen>
	# vnconfig vnd0 /mnt/inspiron1300.wherever.co.uk/target1/storage
	#
      </screen>

      <para>
	We now add a disklabel, which is offset 63 blocks into the iSCSI device.
	This is so that the encrypted device which we shall put on top of the vnd
	does not clash with the vnd's label. Chapter 14 of the NetBSD guide, on
	setting up a cgd device, recommends that the cgd's type be "ccd".
      </para>


      <screen>
	# disklabel -e vnd0

	# /dev/rvnd0d:
	type: vnd
	disk: vnd
	label: fictitious
	flags:
	bytes/sector: 512
	sectors/track: 32
	tracks/cylinder: 64
	sectors/cylinder: 2048
	cylinders: 50
	total sectors: 102400
	rpm: 3600
	interleave: 1
	trackskew: 0
	cylinderskew: 0
	headswitch: 0           # microseconds
	track-to-track seek: 0  # microseconds
	drivedata: 0

	4 partitions:
	#        size    offset     fstype [fsize bsize cpg/sgs]
	a:    102336        63     ccd      2048 16384 28360  # (Cyl.      0 -     49)
	d:    102400         0     unused      0     0        # (Cyl.      0 -     49)
	~
	=== EdDk.a11098a [confmode] is /tmp/EdDk.a11098a ================(22,11) 95% ==
	#
      </screen>

      <para>
	We now set up the cgd device, pointing it at the vnd device.
      </para>

      <screen>
	# priv cgdconfig -s cgd0 /dev/vnd0a aes-cbc 128 &lt; /dev/urandom
	#
      </screen>

      <para>
	and then zero the cgd device's storage.
      </para>

      <screen>
	# dd if=/dev/zero of=/dev/rcgd0d bs=32k
	dd: /dev/rcgd0d: Invalid argument
	1601+0 records in
	1600+0 records out
	52428800 bytes transferred in 16.633 secs (3152095 bytes/sec)
	#
      </screen>
      
      <para>
	We now unconfigure the cgd device.
      </para>

      <screen>
	# cgdconfig -u cgd0
	#
      </screen>

      <para>
	and then write using the disklabel verification method onto the cgd. Sometimes,
	this process does not always complete properly, and so it has to be repeated.
      </para>

      <screen>
	# cgdconfig -g -V disklabel -o /etc/cgd/vnd0a aes-cbc 256
	cgdconfig: could not calibrate pkcs5_pbkdf2
	cgdconfig: Failed to generate defaults for keygen
	# cgdconfig -g -V disklabel -o /etc/cgd/vnd0a aes-cbc 256
	#
      </screen>
      
      <para>
	Now we have to add the password to the cgd device
      </para>

      <screen>
	# cgdconfig -V re-enter cgd0 /dev/vnd0a
	/dev/vnd0a's passphrase:
	re-enter device's passphrase:
	#
      </screen>

      <para>
	and disklabel inside the cgd itself:
      </para>

      <screen>
	# disklabel -I -e cgd0

	# /dev/rcgd0d:
	type: cgd
	disk: cgd
	label: fictitious
	flags:
	bytes/sector: 512
	sectors/track: 2048
	tracks/cylinder: 1
	sectors/cylinder: 2048
	cylinders: 49
	total sectors: 102336
	rpm: 3600
	interleave: 1
	trackskew: 0
	cylinderskew: 0
	headswitch: 0           # microseconds
	track-to-track seek: 0  # microseconds
	drivedata: 0

	4 partitions:
	#        size    offset     fstype [fsize bsize cpg/sgs]
	a:    102336         0     4.2BSD   2048 16384 28360  # (Cyl.      0 -     49*)
	d:    102336         0     unused      0     0        # (Cyl.      0 -     49*)
	~
	~
	=== EdDk.a11253a [confmode] is /tmp/EdDk.a11253a =================(22,53) 95% ==
	#
      </screen>

      <para>
	Having placed a disklabel inside the cgd, we can now make a filesystem on there:
      </para>

      <screen>
	# newfs /dev/rcgd0a
	/dev/rcgd0a: 50.0MB (102336 sectors) block size 8192, fragment size 1024
	using 4 cylinder groups of 12.49MB, 1599 blks, 3136 inodes.
	super-block backups (for fsck_ffs -b #) at:
	32, 25616, 51200, 76784,
	#
      </screen>

      <para>
	we can then mount the new file system in the cgd on the
	<filename>/iscsi</filename> mount point:
      </para>

      <screen>
	# df
	Filesystem   1K-blocks       Used      Avail %Cap Mounted on
	/dev/dk0      28101396   20910216    5786112  78% /
	kernfs               1          1          0 100% /kern
	procfs               4          4          0 100% /proc
	ptyfs                1          1          0 100% /dev/pts
	/dev/puffs           0          0          0 100% /mnt
	# mount /dev/cgd0a /iscsi
	# df
	Filesystem   1K-blocks       Used      Avail %Cap Mounted on
	/dev/dk0      28101396   20910216    5786112  78% /
	kernfs               1          1          0 100% /kern
	procfs               4          4          0 100% /proc
	ptyfs                1          1          0 100% /dev/pts
	/dev/puffs           0          0          0 100% /mnt
	/dev/cgd0a       49519          1      47043   0% /iscsi
	#
      </screen>

      <para>
	The new file system, mounted on /iscsi, can now be used as normal.
      </para>
    </sect2>

    <sect2 id="unmounting">
      <title>Unmounting the Encrypted Device</title>

      <para>
	The device can be freed up using the following commands:
      </para>

      <screen>
	# umount /iscsi
	# cgdconfig -u cgd0
	# vnconfig -u vnd0
      </screen>
    </sect2>

    <sect2 id="usage">
      <title>Normal Usage</title>

      <para>
	In normal usage, the device can be mounted. Firstly, the initiator
	must be configured to connect to the device:
      </para>

      <screen>
	# vnconfig vnd0 /mnt/inspiron1300.wherever.co.uk/target1/storage
	# cgdconfig cgd0 /dev/vnd0a
	/dev/vnd0a's passphrase:
	#
      </screen>

      <para>
	I'm using dk devices on this machine, so I now have to access the cgd
	device using the dk that was assigned in the cgdconfig step.  If I
	wasn't using dk devices, then I'd use the cgd device.
      </para>

      <warning>!!!SO PICK ONE OF THE FOLLOWING TWO COMMANDS!!!</warning>

      <screen>
	# mount /dev/cgd0a /iscsi OR
	# mount /dev/dk3 /iscsi
	# ls -al /iscsi
	total 3
	drwxr-xr-x   2 root  wheel   512 Jan  1  1970 .
	drwxr-xr-x  35 root  wheel  1536 Jan  5 08:59 ..
	# df
	Filesystem   1K-blocks       Used      Avail %Cap Mounted on
	/dev/dk0      28101396   20910100    5786228  78% /
	kernfs               1          1          0 100% /kern
	procfs               4          4          0 100% /proc
	ptyfs                1          1          0 100% /dev/pts
	/dev/puffs           0          0          0 100% /mnt
	/dev/dk3         49519          1      47043   0% /iscsi
	#
      </screen>
    </sect2>

    <sect2 id="conclusion">
      <title>Conclusion</title>

      <para>
	An iSCSI disk can be in a location over which complete control
	cannot be assured. In order to ensure privacy, the cgd device 
	can be used to encrypt the data on the iSCSI device.
      </para>

      <para>
	This document has shown how to set up a cgd device on top of the
	iSCSI device, and how to mount and unmount on a regular basis.
      </para>

      <para>
	Author: Alistar Crooks, Sat Jan  5 22:08:32 GMT 2008
      </para>
    </sect2>
  </sect1>
</webpage>