AKS Security: 10 Proven Tactics for Securing Your Kubernetes Clusters
Tags: azure, cloud, security, kubernetes
Published: 2022-11-11 07:42:12

<!-- wp:paragraph -->
<p>Kubernetes comes with many challenges, and one of them is security. Managed Kubernetes solutions like Azure Kubernetes Service (AKS) take many tasks off your plate, but what about AKS security? Teams can gain confidence here by implementing practices that have become industry standards and go-to methods for the Kubernetes community. <strong>Here are the 10 AKS security practices you need to secure your clusters.</strong></p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 id="h-what-is-aks-security">What is AKS security?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Azure Kubernetes Service (AKS) is a cloud-based service for deploying, managing and securing containerized applications on Kubernetes. AKS takes care of control plane maintenance and health monitoring, leaving you to manage and maintain worker nodes.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Like any other managed Kubernetes service, <strong>AKS still requires you to come up with a security plan for your deployment</strong>. You're responsible for configuring secure configurations, building security into the architecture, setting up secure network communications within your cluster, and maintaining other aspects of the system, such as upgrade management.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To protect a cluster running on AKS, users can leverage the <strong>built-in security features in AKS</strong> and add some Kubernetes-specific security best practices to the mix. We cover the most important ones below. Additionally, it would help if you considered secure configurations recommended by the industry itself (for example, CIS benchmarks).</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 id="h-basics-of-security-for-azure-kubernetes-service-aks">Basics of security for Azure Kubernetes Service (AKS)</h2>
<!-- /wp:heading -->

<!-- wp:heading {"level":3} -->
<h3 id="h-pod-and-cluster-security"><strong>Pod and cluster security</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Azure provides a number of predefined security policies that improve the security posture of your AKS clusters and pods.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>One of the key best practices is based on <strong>limiting access to container operations and preventing root/privilege escalations</strong>. Luckily, an Azure Policy add-on for AKS allows you to install a managed instance of OPA Gatekeeper, an open-source Kubernetes admission controller.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>What exactly is <strong>Gatekeeper</strong>? It works by checking every request that creates or updates a resource. Also, it supports RBAC integration with Azure Active Directory (AD) or other identity providers. This brings fine-grained access, which is very similar to how you control access to other Microsoft Azure resources. It additionally opens the door to logging and auditing on all of the API server operations.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Azure also provides<strong> tools for orchestrating cluster and component upgrades</strong> to the latest version of Kubernetes. This helps you maintain compliance and security, as well as get access to the latest Kubernetes features. Both Kubernetes masters and agents are included in this upgrade orchestration as Azure upgrades each AKS node.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 id="h-network-security"><strong>Network security</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>AKS provides security policies you can use to secure clusters and pods. Some of these policies include:&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li><strong>Ingress controllers</strong> - use ingress controllers to say who can access internal IP addresses, making internal IPs accessible only from your internal network.&nbsp;</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><strong>Filtering network traffic -</strong> only allow network traffic from authorized networks based on IP address or namespace.&nbsp;</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><strong>Web application firewall (WAF)</strong> - using the Azure WAF solution together with an egress firewall allows you to manage predefined routes in and out of an environment.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><strong>Network security groups</strong> - implement finer-grained control by applying security groups to AKS resources, allowing specific ports and protocols based on source/destination. By default, AKS creates a subnet-level security group for your cluster. Security groups change automatically when you add services such as load balancers, port mappings, and ingress routing.&nbsp;</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:heading {"level":3} -->
<h3 id="h-master-security"><strong>Master security</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>AKS manages, maintains, and provides the Kubernetes master components as part of its service. AKS clusters include a single-tenant Kubernetes master, where you can find features such as the API Server and Kubernetes Scheduler.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In AKS, the API server has a public IP address with a domain name. If you need to restrict API access, you can limit access to specific IP ranges or create private clusters inside an Azure Virtual Network (VNet). All in all, you end up managing access via RBAC and Kubernetes RBAC privileges.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 id="h-10-proven-aks-security-practices">10 proven AKS security practices</h2>
<!-- /wp:heading -->

<!-- wp:heading {"level":3} -->
<h3 id="h-1-think-twice-about-running-containers-in-privileged-mode"><strong>1. Think twice about running containers in privileged mode</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Does your deployment have containers running in privileged (root) mode? This lets the container get access to important host resources and - as a result - brings about some security problems.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Don't run containers in privileged mode. Alternatively, you can turn the podSecurityPolicy on and then set the privileged parameter to false. This is how you make sure that no container can run processes that require root privileges on the host.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 id="h-2-avoid-sharing-the-host-s-ipc-or-network-namespace"><strong>2. Avoid sharing the host's IPC or network namespace&nbsp;</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Do your pods share the host's IPC or network namespace? Sharing namespaces for pod and host interprocess communication can be tricky. It poses a security issue because it may open access to this shared information.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>That's why it's an industry best practice to keep pods from accessing host namespaces because it lets network access to the host network from the pod. As a result, you're dealing with a broken network isolation.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>What can you do about it? Set the hostNetwork parameter to false in PodSecurityPolicy, and you'll sleep much better at night, confident that your cluster is secure.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 id="h-3-make-sure-to-isolate-kubernetes-nodes"><strong>3. Make sure to isolate Kubernetes nodes</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Another best practice is not exposing your Kubernetes nodes to public networks directly. Instead, locate your nodes on a separate network so they don't have any direct connection to the general company network.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Isolate Kubernetes control and data traffic isolated, so they don't flow through the same pipe. Open access to the data plane means open access to the control plane, which is bad news for AKS security. Make sure to configure nodes with the help of an ingress controller and set it to only give access to connections from the master node via a specified port in the network access control list (ACL).</p>
<!-- /wp:paragraph -->

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

<!-- wp:paragraph -->
<p>Use RBAC to define who has access to the Kubernetes API and based on what permissions. In Kubernetes 1.6 and higher, RBAC is usually enabled by default. Since Kubernetes brings together authorization controllers, you can disable the Attribute Based Access Control (ABAC) when you use RBAC.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To tighten your cluster security further, pick namespace-specific permissions over cluster-wide permissions. Even when you're debugging your application, you should refrain from granting cluster administrator privileges. If you do, you risk compromising your container security.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 id="h-5-avoid-using-the-root-file-system-for-container-security"><strong>5. Avoid using the root file system for container security</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Are your containers running without a read-only root file system? Expect security issues to arise soon.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Do yourself a favor and use a read-only file system. This helps to avoid all kinds of malicious binaries, be it writing to a system or facing a system takeover. Double-check that your containers use only the read-only file system and set the readOnlyRootFilesystem to true in Pod securityContext definition.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 id="h-6-boost-authentication-and-authorization"><strong>6. Boost authentication and authorization</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Another best practice is integrating Kubernetes with a third-party authentication provider to get an extra layer of security, like multi-factor authentication.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>For secure control plane access, avoid managing users at the level of the API server but use the Azure Active Directory and Azure RBAC. Choose OpenID Connect (OIDC) together with an SSO provider that you've got, if you can't get CSP IAM.<sup>1</sup>&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 id="h-7-disable-net-raw"><strong>7. Disable NET_RAW</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>If your containers don't drop the NET_RAW capability, you might let in various networking exploits from inside the cluster. To boost your AKS security, take advantage of Policy Enforcement solutions such as Open Policy Agents, Kyverno, or Kubernetes Pod Security admission controller.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Additionally, you can set drop for ALL or NET_RAW capabilities in the pod's securityContext definition. This is how you ensure that the NET_RAW capability is disabled.<sup>2,3</sup></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 id="h-8-double-check-unsafe-proc-mount"><strong>8. Double check unsafe /proc mount&nbsp;</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Containers with unsafe /proc mount (procMount=Unmasked) let others bypass the default masking behavior of the container runtime. If you set your Kubernetes container with Unmasked /proc mount type, you might expose the host information to that container.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Why is that a bad idea? You're looking at problems like data leaks or container escapes. Set procMount=Default to ensure your container doesn't expose any parts of /proc.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 id="h-9-don-t-keep-secrets-in-an-environment-variable"><strong>9. Don't keep secrets in an environment variable</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>It's a good practice to have your secret outside an environment variable. The reason for that is that other parts of your system can access environment variables. Use secrets as files or leverage secretKeyRef to minimize threats. You can also leverage Azure Key Vault service to store and access your secrets securely.<sup>4</sup></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 id="h-10-develop-a-rolling-update-strategy"><strong>10. Develop a rolling update strategy</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>To keep your AKS security tight, build a rolling update strategy. Rolling updates allow deployment updates to minimize application downtime by updating pod instances with new ones incrementally.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Another good practice is to run a vulnerability scan at runtime to prevent supply chain attacks. That way, you can see what really got to your cluster - even if you carried out a scan of your deployment artifacts in the CI/CD stage.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you’re using third-party tools, you might install them via vendor-provided scripts - as a result, bypassing security tools built into your CI/CD. Agent-based security solutions give you more accurate and deeper insights than "agentless" ones.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 id="h-achieve-aks-security-with-expert-help">Achieve AKS security with expert help</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>As the Kubernetes ecosystem grows, so do its security concerns. To stay on top of emerging threats, engineers must learn how to prioritize security issues and track them effectively.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>With CAST AI's Kubernetes Security feature, you can scan your cluster against industry best practices, Kubernetes recommendations, and container security system benchmarks to <strong>identify vulnerabilities and set yourself up for success right from the start</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Scan your Kubernetes cluster against a curated list of configuration and security best practices, and find out how to secure it 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 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 {"className":"references","layout":{"inherit":true,"type":"constrained"}} -->
<div class="wp-block-group references">
<h4 id="references">References</h4>
<!-- /wp:heading -->

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

<!-- wp:list-item -->
<li><sup>[2]</sup>- <a href="https://kubernetes.io/docs/concepts/security/pod-security-admission/" target="_blank" rel="noreferrer noopener">Kubernetes documentation</a></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><sup>[3] </sup>- <a href="https://kubernetes.io/docs/concepts/security/pod-security-standards/" target="_blank" rel="noreferrer noopener">Kubernetes documentation</a></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><sup>[4]</sup> - <a href="https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-driver" target="_blank" rel="noreferrer noopener">Microsoft</a></li>
<!-- /wp:list-item -->