Docker Best Practices: Scanning your images for vulnerabilities

Docker Tuesday by Narrowware

Whenever we mention software security, we think of OWASP Top 10. And that's great. While we must protect our app from XSS, MITM, and a whole bunch of other attack vectors, our containers might end up compromising our best efforts. Scanning Docker images for security vulnerabilities stands as a crucial best practice in modern software development for several compelling reasons. Docker, while incredibly useful for its containerization benefits, requires vigilant attention to security, especially considering the complex layers inherent in containerized applications.

Vulnerable base images

Let's say you stick with alpine:3.9. You're confident that the application you've deployed is running, everything seems great, until one day, the service that gets deployed with that container stops working. Your start wondering why. After some time, you get to find out that the base image - alpine:3.9 has vulnerabilities. If an attacker knows about these vulnerabilities and exploits them, it could lead to unauthorized access, data breaches, or compromise of the containerized application. Seems like in your case, the malicious actors knew about the vulnerable version you've been using all that time.

How to mitigate

One of the approaches you can use is a "Continuous security scan" approach where a pipeline in your CI/CD runs security scans on the docker images that you're using. Automated scanning tools enable you to identify vulnerabilities early in the software development lifecycle. This proactive approach saves time, as it allows developers to fix issues at an earlier stage, reducing rework and ensuring that only secure images progress through the pipeline.

How does Docker help?

Docker has a very nifty command, which you can use on top of every other solution that you have.

  docker scan

should be the first line of defense against potential image security threats.

What does docker scan do?

In the background, the service uses a software called Snyk. Snyk employs databases of known vulnerabilities and security issues, continuously updated with information on emerging threats and weaknesses. By comparing the contents of container images against these databases, security tools flag any identified vulnerabilities, including outdated software versions, weak configurations, or known security flaws. This tool is available as a docker standalone command, but also you can employ it automatically when you push an image to DockerHub. Custom repositories might not benefit from it, however, you have to utilize tools such as docker scout.

To sum up

Scanning Docker images for security vulnerabilities is an integral step in the containerization lifecycle. It serves as a proactive security measure, helping organizations identify and remediate potential risks, fortify their defenses, comply with industry standards, and ensure the safety and resilience of containerized applications in today’s evolving threat landscape.