You can find many Docker images on the Internet that do all kinds of useful and cool things, but if you download them without using any mechanisms of trust and authentication, you simply run an arbitrary software on your systems.

  • Where did this image come from?
  • Do you trust its creators? What security policies do they use?
  • Do you have objective cryptographic evidence that the image was really created by these people?
  • Are you sure that no one changed the image after it was downloaded?

Docker will run everything you ask for, so encapsulation won’t help here. Even if you use exclusively images of your own production, it makes sense to check whether someone else has changed them after creation. The solution ultimately comes to a classic PKI-based trust chain.

Best practices

General: do not run untested software and / or software obtained from untrusted sources.

Using the Docker registry servers, which can be found in this list of Docker Security Tools, expand the trust server.

For any image that is uploaded or runs on the system, provide mandatory verification of the digital signature.

Examples

Deploying a fully-fledged trusted server is not fully described in this article, but you can start now with signing your images.

If you don’t have an account on the Docker Hub yet, create one.

Create a directory with a simple Dockerfile which contents:

 

Build the image:

 

Log in to your Docker Hub account and upload the image:

 

Enable Docker trust verification:

 

Now try to get the image you just uploaded:

 

You should get the following error:

 

While DOCKER_CONTENT_TRUST enabled, reassemble the container. Now it will be signed by default.

 

Now you can download and upload signed containers without any security warnings. The first time you upload a trusted image, Docker will create a root key for you. You will also need a repository key. In both cases, you will be asked to set a password.

Your private keys will be saved in the ~ / .docker / trust directory, restrict access to them and create a backup copy.

DOCKER_CONTENT_TRUST is an environment variable that will disappear after closing a terminal session. However, trust verification should be implemented at every stage of the process – from assembling images and placing them in registries to uploading and running on servers.

Resource abuse

In general, containers are much more numerous than virtual machines. They are lightweight, which allows you to run many containers even on very simple hardware. This is certainly an advantage, but from the other side there is serious competition for host resources. Software bugs, design mistakes, and hacker attacks can lead to the Denial of Service. To prevent them, you must properly configure resource limits.

Best practices

By default, in most containerization systems, the restriction of these resources is disabled. However, in production, their configuration is simply required. We recommend to adhere to the following principles:

  1. Use the resource-limiting functions included in the Linux core and / or containerization system.
  2. Try to make a stress testing of the system before putting it into commercial operation. For this, are used synthetic tests, as well as artificial creation of the “real” traffic for the system. Stress testing is vital for determining ultimate and normal workloads.
  3. Deploy a monitoring and alerting Docker systems. We are sure that in case of abuse of resources (malicious or not), you would prefer to receive a timely warning, rather than “crashing into the wall at full speed”.

Examples

Control groups (cgroups) are a tool provided by the Linux core that allows you to restrict the access of processes and containers to system resources. Some limits can be controlled from the Docker command line:

 

This command sets a limit of 2 GB of memory available to the container. To check the limit, run a load simulator, for example, the stress program, which is in the Ubuntu repositories:

 

In the output of the program, you will see the line ‘FAILED’.

The following lines should appear in the syslog of the host:

 

With docker stats, you can check the current memory consumption and set limits. In Kubernetes, in the definition of the pod, you can reserve the resources necessary for the normal operation of the application, as well as set limits.

Stay tuned for our next articles about Docker security!