What Is Container Security?
Organizations keep scaling their use of containers to run application workloads in the cloud. Attackers have taken notice and organizations can’t afford for container security to be an afterthought.
Container security definition
Container security is the technology, tools, and controls used to protect containerized applications and platforms like Kubernetes and Docker through their entire lifecycle from threat actors and malicious activity.
Many organizations run workloads and applications in the cloud through containers, which can be spun up and down easily, enabling organizations to scale as needed. This ephemeral lifecycle often means that strong security measures need to be in place to protect this growing attack surface.
For organizations that use containers as a service, such as Amazon Elastic Kubernetes Service, Azure Kubernetes Service, or Google Kubernetes Engine, they need to understand the shared responsibility to know what they must secure versus what the platform providers do.
Why container security is important
Container security is important because more and more organizations deploy containerized applications due to their scalability and ease of use. Their popularity means that threat actors know to target them too because they share a kernel with the host system.
To keep applications and data residing in containers secure, organizations need to consider a layered security approach that protects all aspects of containers, including container images, container runtime, container registries, network, secrets management, storage, and container orchestration platforms.
Organizations also need to consider how using containerized environments impacts regulatory compliance, such as HIPAA and ISO 27001. To remain compliant, organizations should ensure they regularly scan container images for risks, use role-based access control (RBAC), audit logging, and data security.
Benefits of container security
While cloud workloads naturally expand the attack surface, container security gives organizations the tools they need to manage exposure to threats.
Other container security benefits include:
- Confidence that containers remain secure even at scale.
- Helps to implement the shift-left security mindset.
- Ensures the organization isn’t out of compliance with regulatory standards.
- Improves visibility into resource usage of containers and orchestration platforms.
Challenges of container security
Understanding container security starts with understanding the security threats that can impact containers.
These threats come in too many forms to detail here. However, the most common types of container security threats include the following:
1. Container malware
Malware is malicious code that is deployed within a container. It can sneak into containers at multiple stages of the container lifecycle. An attacker who compromises your CI/CD environment could insert malware into the source code repositories that are later used to build container images, for instance. Or, attackers could breach your container registry and replace your images with tainted ones that contain malware. A third type of container malware attack involves tricking users into downloading malicious container images from external sources.
In all cases, malware that is not detected before a container is launched will enter your runtime environment, which could lead to any number of security issues, such as collecting sensitive data from an application or disrupting other containers.
2. Insecure container privileges
Typically, containers should run in unprivileged mode, which means they don't have access to any resources outside of the containerized environment that they directly control. Communications between containers should also be restricted unless the containers have a reason to communicate with each other (which would be the case if, for instance, you are running a sidecar container that collects logs from an application container).
When containers are allowed to run with more privileges than they strictly require, security risks result. Insecure privileges are usually caused by problematic configurations with the container orchestrator. For example, containers orchestrated by Kubernetes may have more privileges than they should if Kubernetes security contexts and network policies are not properly defined.
3. Containers with sensitive data
Containers are not intended to be used to store data. But sometimes, organizations make the mistake of storing sensitive information inside container images. For example, Vine's entire source code was exposed when someone discovered a container registry that Vine thought was private, but which was publicly accessible, and which turned out to be hosting images that contained the source code. (To be fair, this happened relatively early in the container era, when best practices surrounding container image management were not yet well established. It's understandable how a mistake like this occurred.)
How to secure containers during their lifecycle
To avoid risks like these, businesses should implement security controls that protect containers at all stages of the container lifecycle. The following is an overview of each stage and which types of threats teams must manage in each one.
1. Development pipeline
The container lifecycle starts with the development pipeline, which is where the code that will later make its way into containers originates.
As noted above, attackers who compromise development tools can insert malicious code into source repositories, leading to a so-called software supply chain attack. If developers don't catch the malicious code before they use it to build images, the code can flow down the pipeline and into production environments.
Implementing access controls for development tools and enforcing the principle of least privilege helps to prevent this risk. So does scanning source code for malware prior to building and shipping it.
2. Container images
A container image is a file that contains the code required to run a container. The image is not the container itself, but rather a blueprint on which a running container will be based. Thus, if the contents of a container image include malware or sensitive data, the containers that are created from the image will be insecure.
As noted above, you should scan your internal source code to help ensure that malware doesn't make its way into your container images.
However, because container images often include resources imported from third-party sources, scanning your own code is not enough. You should also scan the entire container image using a container scanner, which will assess the image contents and flag any components that are known to be insecure. Image scanning can't detect every type of threat (in particular, custom malware that has not yet been recorded in vulnerability databases may elude detection), but they will alert you to the majority of known threats.
3. Container registries
After container images are created, they are usually stored in a container registry, from which users can download them.
There are a few best practices to follow to address registry security. First, you should enforce access controls to ensure that only authorized users can access the images in your registry. Doing so helps prevent accidental data leaks that may occur if images contain private applications or data.
Second, audit registries regularly so you know which images they contain. Outdated images that contain obsolete versions of an application should be removed in order to minimize your attack surface.
Finally, when working with container images from third-party registries, be sure that you trust the source. Half of all of the images in Docker Hub, the most popular public container registry, contain at least one security vulnerability. And sometimes, attackers deliberately upload malicious images with names (like mysqlimage or nginxapp) that are designed to attract unsuspecting users. Avoid pulling images from any unofficial public registry, and be sure to scan all images no matter how much confidence you have in the organization that created them.
4. Container runtime environment
The final stage of the container lifecycle is runtime. This is when containers are deployed into a live environment using container images that were downloaded from a registry.
Runtime security is one of the most complex aspects of container security because it involves multiple moving pieces, which can vary depending on which type of container application stack you use. In most cases, however, runtime security is based on securing:
- The container runtime: This is the process on the server that actually executes containers. You should ensure that your runtime software is up-to-date and patched against known security vulnerabilities.
- The orchestrator: The container orchestrator deploys and manages containers. Most orchestrators offer a variety of tools to help restrict containers' privileges and minimize security risks, but you should also use third-party monitoring and analysis tools to help detect security issues at the orchestrator level.
- Nodes: Kubernetes nodes are the servers that host containers. You need to secure the node operating system, user accounts, networking configurations, and other resources in order to ensure that a breach at the node level doesn't allow attackers to impact your container environment.
5. Continuous container security
The container lifecycle is a circular, continuous process. After containers for a given application have been deployed into a runtime environment, the cycle starts anew when the application is updated, which leads to a new set of containers being pushed down the pipeline. Each new container could contain new risks.
Thus, container security is never a set-it-and-forget-it affair. You must continuously monitor for risks across the container lifecycle, while also updating your monitoring tools, vulnerability databases, and configurations to ensure that you continue to adhere to best practices for container security as your environment evolves.
Should a container environment suffer an incident or breach, organizations need container forensics to understand what happened, what led to the incident, and whether any data was exfiltrated.
Container security tools/technologies
To keep containers protected during their lifecycle, organizations have a variety of tool types they can adopt, including:
- Container vulnerability scanner: These tools scan containers and their images for misconfigurations, vulnerabilities, and other risks.
- Posture and compliance: These tools ensure that containers remain in compliance with industry standards and regulations.
- Runtime security: These tools secure containers from threats and risks while processes are running.
- Policy management: These tools implement and manage security policies used to keep containers protected.
- Security orchestration: These tools help secure containers at the architecture and orchestration level.
Some container security tools organizations can use include cloud-native application protection platforms (CNAPP), cloud workload protection platforms (CWPP), and Kubernetes security posture management (KSPM).
Container security best practices
Implementing container security best practices helps keep containers protected from security incidents, reduce risks causing incidents, and speed up incident investigation. Follow these container security best practices to prevent cyberthreats and security incidents:
- Integrate code scanning at the CI/CD process.
- Reduce external vulnerabilities via dependency scanning.
- Use image scanning to analyze container images.
- Enforce image content trust.
- Remediate common container security misconfigurations.
- Incorporate IaC scanning and policy as code.
- Secure your host with host scanning.
- Prevent unsafe containers from running.
- Protect your resources.
- Verify image signatures.
- Restrict container privileges at runtime.
- Assess runtime containers for vulnerabilities.
- Set up real-time events and log auditing.
- Isolate and investigate containers after a security incident.
- Fix misconfigurations after a security incident.
- Patch vulnerabilities after a security incident.
How security is different for Kubernetes vs. Docker
Organizations will undoubtedly hear about Docker and Kubernetes when researching how to begin using and deploying containers. Docker is a platform used by developers to build, share, and run container applications, while Kubernetes is an orchestration platform for deploying and managing container applications.
Container security involves protecting containers during their entire lifecycle and this includes Docker and Kubernetes. Docker security typically involves protecting container images from drift, risks, and vulnerabilities, while Kubernetes security is about monitoring and managing who can access a cluster, container-to-container communications, and container isolation.
Container security with Sysdig moves as fast as threats
Successful container security ensures organizations stay ahead of threat actors by gaining visibility across all deployments and orchestration.
With Sysdig container security, organizations get real-time visibility into all containers, reduce alert burnout, and get full context about any risks, vulnerabilities, and threats. Sysdig is purpose built for containers and cloud-native infrastructure, helping organizations innovate without being slowed down by security.
