Kubernetes Control Plane: 10 Tips for Airtight K8s Security
Tags: cloud, devops, kubernetes, k8s
Published: 2023-01-05 10:27:23

<!-- wp:paragraph -->
<p>In a recent report, 94% of respondents said they experienced a Kubernetes-related security incident. Misconfigurations are the most common kind of Kubernetes vulnerability, reported by 70% of the surveyed companies.<sup>1</sup> What’s one attractive target for cybercriminals? The Kubernetes control plane.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Teams must harden the perimeter of nodes, masters, core components, APIs, and public-facing pods. Otherwise, they can’t defend clusters against existing and potential vulnerabilities. Here are 10 best practices to help you secure your Kubernetes control plane and speed up the deployment process.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="h-10-tips-to-secure-your-kubernetes-control-plane">10 tips to secure your Kubernetes control plane</h2>
<!-- /wp:heading -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-1-use-kubernetes-role-based-access-control-rbac">1. Use Kubernetes Role-Based Access Control (RBAC)</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Take advantage of RBAC to set who has access to the Kubernetes API and, once they’re in, which permissions they have. You’ll find RBAC enabled by default in Kubernetes version 1.6 and up. Since K8s brings together authorization controllers, you can disable the legacy Attribute Based Access Control (ABAC) when RBAC is on.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>When setting permissions, pick namespace-specific ones over cluster-wide ones. Even when your team is busy debugging, it’s better not to give anyone cluster administrator privileges. Otherwise, your cluster’s security may become compromised.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-2-bet-on-isolation">2. Bet on isolation</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Don’t expose your Kubernetes nodes directly to public networks. Trust me; it’s a bad idea. The best place for your nodes is a separate network with no direct connection to the general corporate network.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Another important isolation best practice is to separate the Kubernetes control and data traffic. You don’t want them to flow through the same pipe. Open access to the data plane results in open access to the control plane.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-3-avoid-deploying-objects-to-the-default-namespace">3. Avoid deploying objects to the default namespace</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In Kubernetes, <a href="https://cast.ai/blog/kubernetes-namespace-how-to-use-it-to-organize-and-optimize-costs/" target="_blank" rel="noreferrer noopener">namespaces</a> provide a mechanism for isolating resource groups within one cluster. They’re a great use case for environments where many users are spread across multiple teams or projects.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>All the objects that have no namespace assigned to them end up in the default namespace. That makes it easier to deploy malicious containers close to your most critical workloads. I recommend creating namespaces for objects in your deployment.<sup>2</sup></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-4-steer-clear-of-forbidden-types">4. Steer clear of forbidden types</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Don’t use forbidden types such as NodePort or LoadBalancer. Instead, expose services through ClusterIP. This is how you can avoid the discovery of cluster infrastructure components by some malicious actor.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-5-encrypt-secrets">5. Encrypt secrets</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Did you know that secrets aren’t actually encrypted at rest by default in base Kubernetes implementations? If you use a Kubernetes-managed service like GKE, secrets are encrypted at rest.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Why is encrypting secrets important? If anyone intercepts your key-value store, they’ll get access to everything in your cluster. This includes all cluster secrets in plain text. Encrypting the cluster state store is the best way to secure your cluster against data-at-rest exfiltration.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-6-secure-access-to-etcd">6. Secure access to etcd&nbsp;</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Access to etcd is equivalent to root permission. That’s why it’s a critical control plane component and the most important piece to secure within the control plane.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Ensure that communication with etcd is encrypted and that clients use certificate-based authentication. To limit the attack surface, ideally only the API server should have access to etcd. Take a <a href="https://kubernetes.io/docs/tasks/administer-cluster/configure-upgrade-etcd/#securing-etcd-clusters" target="_blank" rel="noreferrer noopener">look here</a> to see how to do it.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-7-don-t-mount-container-runtime-sockets-in-your-containers">7. Don’t mount container runtime sockets in your containers</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Why should you care if your deployments have container runtime (CRI) sockets mounted in containers? <em>docker.sock</em>, <em>containerd.sock</em>, and <em>crio.sock</em> increase the chance of an attacker gaining root access privileges for the host and the respective container runtime. To avoid this, remove the <em>/var/run/&lt;CRI&gt;.sock hostPath</em> volume.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-8-running-containers-without-a-read-only-root-file-system-think-twice">8. Running containers without a read-only root file system? Think twice</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Are your containers running without a read-only root file system? Using a read-only file system prevents malicious binaries from writing to a system or system takeover. You can ensure that containers use only the read-only filesystem by setting <em>readOnlyRootFilesystem</em> to true in <em>Pod securityContext</em> definition.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-9-secure-then-access-to-the-kubernetes-control-plane">9. Secure then access to the Kubernetes control plane</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>To get an extra layer of security features like multi-factor authentication, get a third-party authentication provider. And to fully secure your control plane access, avoid managing users at the level of the API server level. Instead, use a solution from your cloud provider like AWS Identity and Access Management (IAM). If you can’t get CSP IAM, choose OpenID Connect (OIDC) alongside an SSO provider you’re familiar with.<sup>3</sup></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-10-create-a-rolling-update-strategy">10. Create a rolling update strategy</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>To keep your EKS security airtight, build a rolling update strategy. Rolling updates allow deployment updates to minimize your application downtime thanks to incremental pod updates. Check out <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#rolling-update-deployment" target="_blank" rel="noreferrer noopener">this page in the Kubernetes docs</a> for more information.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Another point is running a vulnerability scan at runtime. Your cluster faces the risk of supply chain attacks. To handle them, you need to understand what really got into your cluster - even if you scanned all the deployment artifacts during CI/CD. Agent-based security solutions are good here - or even better than “agentless” ones.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="h-achieve-kubernetes-control-place-security-with-expert-help">Achieve Kubernetes control place security with expert help</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>As the Kubernetes ecosystem evolves, so do its security concerns. Keeping up with changes is time-consuming, and once vulnerabilities pile up, engineers are forced to prioritize many items at once.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>CAST AI's <a href="https://cast.ai/cloud-security/" target="_blank" rel="noreferrer noopener">Security Report Best Practices</a> feature checks clusters against industry best practices, Kubernetes recommendations, and CIS Kubernetes benchmarks – and then prioritizes them automatically to set you on the right track from the start.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Scan your Kubernetes cluster against configuration and security best practices, and find out how to secure optimally.</p>
<!-- /wp:paragraph -->

<!-- wp:group {"style":{"spacing":{"padding":{"top":"2rem","right":"2rem","bottom":"2rem","left":"2rem"},"margin":{"top":"2rem","bottom":"2rem"}}},"backgroundColor":"cast-black","className":"pattern-cta-text-btn","layout":{"type":"flex","flexWrap":"wrap","justifyContent":"space-between","verticalAlignment":"center"}} -->
<div class="wp-block-group pattern-cta-text-btn has-cast-black-background-color has-background" style="margin-top:2rem;margin-bottom:2rem;padding-top:2rem;padding-right:2rem;padding-bottom:2rem;padding-left:2rem"><!-- wp:group {"style":{"spacing":{"padding":{"top":"0rem","right":"0rem","bottom":"0rem","left":"0rem"},"blockGap":"0.5rem"}},"layout":{"type":"constrained","contentSize":"520px"}} -->
<div class="wp-block-group" style="padding-top:0rem;padding-right:0rem;padding-bottom:0rem;padding-left:0rem"><!-- wp:heading {"level":5} -->
<h5 class="wp-block-heading" id="h-check-your-kubernetes-cluster-against-configuration-and-security-best-practices">Check your Kubernetes cluster against <mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-cast-green-color">configuration and security</mark> best practices</h5>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Connect your cluster and see your costs in 5 min, no credit card required.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->

<!-- wp:buttons {"layout":{"type":"flex","justifyContent":"left","orientation":"horizontal","flexWrap":"nowrap"}} -->
<div class="wp-block-buttons"><!-- wp:button {"width":100} -->
<div class="wp-block-button has-custom-width wp-block-button__width-100"><a class="wp-block-button__link wp-element-button" href="https://console.cast.ai/?screen_hint=SIGNUP" target="_blank" rel="noreferrer noopener">Get started</a></div>
<!-- /wp:group -->

<!-- wp:group {"className":"references","layout":{"inherit":true,"type":"constrained"}} -->
<div class="wp-block-group references"><!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading" id="references">References</h4>
<!-- /wp:heading -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li><sup>[1]</sup> - <a href="https://www.redhat.com/en/resources/kubernetes-adoption-security-market-trends-overview" target="_blank" rel="noreferrer noopener">RedHat</a></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><sup>[2] </sup>- <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/" target="_blank" rel="noreferrer noopener">Kubernetes docs</a></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><sup>[3] </sup>- <a href="https://kubernetes.io/docs/reference/access-authn-authz/authentication/#authentication-strategies" target="_blank" rel="noreferrer noopener">Kubernetes docs</a></li>
<!-- /wp:list-item --></ul>
<!-- /wp:list --></div>
<!-- /wp:group -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="faq">FAQ</h2>
<!-- /wp:heading -->

<!-- wp:yoast/faq-block {"questions":[{"id":"faq-question-1672664201299","question":[{"type":"strong","props":{"children":["What is the control plane in Kubernetes?"]}}],"answer":["A Kubernetes cluster is made of worker machines called nodes, which host pods. The control plane is used to manage the worker nodes and pods in a cluster. In production environments, the control plane runs across multiple machines, and a cluster uses multiple nodes for fault tolerance and high availability.",{"type":"br","props":{"children":[]}},{"type":"br","props":{"children":[]}},"The control plane includes components that are capable of making global decisions about the cluster - for example, node scheduling. A different task of the control plane is detecting and responding to cluster events - for instance, the control place starts up a pod when the deployment's replicas field is unsatisfied.",{"type":"br","props":{"children":[]}}],"jsonQuestion":"\u003cstrong\u003eWhat is the control plane in Kubernetes?\u003c/strong\u003e","jsonAnswer":"A Kubernetes cluster is made of worker machines called nodes, which host pods. The control plane is used to manage the worker nodes and pods in a cluster. In production environments, the control plane runs across multiple machines, and a cluster uses multiple nodes for fault tolerance and high availability.\u003cbr/\u003e\u003cbr/\u003eThe control plane includes components that are capable of making global decisions about the cluster - for example, node scheduling. A different task of the control plane is detecting and responding to cluster events - for instance, the control place starts up a pod when the deployment's replicas field is unsatisfied.\u003cbr/\u003e"},{"id":"faq-question-1672664229807","question":[{"type":"strong","props":{"children":["Is the control plane the same as the master in Kubernetes?"]}}],"answer":["In a Kubernetes cluster, control plane nodes (also called master nodes) are responsible for running services required to control the Kubernetes cluster. ",{"type":"br","props":{"children":[]}}],"jsonQuestion":"\u003cstrong\u003eIs the control plane the same as the master in Kubernetes?\u003c/strong\u003e","jsonAnswer":"In a Kubernetes cluster, control plane nodes (also called master nodes) are responsible for running services required to control the Kubernetes cluster. \u003cbr/\u003e"},{"id":"faq-question-1672664250620","question":[{"type":"strong","props":{"children":["How do I monitor the Kubernetes control plane?"]}}],"answer":["The Kubernetes control plane serves as the source of truth and communication between the entire Kubernetes stack. To make sure everything is running smoothly, teams need a control plane monitoring solution that monitors the API server, the controller manager, the scheduler, and etcd (the key-value store)."],"jsonQuestion":"\u003cstrong\u003eHow do I monitor the Kubernetes control plane?\u003c/strong\u003e","jsonAnswer":"The Kubernetes control plane serves as the source of truth and communication between the entire Kubernetes stack. To make sure everything is running smoothly, teams need a control plane monitoring solution that monitors the API server, the controller manager, the scheduler, and etcd (the key-value store)."}]} -->
<div class="schema-faq wp-block-yoast-faq-block"><div class="schema-faq-section" id="faq-question-1672664201299"><strong class="schema-faq-question"><strong>What is the control plane in Kubernetes?</strong></strong> <p class="schema-faq-answer">A Kubernetes cluster is made of worker machines called nodes, which host pods. The control plane is used to manage the worker nodes and pods in a cluster. In production environments, the control plane runs across multiple machines, and a cluster uses multiple nodes for fault tolerance and high availability.<br/><br/>The control plane includes components that are capable of making global decisions about the cluster - for example, node scheduling. A different task of the control plane is detecting and responding to cluster events - for instance, the control place starts up a pod when the deployment's replicas field is unsatisfied.<br/></p> </div> <div class="schema-faq-section" id="faq-question-1672664229807"><strong class="schema-faq-question"><strong>Is the control plane the same as the master in Kubernetes?</strong></strong> <p class="schema-faq-answer">In a Kubernetes cluster, control plane nodes (also called master nodes) are responsible for running services required to control the Kubernetes cluster. <br/></p> </div> <div class="schema-faq-section" id="faq-question-1672664250620"><strong class="schema-faq-question"><strong>How do I monitor the Kubernetes control plane?</strong></strong> <p class="schema-faq-answer">The Kubernetes control plane serves as the source of truth and communication between the entire Kubernetes stack. To make sure everything is running smoothly, teams need a control plane monitoring solution that monitors the API server, the controller manager, the scheduler, and etcd (the key-value store).</p> </div> </div>
<!-- /wp:yoast/faq-block -->