Devsecguide To Kubernetes
Devsecguide To Kubernetes
Kubernetes
Kubernetes® is the de facto container orchestration system, offering
development teams incredible scale, flexibility, and speed when deploying and
managing cloud native applications. For all its benefits, however, it also brings
new complexity and risk.
In this guide, we’ll explore the unique considerations Kubernetes presents for
cloud native application security and how to build on top of its built-in security
foundation to embrace DevSecOps.
Prisma by Palo Alto Networks | The DevSec Guide to Kubernetes | White Paper 1
Table of Contents
Basic Kubernetes Security Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Kubernetes Security Across Each Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Built-in Kubernetes Security Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Prisma by Palo Alto Networks | The DevSec Guide to Kubernetes | White Paper 2
Basic Kubernetes Security Considerations
To help manage containerization at scale, Kubernetes has risen in popularity as the de facto container
orchestrator. It offers development teams incredible scale, flexibility, and speed when deploying and
managing cloud native applications. For all its benefits, however, it also brings new complexity and
security considerations.
Code
Cluster
Application code
Infrastructure code
etcd API server
Nodes
Pods
kubelet
Containers
Scheduler Controllers Container registries
Prisma by Palo Alto Networks | The DevSec Guide to Kubernetes | White Paper 3
• Network Policies: These policies enable you to regulate traffic flow for specific applications in your
cluster at the IP address and port level by defining how a pod can communicate with different net-
work elements (endpoints and services) over the network.
• Admission Controllers: These plugins serve as gatekeepers, intercepting API requests and determin-
ing if they violate a predefined policy before rejecting or modifying them to meet policy. When con-
figured correctly, Admission Controllers are used to provide several basic Kubernetes best practices,
such as limits and requests, and ensure pods are not overly privileged.
• Transport Layer Security (TLS) for Kubernetes Ingress: You can configure access to your Kubernetes
Ingress by defining which inbound connections reach which services using a set of rules, allowing
you to combine all of your routing rules into a single resource. A secret that includes a TLS private
key and certificate can be used to secure a Kubernetes app. Only one TLS port, 443, is supported by
Ingress, which assumes TLS termination. The TLS secret must have the keys named tls. crt and tls.
keys, which contain the TLS certificate and private key, respectively.
• Pod Security Policies: PSPs let you control pod and container behavior by specifying a set of require-
ments that pods must follow in order to be accepted by the cluster; if a request to create or update a
pod fails to match the requirements, the request is rejected, and an error is returned. PSP is far from
comprehensive, which is why it is currently being deprecated.
These built-in capabilities create some guardrails for limiting access and controlling pod and container
behavior. That said, a truly secure Kubernetes environment requires a holistic and automated approach.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Additionally, packaged manifests such as Helm charts and Kustomize files simplify Kubernetes even
further by reducing complexity and duplication.
The biggest security advantage with IaC is that it enables you to scan earlier in the development lifecy-
cle to catch easy-to-miss misconfigurations before they’re deployed.
Prisma by Palo Alto Networks | The DevSec Guide to Kubernetes | White Paper 4
Takeaway: IaC Security Is Key
Automated and continuous IaC scanning is a huge component of DevSecOps and is crucial for
securing cloud native apps.
These are some of the most common Kubernetes security errors and misconfigurations:
• Leaving host infrastructure vulnerable
• Granting overly permissive access to clusters and registries
• Running containers in privileged mode and allowing privilege escalation
• Pulling “latest” container images
• Failing to isolate pods and encrypt internal traffic
• Forgetting to specify resource limits and enable audit logging
• Using the default namespace
• Incorporating insecure open source components
Prisma by Palo Alto Networks | The DevSec Guide to Kubernetes | White Paper 5
While this may seem logical—after all, you typically want the latest version of an application—it can be
risky from a security perspective because relying on the “latest” tag makes it more difficult to track the
specific version of a container that you are using. In turn, you may not know whether your containers
are subject to security vulnerabilities or image-poisoning attacks that impact specific images on an
application.
To avoid this mistake, specify image versions, or better yet, the image manifest when pulling images,
and audit your Kubernetes configurations to detect instances that lack specific version selection for
images. It’s a little more work, but it’s worth it from a Kubernetes security perspective.
securityContext:
allowPrivilegeEscalation: false
Then, ensure that privilege isn’t granted directly with the “privilege” flag or by granting CAP_SYS_
ADMIN. Here again, you can use IaC scanning tools to check for the absence of this security context and
to catch any other privilege escalation settings within pod settings.
Prisma by Palo Alto Networks | The DevSec Guide to Kubernetes | White Paper 6
To avoid these issues, create new namespaces using kubectl or define them in a YAML file. You can
also scan existing YAML files to detect instances where workloads are configured to run in the default
namespace.
--audit-log-path=/var/log/kubernetes/
apiserver/audit.log
--audit-policy-file=/etc/kubernetes/audit-
policies/policy.yaml
Because audit logs offer critical security information, it’s worth including a rule in your Kubernetes
configuration scans to check whether audit logs are enabled.
Before using open source Helm charts from Artifact Hub, GitHub, or 47%
elsewhere, you should scan them for misconfigurations. Similarly,
before deploying container images, you should scan them using tools
to identify vulnerable components within them. Identifying security
Figure 2: High-level findings from Bridgecrew’s
risks within Kubernetes before putting them into production is crucial,
open source Helm security research
especially when it comes to integrating open source components into
your environment.
Prisma by Palo Alto Networks | The DevSec Guide to Kubernetes | White Paper 7
Development
During the development stage, engineers are writing code for applications and infrastructure that
will later be deployed into Kubernetes. These are the three main types of security flaws to avoid in this
phase:
• Misconfigurations within IaC files
• Vulnerabilities in container images
• Hard-coded secrets
You can check for misconfigurations using IaC scanners which can be deployed from the command line
or via IDE extensions. IaC scanners work by identifying missing or incorrect security configurations
that may later lead to security risks when the files are applied.
Container scanning checks for vulnerabilities inside container images. You can run scanners on
individual images directly from the command line. However, most container registries also feature
built-in scanners. The major limitation of container image scanning tools is that they can only detect
known vulnerabilities—meaning those that have been discovered and recorded in public vulnerability
databases.
When scanning container images, keep in mind that container scanners designed to validate the securi-
ty of container images alone may not be capable of detecting risks that are external to container images.
That’s why you should also be sure to scan Kubernetes manifests and any other files that are associat-
ed with your containers. Along similar lines, if you produce Helm charts as part of your build process,
you’ll need security scanning tools that can scan Helm charts.
In addition to avoiding misconfigurations and vulnerabilities, it’s crucial to avoid hard coding secrets
such as passwords or API keys that threat actors can leverage to gain privileged access. Secrets scanning
tools are key to checking for sensitive data like passwords and access keys inside source code. They can
also be used to check for secret data in configuration files that developers write to govern how their
application will behave once it is compiled and deployed.
The key to getting feedback in this stage is to integrate with developers’ local tools and workflows—ei-
ther via integrated development environments (IDEs) or command lines. As code gets integrated into
shared repositories, it’s also important to have guardrails in place that allow for team-wide feedback to
collaboratively address.
This is your last chance to address security issues before they affect users in production. Doing so auto-
matically is the only way to get continuous security coverage.
Runtime
Once your app has been deployed into production, it enters the final stage of the development lifecy-
cle: runtime. If you’ve done the proper vetting during earlier stages of the DevOps lifecycle, you can be
pretty confident that your runtime environment is secure.
However, there’s never a guarantee that unforeseen vulnerabilities won’t arise within a runtime en-
vironment. There is also the risk that developers or IT engineers could change configurations within a
live production environment.
Prisma by Palo Alto Networks | The DevSec Guide to Kubernetes | White Paper 8
That’s why it’s important to scan production environments continuously in order to detect updates to
Security Contexts, Network Policies, and other configuration data. You want to know as soon as possible
if someone on your team makes a change that creates a security vulnerability, or worse, if attackers who
have found a way to access your cluster are making changes in an effort to escalate the attack.
On top of scanning configuration rules, you should also take steps to secure the Kubernetes runtime en-
vironment by hardening and monitoring the nodes that host your cluster. Kernel-level security frame-
works like AppArmor and SELinux can reduce the risk of successful attacks that exploit a vulnerability
within the operating systems running on nodes. Monitoring operating system logs and processes can
also allow you to detect signs of a breach from within the OS. Security information and event manage-
ment (SIEM) and security orchestration, automation, and response (SOAR) platforms are helpful for
monitoring your runtime environment.
People
Having the right people sets the foundation for DevSecOps. Security training and fostering security
champions have been the go-to solution for making security matter, but you can’t stop there. DevSec-
Ops requires bi-directional knowledge sharing to build true shared accountability for security.
Building your team based on formal titles isn’t necessary for building the right culture; whether you
already have the right building blocks or are looking to build out your teams, these are some of the skills
you should look out for:
• A knack for efficiency: Regardless of department, efficiency and automation are key to DevSec-
Ops success. When manual work inevitably crops up, teammates with productivity mindsets will
invest the time to make that repeatable in the future despite the temptation to just complete the
task at hand.
• Balance individual focus and greater goals: DevOps aims to break down the development process into
smaller components and processes, isolating individual outcomes at each phase. DevSecOps requires
striking the right balance between security and efficiency. To do that in practice, priorities need to be
set, recognized, and constantly evaluated from the organization level to the individual contributors.
• Continuous learning: Although Kubernetes has been around for a while now, it’s valuable for every-
one to be constantly learning new things when it comes to building the most performant and inno-
vative products. The same goes for security. Staying on top of the latest vulnerabilities and policies
is essential to keeping your applications secure. Having natural curiosity is ideal, but with consistent
processes for training and education, you can achieve the same outcome.
Processes
The DevSecOps paradigm necessitates new processes or perhaps improvements to existing ones that
prioritize security at each step.
• Development: As code is being written and updated, securing feedback should be incorporated into
workflows via IDE extensions or CLI tools. By surfacing security best practices earlier, it’s easier to
Prisma by Palo Alto Networks | The DevSec Guide to Kubernetes | White Paper 9
address issues with the right context and quickly prevent them from progressing further. This is also
a great way to foster continuous security education through actionable insights.
• Build and deploy: As you add checks to your pull/merge requests and CI/CD pipelines, ensure that
all stakeholders are aware, and expectations are aligned. That way, friction won’t arise when a build
fails, or a deployment is blocked due to a critical misconfiguration or vulnerability. When issues do
arise, make sure you have individuals responsible and on call to help keep things running smoothly.
• Runtime: Even with the most mature, proactive security guardrails in place, the work doesn’t stop at
deployment. Having the right visibility and processes for when security issues are exposed in runtime
is a significant part of a comprehensive DevSecOps strategy.
• Feedback and planning: It’s important for all stakeholders to understand the security impact new
features and updates may have. Security training and awareness are also crucial at this phase, as
work done in this phase will determine the security coverage throughout the rest of the develop-
ment lifecycle.
Setting the right processes in place ensures that everyone is on the same page and sets the foundation
for security consistency and cohesiveness.
Tools
The last component of implementing a successful DevSecOps strategy is tooling. The Kubernetes secu-
rity landscape has numerous tools that tackle various layers and aspects of Kubernetes and cloud native
security. Many of those tools have major shortfalls, however.
When researching and implementing security tooling, make sure to keep these criteria in mind:
• In code, for code: Whether you’re looking for workload protection or Cloud Security Posture Man-
agement, having visibility at the code level is crucial. This is especially true if you develop and
manage any infrastructure in code—which you likely do if you’re leveraging Kubernetes. On a similar
note, being able to address issues at the source is the best way to prevent issues from resurfacing and
snowballing into hundreds of security alerts in runtime.
• Integrated into dev tools and workflows: For code feedback and fixes to be truly actionable, they
need to be surfaced at the right time and in the right place. Whether that’s on a developer’s local
workstation, in a pull/merge request, or during a CI/CD build, continuously enforcing security best
practices is easiest when layered on top of existing tools and workflows.
• Code to cloud coverage: One of the big challenges of securing cloud native environments is that the
state and connections of their components change throughout the development lifecycle. That’s why
coverage across stages is important and why having unified policies and visibility from code to cloud
is so important. Only then can you address issues at the source and detect drift. Having that complete
coverage also helps to bridge the gap between engineering, operations, and security.
• Don’t forget about compliance: While many of the issues we’ve addressed so far relate to security
best practices, getting compliance feedback and enforcing rules for maintaining compliance across
different benchmarks is also a great use case for embedding security early and often.
Prisma by Palo Alto Networks | The DevSec Guide to Kubernetes | White Paper 10
Because Kubernetes is such a dynamic and complex system, it’s even more crucial to implement a solid
set of KPIs to help you assess your organization’s success internally and externally. DevSecOps is get-
ting more popular as a means to avoid costly (both in resources and reputation) breaches.
Bringing the right technologies, people, and processes together to establish baselines and measure
success over time is necessary for any mature Kubernetes-based DevSecOps strategy.
Conclusion
Kubernetes is key to the cloud native ecosystem, providing a multilayered system for automating, de-
ploying, scaling, and managing containerized applications. Thus, Kubernetes security requires a multi-
pronged approach that addresses the security risks that exist across the various layers of Kubernetes.
By leveraging an IaC-based approach to defining security rules in Kubernetes, you can more easily
configure and minimize the risk of configuration issues that will lead to security breaches within any
layer of your Kubernetes stack. Leveraging Kubernetes’ built-in security features, along with a holistic
IaC security strategy, is a solid foundation for building security from the start. DevSecOps is the strategy
that makes it all possible, integrating teams with common processes, metrics, and tools under a com-
mon goal—to deploy secure applications without being hindered by security best practices.
Request a trial.
3000 Tannery Way © 2022 Palo Alto Networks, Inc. Palo Alto Networks is a registered
Santa Clara, CA 95054 trademark of Palo Alto Networks. A list of our trademarks can be found at
https://www.paloaltonetworks.com/company/trademarks.html. All other
Main: +1.408.753.4000 marks mentioned herein may be trademarks of their respective companies.
Sales: +1.866.320.4788 prisma_wp_the-devsec-guide-to-kubernetes_070622
Support: +1.866.898.9087
www.paloaltonetworks.com