GKE Security: Top 10 Strategies for Securing Your Cluster
Tags: devops, kubernetes, cloud, googlecloud
Published: 2023-01-27 10:24:54

<!-- wp:paragraph -->
<p>Security is one of key challenges in Kubernetes because of its configuration complexity and vulnerability. Managed container services like Google Kubernetes Engine (GKE) provide many protection features but don't take all related responsibilities off your plate. <strong>Read on to learn more about GKE security and best practices to secure your cluster.</strong></p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="basic-overview-of-gke-security">Basic overview of GKE security</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>GKE protects your workload in many layers, which include your container image, its runtime, the cluster network, and access to the cluster API server.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>That's why Google recommends a layered approach to protecting your clusters and workloads. Enabling the right level of flexibility and security for your organization to deploy and maintain workloads may require different tradeoffs, as some settings may be too constraining.&nbsp;&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>The most critical aspects of GKE security involve the following:&nbsp;</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><!-- wp:list-item -->
<li>Authentication and authorization;</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Control plane security, including components and configuration;</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Node security;</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Network security.</li>
<!-- /wp:list-item --></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>These elements are also reflected in CIS Benchmarks, which help to structure work around security configurations for Kubernetes.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="why-are-cis-benchmarks-crucial-for-gke-security">Why are CIS Benchmarks crucial for GKE security?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Handling K8s security configuration isn’t exactly a walk in the park.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Red Hat 2022 State of Kubernetes and Container Security<sup>1</sup> found that almost 1 in 4 serious issues were vulnerabilities that could be remediated. Nearly 70% of incidents happened due to misconfigurations.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Since its release by the Center of Internet Security (CIS), Benchmarks have become globally recognized best practices for implementing and managing cybersecurity mechanisms.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The CIS Kubernetes Benchmark involves recommendations for K8s configuration that support a strong security posture. Written for the open-source Kubernetes distribution, it intends to be as universally applicable as possible.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="cis-gke-benchmarking-in-practice">CIS GKE Benchmarking in practice</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>With a managed service like GKE, not all items on the CIS Benchmark are under your control.&nbsp;</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>That’s why there are recommendations that you cannot audit or modify directly on your own. These involve:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>The control plane;</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>The Kubernetes distribution;</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>The nodes' operating system.</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>However, you still have to take care of upgrading the nodes that run your workloads and, of course, the workloads themselves. You need to audit and remediate any recommendations to these components.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>You could do it manually or use a tool that handles CIS benchmarking</strong>. With CAST AI’s <a href="https://cast.ai/cloud-security/">container security</a> module, for example, you can get an overview of benchmark discrepancies within minutes of connecting your cluster.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The platform also prioritizes the issues it identifies, so you know which items require remediation first. When scanning your cluster, you also check it against the industry's best practices, so you can better assess your overall security posture and plan further GKE hardening.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="h-top-10-strategies-to-ensure-gke-security"><strong>Top 10 strategies to ensure GKE security</strong></h2>
<!-- /wp:heading -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-1-apply-the-principle-of-least-privilege">1. Apply the principle of least privilege</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>This basic security tenet refers to granting a user account only the privileges that are essential to perform the intended function.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>It comes in<strong> CIS GKE Benchmark 6.2.1<sup>2</sup>:</strong> <em>Prefer not running GKE clusters using the Compute Engine default service account</em>.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>By default, your nodes get access to the Compute Engine service account. Its broad access makes it useful to multiple applications, but it also has more permissions than necessary to run your GKE cluster. That's why you must create and use a minimally privileged service account instead of the default one – and follow suit in other contexts, too.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-2-use-rbac-to-strengthen-authentication-and-authorization">2. Use RBAC to strengthen authentication and authorization</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>GKE supports multiple options for managing access to your clusters with role-based access control (<strong>RBAC</strong>)<sup>2</sup>.&nbsp;&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>RBAC enables more granular access to Kubernetes resources at cluster and namespace levels, but it also lets you create detailed permission policies.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>CIS GKE Benchmark 6.8.4</strong> underscores the need to give preference to RBAC over the legacy Attribute Based Access Control (ABAC).&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Another <strong>CIS GKE Benchmark (6.8.3)</strong> recommends using groups to manage users as it simplifies controlling identities and permissions. It also removes the need to update the RBAC configuration whenever users are added or removed from the group.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="3-enhance-your-control-plane-s-security">3. Enhance your control plane’s security&nbsp;</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Under the Shared Responsibility Model, Google manages the GKE <a href="https://cast.ai/blog/kubernetes-control-plane-10-tips-for-airtight-k8s-security/">control plane</a> components for you. However, you remain responsible for securing your nodes, containers, and pods.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>By default, the Kubernetes API server uses a public IP address. You can protect it by using authorized networks and private clusters, which enable you to assign a private IP address.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You can also enhance your control plane’s security by doing a regular credential rotation. When you initiate the process, the TLS certificates and cluster certificate authority are rotated automatically.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="4-upgrade-your-gke-infrastructure-regularly">4. Upgrade your GKE infrastructure regularly</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Kubernetes frequently releases new security features and patches, so keeping your K8s up-to-date is one of the simplest ways to improve your security posture.&nbsp;&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>GKE patches and upgrades the control planes for you automatically. Node auto-upgrade also automatically upgrades nodes in your cluster. <strong>CIS GKE Benchmark 6.5.3</strong> recommends keeping that setting on.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If for any reason you need to disable the auto-upgrade, Google advises performing upgrades monthly and following the GKE security bulletins<sup>4</sup> for critical patches.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="5-protect-node-metadata">5. Protect node metadata</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>CIS GKE Benchmarks 6.4.1 and 6.4.2</strong> refer to two critical factors compromising your node security, which is still your responsibility.&nbsp;&nbsp;&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The v0.1 and v1beta1 Compute Engine metadata server endpoints were deprecated and shut down in 2020 as they didn’t enforce metadata query headers.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Some attacks against Kubernetes rely on access to the VM's metadata server to extract credentials. You can prevent those attacks with Workload identity or Metadata Concealment.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="6-disable-the-kubernetes-dashboard">6. Disable the Kubernetes dashboard&nbsp;</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Some years back, the world was electrified by the news of attackers gaining access to Tesla’s cloud resources and using them to mine cryptocurrency<sup>5</sup>. The vector of attack in that case was a Kubernetes dashboard, which was exposed to the public with no authentication or elevated privileges.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Complying with <strong>CIS GKE Benchmark 6.10.1</strong> is recommended if you want to avoid following Tesla's plight. This standard clearly outlines that you should disable Kubernetes web UI when running on GKE.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>By default, GKE 1.10 and later disable the K8s dashboard. You can also use the following code:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>gcloud container clusters update CLUSTER_NAME \
    --update-addons=KubernetesDashboard=DISABLED</code></pre>
<!-- /wp:code -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="7-follow-the-nsa-cisa-framework">7. Follow the NSA-CISA Framework&nbsp;</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>CIS Kubernetes Benchmark gives you a strong foundation for building a secure operating environment. But if you want to go further, make space for NSA-CISA Kubernetes Hardening Guidance<sup>6</sup> in your security procedures.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The NSA-CISA report outlines vulnerabilities within a Kubernetes ecosystem and recommends best practices for configuring your cluster for security.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>It presents recommendations on vulnerability scanning, identifying misconfigurations, log auditing, and authentication, helping you to ensure that you appropriately address common security challenges.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="8-improve-your-network-security">8. Improve your network security</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Most workloads running in GKE need to communicate with other services running inside and outside the cluster. However, you can control the traffic allowed to flow through your clusters.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>First, you can use network policies to limit pod-to-pod communication</strong>. By default, all cluster pods can be reached over the network via their pod IP address. You can lock down the connection in a namespace by defining traffic flowing through your pods and stopping it for those that don't match the configured labels.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Second, you can balance your Kubernetes pods with a network load balancer</strong>. To do so, you create a LoadBalancer service matching your pod's labels. You will have an external-facing IP mapping to ports on your Kubernetes Pods, and you’ll be able to filter authorized traffic at the node level with kube-proxy.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="9-secure-pod-access-to-google-cloud-resources">9. Secure pod access to Google Cloud resources</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Your containers and pods might need access to other resources in Google Cloud. There are three ways to do this: with Workload Identity, Node Service Account, and Service Account JSON Key.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The simplest and most secure option to access Google Cloud resources is by using Workload Identity. This method allows your pods running on GKE to get permissions on the Google Cloud service account.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You should use application-specific Google Cloud service accounts to provide credentials so that applications have the minimal necessary permissions that you can revoke in case of a compromise.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="10-get-a-gke-configured-secret-manager">10. Get a GKE-configured secret manager</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>CIS GKE Benchmark 6.3.1.</strong> recommends encrypting Kubernetes Secrets using keys managed in Cloud KMS.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Google Kubernetes Engine gives you several options for secret management. You can use Kubernetes secrets natively in GKE, but you can also protect these at an application-layer with a key you manage and application-layer secret encryption.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>There are also secrets managers like Hashicorp Vault, which provide a consistent, production-ready way to manage secrets in GKE. Make sure you check your options out and pick an optimal solution.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="h-assess-gke-security-within-minutes">Assess GKE security within minutes</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The Kubernetes ecosystem keeps growing, but so are its security configuration challenges. If you want to stay on top of GKE container security, you need to be able to identify potential threats and track them efficiently.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://cast.ai/cloud-security/">CAST AI’s security report</a> lets you scan your GKE cluster against CIS benchmark, NSA-CISA framework, and other container security best practices to identify vulnerabilities, spot misconfigurations, and prioritize them. It only takes a few minutes to get a complete overview of your cluster’s security posture.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Scan your GKE cluster now and find out how to secure it best.&nbsp;</strong></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 and scan your cluster 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/topics/containers/kubernetes-security" target="_blank" rel="noreferrer noopener">RedHat</a></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><sup>[2]</sup>- <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/hardening-your-cluster#permissions" target="_blank" rel="noreferrer noopener">Google Cloud</a></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><sup>[3] </sup>- <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/role-based-access-control" target="_blank" rel="noreferrer noopener">Google Cloud</a></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><sup>[4]</sup> - <a href="https://cloud.google.com/anthos/clusters/docs/security-bulletins" target="_blank" rel="noreferrer noopener">GKE Security Bulletins</a></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>[5] -&nbsp;<a href="https://cloud.redhat.com/blog/cryptojacking-attacks-in-kubernetes-how-to-stop-them">RedHat</a></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>[6] - <a href="https://media.defense.gov/2022/Aug/29/2003066362/-1/-1/0/CTR_KUBERNETES_HARDENING_GUIDANCE_1.2_20220829.PDF">National Security Agency &amp; Cybersecurity and Infrastructure Security Agency</a></li>
<!-- /wp:list-item --></ul>
<!-- /wp:list --></div>
<!-- /wp:group -->