<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Devashish Palkhe</title>
    <description>The latest articles on DEV Community by Devashish Palkhe (@devashish_palkhe_).</description>
    <link>https://dev.to/devashish_palkhe_</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2591701%2F4ac35a9e-8050-4cfc-a67a-b5e4ca6fad70.jpg</url>
      <title>DEV Community: Devashish Palkhe</title>
      <link>https://dev.to/devashish_palkhe_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/devashish_palkhe_"/>
    <language>en</language>
    <item>
      <title>A Guide to Kubernetes Security: Threats and Protections</title>
      <dc:creator>Devashish Palkhe</dc:creator>
      <pubDate>Fri, 31 Jan 2025 07:00:13 +0000</pubDate>
      <link>https://dev.to/devashish_palkhe_/a-guide-to-kubernetes-security-threats-and-protections-h57</link>
      <guid>https://dev.to/devashish_palkhe_/a-guide-to-kubernetes-security-threats-and-protections-h57</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Kubernetes has revolutionized container orchestration, enabling organizations to deploy, scale, and manage applications seamlessly. However, with great flexibility comes great responsibility—securing a Kubernetes environment is no small task.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you're already familiar with Kubernetes and want to delve deeper into its security aspects, this article is for you.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Security is a broad concept which is a combination of multiple things on multiple levels .It is not just 2-3 things which will protect your environment from attackers. Just one security link or a misconfiguration can open the door for attackers to breach your system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0oyi5ymox2lcwasmkt9x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0oyi5ymox2lcwasmkt9x.png" alt=" " width="800" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Questions to Consider:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How can you prevent unauthorized access to your Kubernetes cluster?&lt;/li&gt;
&lt;li&gt;What are the most common security misconfigurations that attackers exploit?&lt;/li&gt;
&lt;li&gt;How can Role-Based Access Control (RBAC) help in securing your workloads?&lt;/li&gt;
&lt;li&gt;What security tools and best practices can enhance your Kubernetes defenses?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this guide, we’ll explore key threats to Kubernetes security and provide actionable strategies to harden your clusters against attacks. Let’s dive in! 🚀&lt;/p&gt;




&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9gzcxb8d2z031a525v06.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9gzcxb8d2z031a525v06.jpg" alt=" " width="600" height="428"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Security best practices🎯
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Enable Kubernetes Role-Based Access Control (RBAC)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Who can access the cluster ?&lt;/li&gt;
&lt;li&gt;What permissions do they have?&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;This should be restricted as much as possible .&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Assigning users specific privileges is a best practice in Kubernetes security. This is achieved through Role-Based Access Control (RBAC), which provides a standard method for managing authorisation where we define what user can perform. When implementing RBAC, it is recommended to use namespace-specific permissions rather than cluster-wide permissions to minimise risk. Even during debugging, avoid granting cluster administrator privileges, as excessive permissions can lead to security vulnerabilities.&lt;/p&gt;

&lt;h3&gt;
  
  
  Network policy
&lt;/h3&gt;

&lt;p&gt;Kubernetes allows all pods within the cluster to communicate with each other which can make operation easier but also creates a security risks.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Communincation between pods is unencrypted this can lead to an attacker to read the communication in plain text .It is a good practise to limit communication by implementing network policy.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This can be done by using service mesh &lt;a href="https://istio.io/latest/about/service-mesh/" rel="noopener noreferrer"&gt;Istio&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is a service mesh an open source app that injects as a sidecar container &lt;/li&gt;
&lt;li&gt;It can handle network logic .&lt;/li&gt;
&lt;li&gt;Acts as a proxy which ensured secure communication between services on a logic level.&lt;/li&gt;
&lt;li&gt;We can also define rules.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Istio not not only provide configuration over networking but also can be used for tracing, metrics &amp;amp; security.&lt;/p&gt;

&lt;h3&gt;
  
  
  Misconfiguration of manifest
&lt;/h3&gt;

&lt;p&gt;Misconfigurations are the most common source of security risk in containerized applications running on Kubernetes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.kubelinter.io/#/" rel="noopener noreferrer"&gt;kube-linter&lt;/a&gt; a tool which checks your yaml manifests and also reports recommendations for resolving any potential issues and returns a non-zero exit code.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Some common issues that KubeLinter identifies are running containers as a non-root user, enforcing least privilege.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;securityContext:
  readOnlyRootFilesystem: true
           runAsUser: 1000
           runAsGroup: 3000
           fsGroup: 2000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Securing Secret Data
&lt;/h3&gt;

&lt;p&gt;Using secrets we only encode and store them in etcd and it is at risk when stored and can easily be decoded if accessed.K8s provides encryption by enabling EncryptionConfiguration but it is complex to set up and manage.We might need to store :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Credentials&lt;/li&gt;
&lt;li&gt;Secret Token&lt;/li&gt;
&lt;li&gt;Keys&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This can be done by using &lt;a href="https://www.vaultproject.io/" rel="noopener noreferrer"&gt;Hashicorp Vault&lt;/a&gt; which store them by encrypting them and we can inject them in namespace by using &lt;a href="https://external-secrets.io/latest/" rel="noopener noreferrer"&gt;External secret Operator&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Building secure Images
&lt;/h3&gt;

&lt;p&gt;As we all know k8s is a platform where we run containerised applications using Images and creating such images is a core part of security .Basic image scanning is what everyone does but that alone is not sufficient .The  best practises are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run as non-root user
By default if we don't provide a user in Dockerfile it runs as a root user.Create a dedicated user and group and then change to non-root user with user directive .&lt;/li&gt;
&lt;li&gt;Setting resource limits
By default, a container has no resource constraints. It is great practise to set resource constraints for an image.&lt;/li&gt;
&lt;li&gt;Keep secrets out
Secrets, which include sensitive data such as credentials and keys, should not be embedded within container images.&lt;/li&gt;
&lt;li&gt;Choose base images from trusted source
All Dockerfiles start from a base image. Using trusted sources of image is important ,You can check for &lt;a href="https://docs.docker.com/docker-hub/image-library/trusted-content/#docker-official-images" rel="noopener noreferrer"&gt;docker&lt;/a&gt; verified images .&lt;/li&gt;
&lt;li&gt;Using multistage Docker build
Multi-stage builds are useful to anyone who has struggled to optimize Dockerfiles while keeping them easy to read and maintain.
With multi-stage builds, you use multiple FROM statements in your Dockerfile.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Secure the etcd
&lt;/h3&gt;

&lt;p&gt;Etcd acts as a database for storing all cluster level information which continously monitors and updates the changes.It is a NoSQL ,key-value pair unencrypted .It stores manifests files for k8s resources.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If accessed by a hacker can add ,delete, update do any malpractice .&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To secure the etcd we put etcd behind a firewall &amp;amp; allow only kube-api-server to access it with proper authentication.&lt;/p&gt;

&lt;h3&gt;
  
  
  Securing backup data
&lt;/h3&gt;

&lt;p&gt;Application data needs to be backed-up and restore if any error occur or any downtime occurs and the data may have information such as :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Medical Record&lt;/li&gt;
&lt;li&gt;Credit card info&lt;/li&gt;
&lt;li&gt;Private information&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;To avoid any malpractice of such important data  which can be leaked, altered or a ransomware we must secure it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://docs.kasten.io/latest/index.html" rel="noopener noreferrer"&gt;Kasten K10&lt;/a&gt; at platform built for Kubernetes, provides enterprise operations teams an easy-to-use, scalable, and secure system for backup/restore, disaster recovery, and mobility of Kubernetes applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure Security policies
&lt;/h3&gt;

&lt;p&gt;Admission Controllers are a crucial part of the Kubernetes security and governance framework. They act as gatekeepers, intercepting requests to the Kubernetes API server before they are persisted. When a request is made to the Kubernetes API server it's intercepted by the admission control layer.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Validating Requests: Ensure that incoming requests comply with predefined rules and policies.&lt;/li&gt;
&lt;li&gt;Modifying Requests: Alter the requested objects before they are created or updated in the cluster. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://kyverno.io/" rel="noopener noreferrer"&gt;Kyverno&lt;/a&gt; &amp;amp; &lt;a href="https://open-policy-agent.github.io/gatekeeper/website/docs/" rel="noopener noreferrer"&gt;Gatekeeper&lt;/a&gt; are widely used and popular due to their ease of use and powerful feature sets.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F83wsbmz8f9vjip2dwnzn.jpeg" alt=" " width="666" height="375"&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Bonus tips 💡
&lt;/h3&gt;

&lt;p&gt;1.Keep the cluster up to date.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Patching Vulnerabilities: Updates often include critical security patches that address newly discovered vulnerabilities.&lt;/li&gt;
&lt;li&gt;Improved Security Features: New Kubernetes versions may introduce enhanced security features, such as improved access control, encryption, or auditing capabilities.&lt;/li&gt;
&lt;li&gt;Compliance: Staying up-to-date helps you meet compliance requirements and industry best practices for security.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2.Enhance app security&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Secure applications exposed via Ingress controllers they provide IP whitelisting/blacklisting features.&lt;/li&gt;
&lt;li&gt;Integrate a WAF with your Ingress controller. A WAF can inspect incoming traffic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3.Limiting usage of resources via namespace:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Logical Separation: Namespaces provide a logical separation of resources within a Kubernetes cluster.&lt;/li&gt;
&lt;li&gt;In case of back door entry and to prevent noisy neighbour we can set ResourceQuotas .&lt;/li&gt;
&lt;/ul&gt;







&lt;h3&gt;
  
  
  What we achieved
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;In this guide, we've explored critical security considerations for Kubernetes and provided practical strategies to strengthen your cluster's defenses. We covered a range of topics, including:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Granular access control (RBAC) &lt;/li&gt;
&lt;li&gt;Network segmentation (Network Policies, Istio) &lt;/li&gt;
&lt;li&gt;Secret management (HashiCorp Vault) &lt;/li&gt;
&lt;li&gt;Etcd protection, secure backups (Kasten K10), policy enforcement (Kyverno, Gatekeeper), secure image building, and manifest validation (kube-linter).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbgcdbzaevf31qpssyrih.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbgcdbzaevf31qpssyrih.jpg" alt=" " width="600" height="479"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Kubernetes security is a continuous effort its hard to secure 100% but implementing these practices will surely secure your environment. These best practices significantly improve your cluster's defenses. Stay informed about vulnerabilities and adapt your strategies.&lt;/p&gt;

&lt;p&gt;Which practice are you most eager to implement? Share in the comments!  The next blog post will provide step-by-step implementation guides for each topic. Follow us for updates!&lt;/p&gt;

&lt;h3&gt;
  
  
  A Quick Reference
&lt;/h3&gt;

&lt;p&gt;Access Control: RBAC (built-in).&lt;/p&gt;

&lt;p&gt;Networking: Network Policies (built-in), Istio (&lt;a href="https://istio.io/" rel="noopener noreferrer"&gt;https://istio.io/&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg9umgtgx96n4u02m83ny.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg9umgtgx96n4u02m83ny.png" alt=" " width="548" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Secrets: Vault (&lt;a href="https://www.vaultproject.io/" rel="noopener noreferrer"&gt;https://www.vaultproject.io/&lt;/a&gt;), External Secrets Operator (&lt;a href="https://external-secrets.io/" rel="noopener noreferrer"&gt;https://external-secrets.io/&lt;/a&gt;).&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0mmi6je6k1cgwldmqk4f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0mmi6je6k1cgwldmqk4f.png" alt=" " width="318" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Manifests: kube-linter (&lt;a href="https://docs.kubelinter.io/" rel="noopener noreferrer"&gt;https://docs.kubelinter.io/&lt;/a&gt;).&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8h06pgf1iztrwgxjjc20.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8h06pgf1iztrwgxjjc20.png" alt=" " width="800" height="648"&gt;&lt;/a&gt;&lt;br&gt;
Images: Non-root, resource limits, no secrets, trusted base images (Docker Official Images: &lt;a href="https://docs.docker.com/docker-hub/image-library/trusted-content/" rel="noopener noreferrer"&gt;https://docs.docker.com/docker-hub/image-library/trusted-content/&lt;/a&gt;), multi-stage builds.&lt;br&gt;
etcd: Access restriction, authentication, encryption.&lt;/p&gt;

&lt;p&gt;Backups: Kasten K10 (&lt;a href="https://docs.kasten.io/" rel="noopener noreferrer"&gt;https://docs.kasten.io/&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxkk17vmuq2a7j68t1cdj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxkk17vmuq2a7j68t1cdj.png" alt=" " width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
Policies: Kyverno (&lt;a href="https://kyverno.io/" rel="noopener noreferrer"&gt;https://kyverno.io/&lt;/a&gt;), Gatekeeper (&lt;a href="https://open-policy-agent.github.io/gatekeeper/" rel="noopener noreferrer"&gt;https://open-policy-agent.github.io/gatekeeper/&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftz06a9u04ly21tnseoya.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftz06a9u04ly21tnseoya.png" alt=" " width="800" height="805"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>k8s</category>
      <category>kubernetes</category>
      <category>security</category>
      <category>cloud</category>
    </item>
  </channel>
</rss>
