You are on page 1of 18

Container Security:

Going Beyond
Image Scanning
In theory at least, containerized applications
are more secure than previous generations of
applications. It’s a lot easier to rip and replace
containers that have encapsulated vulnerable
code, behave in a suspicious or malicious way
indicative of an active breach, or contain high-
risk misconfigurations, than it is to patch an entire
monolithic application. Containers are designed to
make it possible to build and deploy applications
and incremental updates more easily using
microservices that isolate specific functionality in
a modular fashion. In short, microservices make it
easier to rapidly discard a container and replace it
with a more secure version.

However, an application environment can have


thousands of containers — built from base images
that may or may not have originated from trusted
sources — and each container image is composed
of layers of files. Finding the images that have
vulnerabilities requires a significant amount of time,
effort and expertise, but time spent scanning images
at the build stage paves the way for a more secure
application. For this reason, one of the first steps
most organizations take to secure their containerized
applications is to scan their container images for
known vulnerabilities before pushing it into their
registry.

Image scanning is one piece of a much larger


security puzzle that must be solved in order to
ensure your application is protected throughout the
container life cycle.

2
A recent survey of over 400 IT professionals who have Most common
experience working with containers and Kubernetes clusters Kubernetes container

67+33+S
finds a full 90% have dealt with some type of cybersecurity cyberscurity issues
incident involving containers. The most common issues
involved misconfigurations (67%), followed by an actual


major vulnerability (22%), runtime threats (17%) and failed
audit (16%).

Naturally, security will be a concern whenever an 67%

22+78+S
organization adopts an emerging technology. A third of the
Misconfigurations
survey respondents (34%) said they have security concerns
related to their organization’s container strategy. Those
concerns are already having a major impact—nearly half of

 22
respondents (44%) said they have had to delay deploying an
application due to security concerns. 22%
%
Organizations of all sizes are trying to address those

17+83+S
concerns proactively by shifting responsibility for Major vulnerabilities
application security toward developers, otherwise known as
DevSecOps, and implementing security controls spanning
the entire container life cycle, from build, to deploy, to
17%
17%
runtime.

In this e-book, we discuss security best practices that


you should follow while building images and scanning for

16+84+S
vulnerabilities. We will then expand our discussion beyond Runtime incidents
image scanning and identify opportunities for you to
protect your containerized applications and infrastructure
throughout the software life cycle. 16%
16%
Note: this e-book assumes Kubernetes to be the container
orchestrator but many of the recommendations provided are
applicable to most container environments regardless of the

management tool being used. Failed audits

3
SECURING CONTAINER IMAGES
Beyond providing developers with tools to scan images for vulnerabilities, IT organizations also
need to secure the infrastructure entrusted to run those container images. As cybercriminals
become more familiar with container technologies, they are discovering that the most efficient
way to compromise containers is to attack the infrastructure on which they are deployed.
Cybercriminals are known to employ misconfigured Docker application programming interfaces
(APIs) to compromise entire hosts. Cybercriminals can then spin up whatever Docker container
images they like.

BEST PRACTICES FOR The first thing attack surface there is to defend.
SECURING CONTAINER IMAGES developers should be Smaller images are also less
Fortunately, a set of best made aware of is the likely to be impacted by zero-day
practices for securing container need to use secure vulnerabilities if and when they arise.
environments is now emerging. base images whenever possible. A Restricting the image to required
The best place to secure container secure base image provides some binaries, libraries and configuration
images will always be at the peace of mind because they are files is always a good idea.
point where they are created, automatically patched by the entity
which is why static and dynamic that created them. Most developers Development teams
image scanners are now being will employ a secure base image as should also take care
integrated with continuous the foundation for an application by to never bake in any
integration/continuous delivery layering additional images on top of secrets to images.
(CI/CD) platforms. The goal is to the base image. If the base image is Secrets include TLS certificate
make security checks a natural secure, it can make securing the rest keys, cloud provider credentials,
extension of the application of the application that much easier. SSH private keys and database
development process. Instead of passwords. Anyone who can pull the
throwing code “over the wall” for IT teams should also image can extract the secret. Making
cybersecurity teams to review, endeavor to keep sensitive data available only at
application developers are now the base images runtime enables developers to reuse
scanning for vulnerabilities as they they employ to a minimal size the same image in different runtime
write code and as that code is by removing non-essential environments, while still being able
committed to a CI/CD platform. components. Package managers, to update expired or revoked secrets
Once that code is deployed in a networking tools, shells, debuggers without having to reconstruct the
runtime environment, it should be and other application development image. Most organizations manage
subjected to additional periodic tools should never be included secrets via a pod in their Kubernetes
scans to ensure the environment in a production environment. The cluster or a dedicated secret
remains secure. smaller the base image, the less management system.

4
Establishing a comprehensive That approach makes it possible to
DevSecOps workflow for container ensure whatever container images
application is essential. The that are reused have been scanned
challenge is not only making for vulnerabilities and are compliant
sure those workflows are applied with all application regulatory
consistently, but also educating requirements.
developers on why a build failed
because of an unaddressed Each time a container
security issue. image is updated
it should also be
CONTAINER REPOSITORIES automatically
MATTER scanned for known
Developers pull vulnerabilities. At a minimum, each
container images container image should be scanned
from both public and at least every 90 days. Organizations
private repositories, will have to decide for themselves
also known as registries, all the how much risk is associated with
time. The most widely employed each vulnerability discovered.
public repository is Docker Hub. DevSecOps teams should have
However, only a small percentage access to information describing the
of the container images available severity of the vulnerability as well
on any public repository have been as contextual information describing
validated; therefore, organizations how the vulnerabilities may impact
need to be aggressive in inspecting their production environment,
container images pulled from including the different versions and
any public repository. It’s not distributions of Kubernetes clusters.
uncommon for container images The latest version of Kubernetes
on a public repository to have at is 1.19, and some organizations
least one or more known major have clusters running versions of
vulnerabilities, often because they Kubernetes as old or older than
were constructed with outdated 1.11. There are also more than 100
software modules. certified distributions of Kubernetes,
each of which have their own
IT teams would be well- unique configurations.
advised to standardize
on a single container Vulnerability assessment tools
registry through need to be able to pinpoint where a
which they can apply security and vulnerability lies along with specific
compliance controls consistently. recommendations for remediation.

5
HARDENING THE DEPLOYMENT
Once you’ve built your images, the next step is to deploy them. To achieve security in the
deployment phase, you need to understand and manage risk factors including those posed by
the contents of the images being deployed and the configuration of individual containerized
workloads.

While default orchestrator and container engine settings provide a reasonable level of
security in some areas, other settings require specific configurations to lock them down. The
right container security solution should not only display violations of standard policies, but
also provide the DevOps team with recommended changes to quickly correct unnecessary
risks or misconfigurations.

Only with all of this data can


Individual workloads have rich configuration options you get a full understanding
that affect the security posture of the application. To of your risk posture, so
fully understand the risk posed by an application, you you know where to target
need to know: remediation and hardening
efforts. And only with
• What it is (including information about the image, checks and enforcement on
all of these attributes can
such as components or vulnerabilities).
you ensure that workloads
are deployed securely.
• Where it came from (including the registry and tag).

• How it’s deployed (including user identity, privilege Within a cluster, sensitive
level, and other configurations). workloads should also be
separated logically and
physically. Different groups of
• What it can access (including secrets, volumes, and applications, and services with
other infrastructure components such as the host or different security needs, should be
orchestrator API). deployed in separate namespaces
as a first level of isolation. The most
• Whether it complies with your policies and security sensitive workloads should run
requirements. on dedicated nodes so that less
trusted workloads are not able to
affect their operation.

6
BEST PRACTICES FOR HARDENING
THE DEPLOYMENT

USE NAMESPACES TO PROVIDE IDENTIFY EXTERNAL NETWORK


WORKLOAD ISOLATION EXPOSURES
Namespaces are a key boundary for network External network exposure opens services to a
policies, orchestrator access control restrictions, broader pool of potential adversaries. Removing
and other important security controls. Separating unnecessary exposures can prevent exploits,
workloads into namespaces can help contain especially when new vulnerabilities emerge.
attacks and limit the impact of mistakes or
destructive actions by authorized users.

UNDERSTAND YOUR NETWORK


SEGMENTATION RULES
UNDERSTAND HOW PERSISTENT
STORAGE IS CONFIGURED AND Orchestrators typically provide relatively open
USED networking between components — for instance,
Persistent storage is a key persistence vector in Kubernetes by default allows every pod to contact
otherwise ephemeral container environments. every other pod. Network segmentation policies
Persistent storage may also store valuable, sensitive are a key security control that can limit the ability
data. For these reasons, you should be able to of an attacker to move laterally through a container
identify the use and configuration of persistent environment.
storage to enhance your security posture.

UNDERSTAND HOW SECRETS


ARE BEING USED
UNDERSTAND HOW HOST
MOUNTS ARE USED
The container infrastructure can enforce access
Host mounts are another vector that adversaries controls to prevent secrets from being read by
use to establish persistence or interfere with unrelated deployments, but that step helps only if
other containers. Host mounts are sometimes deployments mount just the secrets they actually
unintentionally writable or overbroad. You should need. Visibility into secrets helps you find this type
be familiar with the use and configuration of host of unnecessary exposure and can expose other
mounts. weaknesses, such as short key lengths.

7
BEST PRACTICES FOR HARDENING
THE DEPLOYMENT
ASSESS IMAGE PROVENANCE,
ASSESS PRIVILEGES USED INCLUDING REGISTRIES AND
BY CONTAINERS OTHER ATTRIBUTES
The capabilities, user identity, and privileges It’s highly recommended for your teams to know
granted to container processes can allow or block where the code in your environment was deployed
many security attack vectors, and you should from and implement controls that prevent
examine these settings to minimize risk. deployment from untrusted sources or registries.

ENSURE OLD (AND POTENTIALLY ASSESS IMAGE SCAN STATUS


VULNERABLE) IMAGES ARE BEFORE, DURING, AND AFTER
NOT BEING USED DEPLOYMENT
Your security assessment should include the age It’s important to enforce distinct checks based
of images in their risk profiling, since older images on last vulnerability scan date because images
can contain more vulnerabilities than fresher ones. that haven’t been scanned recently may contain
You should set up alerts for when very old images vulnerabilities that are discoverable but not yet
are deployed. reported for the image.

ASSESS OPERATIONAL BEST


PRACTICES, SUCH AS LABELS
ASSESS RESOURCE REQUESTS AND ANNOTATIONS OR THE USE
AND LIMITS FOR DEPLOYMENTS OF THE “LATEST” TAG
Deployments without resource limits can cause Workloads that don’t specify standard annotations
availability issues for themselves or for neighboring or labels are harder to understand, making it more
applications, especially if they are compromised difficult to remediate security issues. Using tags
and used to run cryptocurrency miners or similar like “latest” increases the risk of new code being
payloads. accidentally deployed.

8
BEST PRACTICES FOR HARDENING
THE DEPLOYMENT
IMPLEMENT CHECKS TO DETECT AUTOMATICALLY NOTIFY APPROPRIATE
COMMON CONFIGURATION TEAMS BASE ON DEPLOYMENT
PROBLEMS METADATA
CHECK-SQUARE High-severity vulnerabilities. Many organizations annotate deployments with
CHECK-SQUARE Image scan age and other best practices. the name, email alias, or Slack channel of the team
responsible for an application. You should be able
CHECK-SQUARE Abnormal privilege levels. to use this metadata effectively to prevent security
CHECK-SQUARE Security-relevant image components, teams from having to manually triage and forward
including package managers and download alerts and findings.
tools.
CHECK-SQUARE Key vectors for adversary persistence attempts,
such as sensitive host directory mounts.
CHECK-SQUARE Common bad practices, such as distributing BLOCK DEPLOYMENTS THAT FAIL
secrets in environment variables. CRITICAL CHECKS
Configuration options evolve over time and The best way to ensure ongoing compliance with
may require significant research to develop policies is to prevent noncompliant workloads from
appropriately specific and understandable being deployed.
policies. Look for out-of-the-box policies in your
security platform to help your team initiate its
security efforts. A solid base of pre-built policies
allows your team to instead focus on building
custom policies in areas they know best: your
applications and practices.

9
SECURING RUNNING CONTAINERS
The goal of the security controls instituted earlier in the life cycles, and described above, is to
minimize risk and prevent attacks, but a successful container security program must also detect
and respond to issues as containers run.

In runtime, security efforts should focus on protecting running deployments by providing


both visibility and detection features. You must monitor the most security-relevant container
activities, including:

Process activity Network communications Network communications


among containerized between containerized
services services and external
clients and servers

Container image and application deployment formats allow developers to better specify
their intent and enable easier introspection into what’s deployed. Effective container security
solutions must take into account the context accumulated during the Build and Deploy
phases of the container life cycle to deliver more effective and accurate runtime detection.

In addition, effective runtime security requires behavioral analysis of container runtime


activity using sophisticated techniques that establish risk, detect and respond to active
attacks, and track attack progression, in addition to basic approaches that include
generating allowlists for process executions, blocking and static log analysis.

10
BEST PRACTICES FOR PROTECTING
RUNTIME CONTAINERS
MONITOR RUNNING GET VISIBILITY INTO ACTIVE
DEPLOYMENTS FOR NEWLY NETWORK TRAFFIC BETWEEN
DISCOVERED VULNERABILITIES ORCHESTRATED MICROSERVICES
Vulnerability data on running — PREFERABLY ORGANIZED BY
containers must be continually CLUSTER, NAMESPACE, AND
updated rather than relying on a single image DEPLOYMENT
vulnerability scan at a particular time. New Microservices and containerized applications
vulnerabilities may be disclosed publicly after typically make extensive use of cluster networking
deployment, so images need to be periodically to cooperate with other services. Active network
rescanned, and any new results need to be included traffic is a key way to understand how applications
in the risk assessment for the deployment. are interacting and spot unexpected contact.

COMPARE AND ANALYZE


UNDERSTAND ALL PROCESSES DIFFERENT RUNTIME ACTIVITY
EXECUTED IN CONTAINERIZED IN PODS OF THE SAME
DEPLOYMENTS DEPLOYMENTS

Processes are an important indicator of security Microservices and containerized applications


and operations-relevant container activity. In typically make extensive use of cluster networking
containers, ad-hoc process launches are less to cooperate with other services. Active network
frequent and more suspicious than they would be traffic is a key way to understand how applications
in other types of infrastructure. are interacting and spot unexpected contact.

ENFORCE CUSTOM POLICIES THAT COMBINE RUNTIME CRITERIA


WITH ATTRIBUTES FROM BUILD- AND DEPLOY-TIME
Build- and deploy-time context, such as orchestrator annotations or image details from
scanners and registries, can help security teams build more effective and targeted
policies. For example, images from public registries might be less trusted, and interactive
debugging activities might be more restricted in sensitive applications.

11
BEST PRACTICES FOR PROTECTING
RUNTIME CONTAINERS
IMPLEMENT RUNTIME DETECTION AUTOMATICALLY ALERT EXTERNAL
POLICIES FOR ATTEMPTED OR SYSTEMS (E.G., EMAIL, PAGERDUTY,
SUCCESSFUL: SLACK, GOOGLE CLOUD SCC AND
SIEM SYSTEMS) WHEN A POLICY IS
CHECK-SQUARE Privilege escalation.
VIOLATED
CHECK-SQUARE Network reconnaissance.
CHECK-SQUARE Package installation. You should immediately alert the right responders
once an attack is detected and the recommended
CHECK-SQUARE Cryptocurrency mininig. response should be based on the severity of the
CHECK-SQUARE Modification of host configuration. policy violation.
CHECK-SQUARE Execution of reverse shells or other remote
access tools.
CHECK-SQUARE Data exfiltration.

DETECT UNEXPECTED ACTIVITIES NEVER PATCH, AND INSTEAD USE


THAT INDICATE AN ADVERSARY KUBERNETES-NATIVE CONTROLS
MAY BE GAINING A FOOTHOLD, TO REPLACE SUSPICIOUS
ESTABLISHING PERSISTENCE, INSTANCES OF RUNNING
ESCALATING PRIVILEGE, MOVING APPLICATIONS.
LATERALLY, OR ACHIEVING THEIR OBJECTIVES Don’t let anyone patch/update a running container;
Adversary behaviors may not match a specific instead, it’s faster, easier and more secure to “scale
denylist item or known vector, but should still be to zero” and then restart. In a runtime environment,
identified using more sophisticated techniques that just kill the pod and relaunch a new one. Containers
compare activity to each application’s baseline. are meant to be immutable, so when suspicious
activity is detected, instruct Kubernetes to scale
suspicious pods to zero, then restart instances of
problematic applications.

12
THE KUBERNETES INFRASTRUCTURE
To understand how to effectively secure your Kubernetes infrastructure, it is informative to
understand the architecture of Kubernetes itself as well as where and how to focus efforts on
valuable mitigations, especially those which require administrator or user configuration when
provisioning clusters. Kubernetes is a robust yet complex infrastructure system for container
orchestration, with multiple components that must be adequately protected.

Each Kubernetes cluster consists of two sets of components: (1) the control plane which
is used to manage operations throughout the cluster, and (2) the cluster’s worker nodes
which run containerized applications in pods. Also, to achieve high availability and resiliency,
especially for production cluster environments, both sets of components can be deployed
across multiple machines that form a cluster.

KUBERNETES CONTROL PLANE

CLOUD
KUBE- CLOUD-
CONTROLLER CONTROLLER
MANAGER MANAGER

KUBE-API-SERVER KUBERNETES NODES

KUBELET KUBELET KUBELET


ETCD KUBE-
KUBE-PROXY KUBE-PROXY KUBE-PROXY
SCHEDULER

CONTAINER CONTAINER CONTAINER


RUNTME RUNTME RUNTME

13
SECURING KUBERNETES
CONTROL PLANE COMPONENTS
Considering that the Kubernetes control plane is designed to make global decisions regarding
a cluster’s operations, compromise of control plane components could easily result in complete
compromise of a cluster. Therefore, a critical starting point for any effort to secure Kubernetes is
to initially focus on protecting its control plane services.

The Kubernetes control plane includes the following components listed below, along with
recommended steps you can take to increase security for each component.

KUBERNETES API SERVER ETCD


(KUBE-APISERVER) This control plane
This is the central control plane component component is the key value
that exposes the Kubernetes API and store that Kubernetes uses
receives and validates API requests for to store all cluster data,
resource creation and modification. It serves as the main including API objects and configurations.
interface for cluster communications, since it is the only
cluster component that all control plane and worker Data stored in etcd needs to be adequately
components can communicate with directly. protected using encryption and access
control since gaining visibility into this data
A number of vulnerabilities impacting the Kubernetes API can reveal significant details about your
server have been and continue to be disclosed. In addition environment, including your containerized
to taking steps to mitigate these vulnerabilities by upgrading applications.
Kubernetes versions or applying security patches, restricting
access to the Kubernetes API is key to securing clusters. Kubernetes supports encryption at rest of
This can be done by: sensitive data such as secrets, but only if it is
• Setting up authentication for all Kubernetes API clients. enabled. Additionally, strong authentication
• Configuring authorization that determines permissions and access controls must be enabled to
regarding who can do what, using Kubernetes Role- limit both read and write access to the data
based Access Control (RBAC). store — while write access to etcd grants full
• Ensuring all API traffic is TLS-encrypted. privileges on the entire cluster.

Audit logging in Kubernetes should also be enabled to


ensure that API events are recorded for further analysis or
investigation, as warranted.

14
KUBE-SCHEDULER
This is the control plane component that handles scheduling of pods on worker nodes based
on resource availability; requirements, and allocation; affinity/anti-affinity, taints/tolerations
requests, and other policy constraints.

File permissions on the kube-scheduler pod specification and kubeconfig files should be restricted, and the
service should be configured to only serve HTTPS. Additionally, the service should be bound to a localhost
interface since it exposes health and metrics information which, by default, do not require authentication or
encryption. Communication with the API server should be done using the secured port, in addition to requiring
controls for authentication and authorization.

KUBE-CONTROLLER-MANAGER CLOUD-CONTROLLER-MANAGER
This control plane component runs This control plane component runs
processes that regulate, maintain processes that manage cluster
and adjust the state of things such dependencies in cloud provider
as nodes, pod replicas, services, environments for functions such as
and services accounts and access node termination, route setup and
tokens. load balancing.

File permissions on the kube-controller-manager pod File permissions on the kube-controller-manager


specification and kubeconfig files should be restricted, pod specification and kubeconfig files should be
and the service should be configured to only serve restricted, and the service should be configured to
HTTPS. It should be bound to a localhost interface only serve HTTPS. You should also ensure that an
as well. You should also ensure that an individual individual service account credential is configured
service account credential is configured per controller per controller in conjunction with Kubernetes RBAC
in conjunction with Kubernetes RBAC to ensure the to ensure control loops run with minimum required
control loops run with minimum required permissions. permissions. Communication with the API server
Communication with the API server should be done should be implemented using the secured port, in
using the secured port, in addition to requiring controls addition to requiring controls for authentication and
for authentication and authorization. authorization.

15
SECURING KUBERNETES
NODE COMPONENTS
Each Kubernetes node runs the following components:

KUBELET KUBE-PROXY
This node component is the This node component is the primary
primary node agent that manages node agent that manages individual
individual containers running in containers running in pods and their
pods and their state based on state based on PodSpecs passed
PodSpecs passed via the Kubernetes API server, or via the Kubernetes API server, or as
as a file with the kubectl command line tool. a file with the kubectl command line tool.

Vulnerabilities related to the kubelet have been Vulnerabilities related to the kubelet have been
and continue to be disclosed — these should and continue to be disclosed — these should
be addressed by upgrading kubelet versions, be addressed by upgrading kubelet versions,
applying available patches, and/or taking steps to applying available patches, and/or taking steps to
mitigate the particular threat vector. mitigate the particular threat vector.

Limiting access to the kubelet with strong Limiting access to the kubelet with strong
authentication and authorization is necessary authentication and authorization is necessary
because its HTTPS endpoints expose APIs because its HTTPS endpoints expose APIs
that grant certain privileges on the node and that grant certain privileges on the node and
containers. By default, access is unauthenticated. containers. By default, access is unauthenticated.

CONTAINER RUNTME
This component enables the functionality required to start, run and manage containers on a
given node, such as communicating with the kernel, setting up cgroups, etc. Some examples of
runtimes supported by Kubernetes include: Docker, CRI-O and containerd.

The container runtime is what executes containers and, therefore, appropriate steps and security best practices
should be taken to harden it. See here for recommendations on securing Docker containers

16
SUMMARY
A foundational aspect of securing
your containers is to focus on the
earliest security gaps that can
arise at the build stage. And while
vulnerability scanning is one of
the most critical early steps you
should take to secure containers,
the security mission doesn’t stop
there. Securing containerized
applications from the time they’re
built until they’re deployed and
running as Kubernetes applications
requires a comprehensive security
program covering the entire software
life cycle and the underlying
infrastructure, too. Your security
tooling and workflows must be
adapted to fit how DevOps operate
so that security doesn’t become a
business inhibitor.

17
Ready to see StackRox in action?
Get a personalized demo tailored for your business,
environment, and needs.

 http://www.devops.com
 https://twitter.com/devopsdotcom
 https://www.facebook.com/devopscom

You might also like