Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are requests to /dev/(u)random etc. handled in Docker?

Tags:

for documentation purposes on our project I am looking for the following information:

We are using Docker to deploy various applications which require entropy for SSL/TLS and other stuff. These applications may use /dev/random, /dev/random, getrandom(2), etc.. I would like to know how these requests are handled in Docker containers as opposed to one virtual machine running all services (and accessing one shared entropy source).

So far I have (cursorily) looked into libcontainer and runC. Unfortunately I have not found any answers to my question, although I do have a gut feeling that these requests are passed through to the equivalent call on the host.

Can you lead me to any documentation supporting this claim, or did I get it wrong and these requests are actually handled differently?

like image 711
Thomas Avatar asked Oct 08 '18 09:10

Thomas


1 Answers

A docker container is "chroot on steroids". Anyway, the kernel is the same between all docker containers and the host system. So all the kernel calls share the same kernel.

So we can do on our host (in any folder, as root):

mknod -m 444 urandom_host c 1 9

and in some linux chroot:

wget <alpine chroot> | tar -x <some folder>
chroot <some folder>
mknod -m 444 urandom_in_chroot c 1 9

and we can do

docker run -ti --rm alpine sh -l
mknod -m 444 urandom_in_docker c 1 9

Then all calls open(2) and read(2) by any program to any urandom_in_docker and urandom_in_chroot and urandom_host will go into the same kernel into the same kernel urandom module binded to special character file with major number 1 and minor number 9, which is according to this list the random number generator.

As for virtual machine, the kernel is different (if there is any kernel at all). So all the calls to any block/special character files are translated by different kernel (also maybe using different, virtualized architecture and different set of instructions). From the host the virtualmachine is visible as a single process (implementation depended) which may/or may not call the hosts /dev/urandom if the virtualized system/program calls /dev/urandom. In virtualization anything can happen, and that is dependent on particular implementation.

So, the requests to /dev/urandom in docker are handled the same way as on the host machine. As how urandom is handled in kernel, maybe here is a good start.

If you require entropy, be sure to use and install haveged.

like image 179
KamilCuk Avatar answered Nov 17 '22 00:11

KamilCuk