Securing Docker Deployments with Notary: A Simplified Explanation

Valente Vidal
3 min readMar 16, 2023

--

Docker is an incredibly useful platform that allows developers to package applications and their dependencies into containers. These containers make it easy to share, deploy, and run applications consistently across different environments. However, ensuring the security and integrity of these container images is crucial. That’s where Notary comes in.

Notary is a security tool developed by Docker, now part of the Cloud Native Computing Foundation (CNCF). Its primary purpose is to cryptographically sign and verify container images, ensuring that they haven’t been tampered with or altered. In essence, Notary acts as a “seal of approval” for your Docker images.

Here’s a breakdown of why Notary is essential for Docker users, explained through simple examples:

  1. Preventing malicious modifications: Imagine receiving a letter in a sealed envelope. You trust the content of the letter because the seal guarantees that it hasn’t been tampered with. Notary works similarly, ensuring that your Docker images remain intact and free from any unauthorized modifications, such as injected malware or altered code.
  2. Establishing trust in the supply chain: When sharing container images with other teams or organizations, it’s crucial to trust that those images are safe and genuine. Notary is like a digital passport for your container images, certifying their authenticity and allowing developers to collaborate with confidence, knowing they’re working with verified images.
  3. Mitigating reputational risks: Imagine ordering food from a restaurant, only to find out it’s contaminated. You’d likely lose trust in the restaurant, and they would suffer reputational damage. Similarly, if a company unknowingly deploys compromised containers, they risk losing customers and credibility. By using Notary, organizations can confidently distribute their applications, knowing they’re secure and verifiable.
  4. Efficient troubleshooting and maintenance: Verifying the origin and content of container images makes it easier to find and fix issues. For example, if you have a puzzle with missing pieces, it’s easier to identify and solve the problem when you know the source of the puzzle. By integrating Notary into the deployment process, developers can quickly pinpoint issues and focus on enhancing their applications instead of spending excessive time tracing problems.

In short, Notary is a vital tool for professionals working with Docker. It helps secure container images, ensuring they’re authentic and unaltered. By adopting Notary within your Docker ecosystem, you’ll create a more reliable and secure foundation for your application deployments.

Testing it out

Before we dive into the code, you’ll need to have Docker installed on your system. You can follow the installation instructions for your operating system here: https://docs.docker.com/engine/install/

Next, you’ll need to set up a Notary server and client. However, for testing purposes, you can use Docker’s public Notary server at https://notary.docker.io. Here's a step-by-step guide to testing Notary with Docker:

Enable Docker Content Trust, which automatically integrates Docker with the Notary server. You can do this by setting the DOCKER_CONTENT_TRUST environment variable to 1:

For Linux/macOS:

export DOCKER_CONTENT_TRUST=1

For Windows (PowerShell):

$env:DOCKER_CONTENT_TRUST=1

Pull a signed image from Docker Hub, such as the official alpine image:

docker pull alpine:latest

Since Docker Content Trust is enabled, Docker will automatically verify the image’s signature using Notary. If the signature is valid, the image will be pulled successfully. Otherwise, you’ll see an error message.

Now, let’s try to sign and push an image to Docker Hub. First, create a simple Dockerfile:

# Dockerfile
FROM alpine:latest
CMD ["echo", "Hello, Notary!"]

Build the Docker image and tag it with your Docker Hub username:

docker build -t <your-docker-hub-username>/hello-notary .

Replace <your-docker-hub-username> with your actual Docker Hub

Replace <your-docker-hub-username> with your actual Docker Hub username.

Log in to Docker Hub:

docker login

Enter your Docker Hub credentials when prompted.

Push the image to Docker Hub:

docker push <your-docker-hub-username>/hello-notary

Docker will automatically sign the image using your Notary key and push it to Docker Hub. If you haven’t set up a key yet, Docker will guide you through the process.

You can now pull the signed image from Docker Hub and verify its signature:

docker pull <your-docker-hub-username>/hello-notary

With these instructions, you can test the integration of Notary with Docker by signing and verifying container images. Remember to replace <your-docker-hub-username> with your actual Docker Hub username in the commands.

--

--

No responses yet