Apparently, /dev/random is based on hardware interrupts or similar unpredictable aspects of physical hardware. Since virtual machines don't have physical hardware, running cat /dev/random
within a virtual machine produces nothing. I'm using Ubuntu Server 11.04 as the host and guest, with libvirt/KVM.
I need to set-up Kerberos inside a VM, but krb5_newrealm
just hangs forever "Loading random data", since the system isn't producing any.
Does anyone know how to work around this? Is is possible to pass the host's /dev/random (which is very chatty) into the vm so the vm can use it's random data?
I've read that there are some software alternatives, but they aren't good for cryptology since they aren't random enough.
EDIT: It appears that cat /dev/random on the vm does produce output, just very, very slowly. I got my realm set-up by waiting about two hours while it was "Loading random data". Eventually it got enough to continue. I'm still interested in a way to accelerate this though.
It should 'just work'. Even though the vm has no dedicated physical hardware, it still has access to several very good sources of randomness. For example, it can use the CPU's TSC to time its read from virtual disks, which will ultimately wind up timing physical disks to the billionth of a second. These timings depend on turbulent airflow shear in the hard drive, which is unpredictable.
Similar logic applies to network traffic. Even though the interface is virtualized, so long as the packet originates on a physical network (and isn't local to the box, say originating in another vm), the packet timing depends on the phase offset between the crystal oscillator on the network card and the crystal oscillator that drives the TSC. This is dependent on microscopic zone temperature variations in the two quartz crystals. This too is unpredictable.
If for some reason it's not working, the simplest solution is to write a program to mine entropy and add it to the system pool. The network interface is your most reliable source. For example, you can write code to:
Linux has simple IOCTL calls to add entropy to the pool, check the pool's level, and so on. You probably have
rngd
, which can take entropy from a pipe and feed it to the system pool. You can fill the pipe from any source you want, whether it's the TSC or 'wget' requests from your own entropy source.I use haveged on all my headless servers that perform cryptographic operations (e.g. TLS handshakes, kerberos, etc). It should be in most Ubuntu versions' package repository: http://packages.ubuntu.com/search?keywords=haveged&searchon=names&suite=all§ion=all
haveged uses the HAVAGE algorithm to extract entropy from the internal state of modern processors. Here's an indepth explanation: http://www.irisa.fr/caps/projects/hipsor/
You can check the randomness of generated entropy with the ent package. On my systems the generated entropy from haveged passed all randomness tests by ent
Yeah you can seed it, from:
http://manpages.ubuntu.com/manpages/jaunty/man4/random.4.html
You can just put that into /dev/urandom and it should seed the entropy pool. I was able to confirm this by:
Bonus if you make the ssh command go through a router so it generates entropy *:)
This worked for me
Running krb5_newrealm inside a VM can take a long time to complete (after showing "Loading random data" message). You can use the following hack to quicken things a bit.
posted at http://fossies.org/linux/john/doc/Kerberos-Auditing-HOWTO.md
The X86 answer is make sure your VM doesn't trap RdRand or RdSeed. You trust your VM for many things, this is one of them.
A sufficiently recent RNGd on a post Snady Bridge CPU, will (or can be told to) use RdRand or RdSeed, and an untrapped RdRand or RdSeed gets entropy into the VM. /dev/random then works with a real (not a virtual) source of entropy.
This isn't by accident. It's right there in the Intel architecture docs.
For a device based hardware entropy source (I.E. uses a kernel driver to share it) you need the VM to correctly virtualize the physical source. I have no clue if they do this and if so, for which devices.
If your RNGd doesn't have the drng option below, update it. If your hardware doesn't have a fast hardware RNG, you're doomed and you should consider using different hardware for security purposes.
I was having problems with krb5_newrealm hanging as well. This worked well for me, based on the above answer:
You might want to kill it once you're done with your need for random data. /dev/sda probably has more data than you need.
Note: I'm not sure how random the random data generated in this manner actually is.